From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.user Subject: Re: readline eats previous text on line Date: Thu, 05 Oct 2006 09:13:41 +1000 Message-ID: <8764ezu122.fsf@zip.com.au> 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> <877izl35jb.fsf@ossau.uklinux.net> <87bqoujltw.fsf@zip.com.au> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1160003662 28285 80.91.229.2 (4 Oct 2006 23:14:22 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 4 Oct 2006 23:14:22 +0000 (UTC) Cc: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Oct 05 01:14:22 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 1GVFwJ-0006bg-9D for guile-user@m.gmane.org; Thu, 05 Oct 2006 01:14:12 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GVFwI-0004Jl-OF for guile-user@m.gmane.org; Wed, 04 Oct 2006 19:14:10 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GVFwD-0004JC-TQ for guile-user@gnu.org; Wed, 04 Oct 2006 19:14:06 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GVFwC-0004I4-1d for guile-user@gnu.org; Wed, 04 Oct 2006 19:14:04 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GVFwB-0004Hq-Uw for guile-user@gnu.org; Wed, 04 Oct 2006 19:14:03 -0400 Original-Received: from [61.8.2.229] (helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GVG2i-0003cU-8y for guile-user@gnu.org; Wed, 04 Oct 2006 19:20:48 -0400 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.2.163]) by mailout2.pacific.net.au (Postfix) with ESMTP id 345D110D2DC; Thu, 5 Oct 2006 09:14:01 +1000 (EST) Original-Received: from localhost (ppp2A18.dyn.pacific.net.au [61.8.42.24]) by mailproxy2.pacific.net.au (8.13.4/8.13.4/Debian-3sarge3) with ESMTP id k94NDxxw022388; Thu, 5 Oct 2006 09:14:00 +1000 Original-Received: from gg by localhost with local (Exim 4.63) (envelope-from ) id 1GVFvp-0003hM-O2; Thu, 05 Oct 2006 09:13:41 +1000 Original-To: Neil Jerram In-Reply-To: <87bqoujltw.fsf@zip.com.au> (Kevin Ryde's message of "Tue, 03 Oct 2006 10:15:55 +1000") User-Agent: Gnus/5.110006 (No Gnus v0.6) 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:5571 Archived-At: This is what I ended up checking-in. 6.5.3 Readline Functions ------------------------ The following functions are provided by (use-modules (ice-9 readline)) There are two ways to use readline from Scheme code, either make calls to `readline' directly to get line by line input, or use the readline port below with all the usual reading functions. -- Function: readline [prompt] Read a line of input from the user and return it as a string (without a newline at the end). PROMPT is the prompt to show, or the default is the string set in `set-readline-prompt!' below. (readline "Type something: ") => "hello" -- Function: set-readline-input-port! port -- Function: set-readline-output-port! port Set the input and output port the readline function should read from and write to. PORT must be a file port (*note File Ports::), and should usually be a terminal. The default is the `current-input-port' and `current-output-port' (*note Default Ports::) when `(ice-9 readline)' loads, which in an interactive user session means the Unix "standard input" and "standard output". 6.5.3.1 Readline Port ..................... -- Function: readline-port Return a buffered input port (*note Buffered Input::) which calls the `readline' function above to get input. This port can be used with all the usual reading functions (`read', `read-char', etc), and the user gets the interactive editing features of readline. There's only a single readline port created. `readline-port' creates it when first called, and on subsequent calls just returns what it previously made. -- Function: activate-readline If the `current-input-port' is a terminal (*note `isatty?': Terminals and Ptys.) then enable readline for all reading from `current-input-port' (*note Default Ports::) and enable readline features in the interactive REPL (*note The REPL::). (activate-readline) (read-char) `activate-readline' enables readline on `current-input-port' simply by a `set-current-input-port' to the `readline-port' above. An application can do that directly if the extra REPL features that `activate-readline' adds are not wanted. -- Function: set-readline-prompt! prompt1 [prompt2] Set the prompt string to print when reading input. This is used when reading through `readline-port', and is also the default prompt for the `readline' function above. PROMPT1 is the initial prompt shown. If a user might enter an expression across multiple lines, then PROMPT2 is a different prompt to show further input required. In the Guile REPL for instance this is an ellipsis (`...'). See `set-buffered-input-continuation?!' (*note Buffered Input::) for an application to indicate the boundaries of logical expressions (assuming of course an application has such a notion). 6.5.3.2 Completion .................. -- Function: with-readline-completion-function completer thunk Call `(THUNK)' with COMPLETER as the readline tab completion function to be used in any readline calls within that THUNK. COMPLETER can be `#f' for no completion. COMPLETER will be called as `(COMPLETER text state)', as described in (*note How Completing Works: (readline)How Completing Works.). TEXT is a partial word to be completed, and each COMPLETER call should return a possible completion string or `#f' when no more. STATE is `#f' for the first call asking about a new TEXT then `#t' while getting further completions of that TEXT. Here's an example COMPLETER for user login names from the password file (*note User Information::), much like readline's own `rl_username_completion_function', (define (username-completer-function text state) (if (not state) (setpwent)) ;; new, go to start of database (let more ((pw (getpwent))) (if pw (if (string-prefix? text (passwd:name pw)) (passwd:name pw) ;; this name matches, return it (more (getpwent))) ;; doesn't match, look at next (begin ;; end of database, close it and return #f (endpwent) #f)))) -- Function: apropos-completion-function text state A completion function offering completions for Guile functions and variables (all `define's). This is the default completion function. -- Function: filename-completion-function text state A completion function offering filename completions. This is readline's `rl_filename_completion_function' (*note Completion Functions: (readline)Completion Functions.). -- Function: make-completion-function string-list Return a completion function which offers completions from the possibilities in STRING-LIST. Matching is case-sensitive. _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user