From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.user Subject: Re: readline eats previous text on line Date: Sat, 30 Sep 2006 13:25:28 +0100 Message-ID: <877izl35jb.fsf@ossau.uklinux.net> References: <451AEC75.90200@fastmail.fm> <87y7s4ahvc.fsf@zip.com.au> <451B2A4C.2040000@fastmail.fm> <87ejtw8m7r.fsf@ossau.uklinux.net> <878xk3h52l.fsf@zip.com.au> <87y7s22tgt.fsf@ossau.uklinux.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1159619412 24398 80.91.229.2 (30 Sep 2006 12:30:12 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 30 Sep 2006 12:30:12 +0000 (UTC) Cc: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Sep 30 14:30:11 2006 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GTdyq-0002BD-DG for guile-user@m.gmane.org; Sat, 30 Sep 2006 14:30:08 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GTdyq-0004Su-5d for guile-user@m.gmane.org; Sat, 30 Sep 2006 08:30:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GTdyl-0004Sc-8x for guile-user@gnu.org; Sat, 30 Sep 2006 08:30:03 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GTdyk-0004SN-2x for guile-user@gnu.org; Sat, 30 Sep 2006 08:30:02 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GTdyj-0004SK-Uc for guile-user@gnu.org; Sat, 30 Sep 2006 08:30:02 -0400 Original-Received: from [80.84.72.33] (helo=mail3.uklinux.net) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GTe4G-00006Y-F0 for guile-user@gnu.org; Sat, 30 Sep 2006 08:35:44 -0400 Original-Received: from laruns (host86-145-154-50.range86-145.btcentralplus.com [86.145.154.50]) by mail3.uklinux.net (Postfix) with ESMTP id 745E340A2CD; Sat, 30 Sep 2006 12:25:37 +0000 (UTC) Original-Received: from laruns (laruns [127.0.0.1]) by laruns (Postfix) with ESMTP id 836916F6D4; Sat, 30 Sep 2006 13:25:28 +0100 (BST) Original-To: Kevin Ryde In-Reply-To: <87y7s22tgt.fsf@ossau.uklinux.net> (Neil Jerram's message of "Fri, 29 Sep 2006 23:33:54 +0100") User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:5562 Archived-At: Neil Jerram 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