Andy Wingo <[email protected]> writes:
> * History: Expression-oriented, please!
>
> It would be great if going back in the history cycled through entire
> expressions, not line-by-line. Again I know that readline can do
> this. Please fix? :)
The attached seems to work for me. Does it look OK?
Regards,
Neil
>From 77c260435092f9bbfba17b6b2b4e4c8b1c5623d9 Mon Sep 17 00:00:00 2001
From: Neil Jerram <[email protected]>
Date: Sat, 30 Oct 2010 16:28:54 +0100
Subject: [PATCH] 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.
---
guile-readline/ice-9/readline.scm | 43 +++++++++++++++++++++++++------------
1 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/guile-readline/ice-9/readline.scm b/guile-readline/ice-9/readline.scm
index 4879bab..36f805f 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 ---
--
1.7.1