[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: readline eats previous text on line
Re: readline eats previous text on line
Thu, 05 Oct 2006 09:13:41 +1000
Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)
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
22.214.171.124 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' 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).
-- 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
(define (username-completer-function text state)
(if (not state)
(setpwent)) ;; new, go to start of database
(let more ((pw (getpwent)))
(if (string-prefix? text (passwd:name pw))
(passwd:name pw) ;; this name matches, return it
(more (getpwent))) ;; doesn't match, look at next
;; end of database, close it and return #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: 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.