unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Neil Jerram <neil@ossau.uklinux.net>
Cc: guile-user@gnu.org
Subject: Re: readline eats previous text on line
Date: Sat, 30 Sep 2006 13:25:28 +0100	[thread overview]
Message-ID: <877izl35jb.fsf@ossau.uklinux.net> (raw)
In-Reply-To: <87y7s22tgt.fsf@ossau.uklinux.net> (Neil Jerram's message of "Fri, 29 Sep 2006 23:33:54 +0100")

Neil Jerram <neil@ossau.uklinux.net> 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)



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


  reply	other threads:[~2006-09-30 12:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-27 21:26 readline eats previous text on line Jon Wilson
2006-09-28  1:40 ` Kevin Ryde
2006-09-28  1:50   ` Jon Wilson
2006-09-28  7:49     ` Neil Jerram
2006-09-29  0:47       ` Kevin Ryde
2006-09-29 22:33         ` Neil Jerram
2006-09-30 12:25           ` Neil Jerram [this message]
2006-10-03  0:15             ` Kevin Ryde
2006-10-03  0:52               ` Kevin Ryde
2006-10-04 23:13               ` Kevin Ryde
2006-10-05 23:06                 ` Neil Jerram
2006-10-05 23:35               ` Neil Jerram
2006-10-06  0:03                 ` Kevin Ryde
2006-12-01 20:24                 ` Jon Wilson
2006-10-03  0:22             ` Kevin Ryde
2006-09-28 21:08   ` Jon Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877izl35jb.fsf@ossau.uklinux.net \
    --to=neil@ossau.uklinux.net \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).