unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Cc: guile-user@gnu.org
Subject: Re: readline eats previous text on line
Date: Thu, 05 Oct 2006 09:13:41 +1000	[thread overview]
Message-ID: <8764ezu122.fsf@zip.com.au> (raw)
In-Reply-To: <87bqoujltw.fsf@zip.com.au> (Kevin Ryde's message of "Tue, 03 Oct 2006 10:15:55 +1000")

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


  parent reply	other threads:[~2006-10-04 23:13 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
2006-10-03  0:15             ` Kevin Ryde
2006-10-03  0:52               ` Kevin Ryde
2006-10-04 23:13               ` Kevin Ryde [this message]
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=8764ezu122.fsf@zip.com.au \
    --to=user42@zip.com.au \
    --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).