1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-29 19:30:36 +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:
Neil Jerram 2010-10-30 16:28:54 +01:00 committed by Andy Wingo
parent d9f00c3db5
commit 8b755a759e

View file

@ -80,20 +80,35 @@
(define read-hook #f)
(define (make-readline-port)
(make-line-buffered-input-port (lambda (continuation?)
(let* ((prompt (if continuation?
continuation-prompt
new-input-prompt))
(str (%readline (if (string? prompt)
prompt
(prompt))
input-port
output-port
read-hook)))
(or (eof-object? str)
(string=? str "")
(add-history str))
str))))
(let ((history-buffer #f))
(make-line-buffered-input-port (lambda (continuation?)
;; When starting a new read, add
;; the previously read expression
;; to the history.
(if (and (not continuation?)
history-buffer)
(begin
(add-history history-buffer)
(set! history-buffer #f)))
;; Set up prompts and read a line.
(let* ((prompt (if continuation?
continuation-prompt
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
;;; more, since they would all share the tty and history ---