[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: readline eats previous text on line
From: |
Kevin Ryde |
Subject: |
Re: readline eats previous text on line |
Date: |
Tue, 03 Oct 2006 10:15:55 +1000 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) |
Neil Jerram <address@hidden> writes:
>
> Slightly confusingly, set-readline-prompt! does also set the default
> prompt for an explicit `readline' call (1). I think the overall
> situation would be clearer if it didn't.
It's not too terrible, may as well leave it alone in case anyone's
nutted it out and is using it.
> 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,
It might have been from only using `display' to show a prompt, which
readline doesn't know and hence overwrites.
> ... This code should instead
> save the existing prompts and restore them afterwards
But yes, that'd be a good thing.
> Patch is below.
Looks pretty reasonable.
> (This is pretty horrible, but I can't see any other way. If anyone
> has any better ideas, please suggest them!)
I guess the application has to say the boundaries somehow.
I wrote some words for the manual. Readline functions to follow the
other readline bits, the buffered-input to go in the Guile Modules
section.
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
`activate-readline' to have readline for all input from
`current-input-port'.
-- Function: readline [prompt]
Read and return a line of input from the user and return it as a
string (without a newline at the end). PROMPT is printed as a
prompt, or the default is the string set in `set-readline-prompt!'
below.
(readline "Type something: ") => "hello"
-- Function: activate-readline
Enable readline for all reading from `current-input-port' (*note
Default Ports::), and also enable readline features in the
interactive REPL (*note The REPL::).
(activate-readline)
(read-char)
`activate-readline' works by changing `current-input-port' to a
special soft port which calls the `readline' function above for
input. This means all the usual reading functions (`read',
`read-char', etc) work as normal, but the user has the interactive
editing features of readline.
-- Function: set-readline-prompt! prompt1 [prompt2]
Set the prompt string to print when reading input. This is used
when reading through `activate-readline', 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 Line Buffered
Input::) t indicate the boundaries of logical expressions
(assuming of course an application has such a notion).
6.5.4 Line Buffered Input
-------------------------
The following functions are provided by
(use-modules (ice-9 buffered-input))
A buffered input port allows a reader function to return chunks of
characters, which are to be handed out on reading the port. A notion
of when further input for an application level expression is maintained
too, and passed through to the reader.
-- Function: make-buffered-input-port reader
Create an input port which returns characters obtained from the
given READER function. READER is called (READER cont), and should
return a string or an EOF object.
The new port gives precisely the characters returned by READER,
nothing is added, so if any newline characters or other separators
are desired they must come from the reader function.
The CONT parameter to READER is `#f' for initial input, or `#t'
when continuing an expression. This is an application level
notion set with `set-buffered-input-continuation?!' below. If the
user has entered a partial expression then it allows the reader
for instance to give a different prompt to show more is required.
-- Function: make-line-buffered-input-port reader
Create an input port which returns characters obtained from the
specified READER function, similar to `make-buffered-input-port'
above, but where READER is expected to be a line-oriented.
READER is called (READER cont), and should return a string or an
EOF object as above. Each string is a line of input without a
newline character, the port code inserts a newline after each
string.
-- Function: set-buffered-input-continuation?! port cont
Set the input continuation flag for a given buffered input PORT.
An application uses this by calling with a CONT flag of `#f' when
beginning to read a new logical expression. For example with the
Scheme `read' function (*note Scheme Read::),
(define my-port (make-buffered-input-port my-reader))
(set-buffered-input-continuation?! my-port #f)
(let ((obj (read my-port)))
...
- Re: readline eats previous text on line,
Kevin Ryde <=