summaryrefslogtreecommitdiff
path: root/guile-readline
diff options
context:
space:
mode:
authorNeil Jerram <neil@ossau.uklinux.net>2010-10-30 16:28:54 +0100
committerAndy Wingo <wingo@pobox.com>2010-11-14 12:22:56 +0100
commit8b755a759eb7d07e82285e925bae02c19e7a3107 (patch)
tree729b6ec876a33bee111548578ffa98d0b3f7d47d /guile-readline
parentd9f00c3db598955db75047aa805adf16a7bb2421 (diff)
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.
Diffstat (limited to 'guile-readline')
-rw-r--r--guile-readline/ice-9/readline.scm43
1 files changed, 29 insertions, 14 deletions
diff --git a/guile-readline/ice-9/readline.scm b/guile-readline/ice-9/readline.scm
index 4879babc5..36f805f6c 100644
--- a/guile-readline/ice-9/readline.scm
+++ b/guile-readline/ice-9/readline.scm
@@ -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 ---