mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-29 22:40:34 +02:00
Expression-oriented readline history
* guile-readline/ice-9/readline.scm (make-readline-port): Instead of calling add-history after every %readline call, do it only when starting a new read. Other times, append the line just read to an internal buffer.
This commit is contained in:
parent
d9f00c3db5
commit
8b755a759e
1 changed files with 29 additions and 14 deletions
|
@ -80,20 +80,35 @@
|
||||||
(define read-hook #f)
|
(define read-hook #f)
|
||||||
|
|
||||||
(define (make-readline-port)
|
(define (make-readline-port)
|
||||||
(make-line-buffered-input-port (lambda (continuation?)
|
(let ((history-buffer #f))
|
||||||
(let* ((prompt (if continuation?
|
(make-line-buffered-input-port (lambda (continuation?)
|
||||||
continuation-prompt
|
;; When starting a new read, add
|
||||||
new-input-prompt))
|
;; the previously read expression
|
||||||
(str (%readline (if (string? prompt)
|
;; to the history.
|
||||||
prompt
|
(if (and (not continuation?)
|
||||||
(prompt))
|
history-buffer)
|
||||||
input-port
|
(begin
|
||||||
output-port
|
(add-history history-buffer)
|
||||||
read-hook)))
|
(set! history-buffer #f)))
|
||||||
(or (eof-object? str)
|
;; Set up prompts and read a line.
|
||||||
(string=? str "")
|
(let* ((prompt (if continuation?
|
||||||
(add-history str))
|
continuation-prompt
|
||||||
str))))
|
new-input-prompt))
|
||||||
|
(str (%readline (if (string? prompt)
|
||||||
|
prompt
|
||||||
|
(prompt))
|
||||||
|
input-port
|
||||||
|
output-port
|
||||||
|
read-hook)))
|
||||||
|
(or (eof-object? str)
|
||||||
|
(string=? str "")
|
||||||
|
(set! history-buffer
|
||||||
|
(if history-buffer
|
||||||
|
(string-append history-buffer
|
||||||
|
" "
|
||||||
|
str)
|
||||||
|
str)))
|
||||||
|
str)))))
|
||||||
|
|
||||||
;;; We only create one readline port. There's no point in having
|
;;; We only create one readline port. There's no point in having
|
||||||
;;; more, since they would all share the tty and history ---
|
;;; more, since they would all share the tty and history ---
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue