[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: readline eats previous text on line
From: |
Neil Jerram |
Subject: |
Re: readline eats previous text on line |
Date: |
Sat, 30 Sep 2006 13:25:28 +0100 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
Neil Jerram <address@hidden> writes:
> The bug which Jon has noted, about the effect of set-readline-prompt!
> not lasting very long, is caused by the fact that Guile's REPL code,
> when using readline, does a
>
> (set-readline-prompt! "guile>" "...")
>
> before reading an expression from the REPL, and
>
> (set-readline-prompt! "" "")
>
> after the read, thus losing whatever prompt the user might have
> installed for their own (non-REPL) purposes. This code should instead
> save the existing prompts and restore them afterwards - I'll post a
> patch for that soon.
Patch is below.
Another thing that is likely to bite people in this area is the
concept of continuation input and need to use
`set-buffered-input-continuation?!'. The right thing to do here is
either to call `(set-buffered-input-continuation?! port #f)' before
each new read, or to set the new-input and continuation prompts to the
same thing: `(set-readline-prompt! my-prompt my-prompt)'.
(This is pretty horrible, but I can't see any other way. If anyone
has any better ideas, please suggest them!)
Regards,
Neil
Index: readline.scm
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/guile-readline/ice-9/readline.scm,v
retrieving revision 1.5
diff -u -r1.5 readline.scm
--- readline.scm 17 Apr 2006 01:35:37 -0000 1.5
+++ readline.scm 30 Sep 2006 12:20:12 -0000
@@ -68,8 +68,8 @@
;;; Dirk:FIXME:: If the-readline-port, input-port or output-port are closed,
;;; guile will enter an endless loop or crash.
-(define prompt "")
-(define prompt2 "")
+(define new-input-prompt "")
+(define continuation-prompt "")
(define input-port (current-input-port))
(define output-port (current-output-port))
(define read-hook #f)
@@ -77,8 +77,8 @@
(define (make-readline-port)
(make-line-buffered-input-port (lambda (continuation?)
(let* ((prompt (if continuation?
- prompt2
- prompt))
+ continuation-prompt
+ new-input-prompt))
(str (%readline (if (string? prompt)
prompt
(prompt))
@@ -125,7 +125,7 @@
;;; %readline is the low-level readline procedure.
(define-public (readline . args)
- (let ((prompt prompt)
+ (let ((prompt new-input-prompt)
(inp input-port))
(cond ((not (null? args))
(set! prompt (car args))
@@ -141,9 +141,9 @@
args)))
(define-public (set-readline-prompt! p . rest)
- (set! prompt p)
+ (set! new-input-prompt p)
(if (not (null? rest))
- (set! prompt2 (car rest))))
+ (set! continuation-prompt (car rest))))
(define-public (set-readline-input-port! p)
(cond ((or (not (file-port? p)) (not (input-port? p)))
@@ -202,19 +202,22 @@
(not (let ((guile-user-module (resolve-module '(guile-user))))
(and (module-defined? guile-user-module 'use-emacs-interface)
(module-ref guile-user-module 'use-emacs-interface)))))
- (let ((read-hook (lambda () (run-hook before-read-hook))))
+ (let ((repl-read-hook (lambda () (run-hook before-read-hook))))
(set-current-input-port (readline-port))
(set! repl-reader
- (lambda (prompt)
- (dynamic-wind
- (lambda ()
- (set-buffered-input-continuation?! (readline-port) #f)
- (set-readline-prompt! prompt "... ")
- (set-readline-read-hook! read-hook))
- (lambda () (read))
- (lambda ()
- (set-readline-prompt! "" "")
- (set-readline-read-hook! #f)))))
+ (lambda (repl-prompt)
+ (let ((outer-new-input-prompt new-input-prompt)
+ (outer-continuation-prompt continuation-prompt)
+ (outer-read-hook read-hook))
+ (dynamic-wind
+ (lambda ()
+ (set-buffered-input-continuation?! (readline-port) #f)
+ (set-readline-prompt! repl-prompt "... ")
+ (set-readline-read-hook! repl-read-hook))
+ (lambda () (read))
+ (lambda ()
+ (set-readline-prompt! outer-new-input-prompt
outer-continuation-prompt)
+ (set-readline-read-hook! outer-read-hook))))))
(set! (using-readline?) #t))))
(define-public (make-completion-function strings)
Re: readline eats previous text on line, Jon Wilson, 2006/09/28