[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question to completion

From: Klaus Berndl
Subject: Re: Question to completion
Date: 09 Nov 2003 18:21:06 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Thanks a lot, Ehud, your code works very well. But in the meanwhile i have
found a solution for myself. Could you please compare yours with mine and tell
me which is better and why? In general my solution seems to be a little hack -
your seems cleaner...

(defun ecb-offer-choices (prompt choices)
  "Prints PROMPT and returns a string which must be one of CHOICES.
CHOICES is a list of strings whereas the first choice is the default. All
choices are immediately displayed as if completion does it so a selection can
be made either with the mouse or with the keyboard."
  ;; First we create a TAB-event
  (let ((event (if ecb-running-xemacs
                   (make-event 'key-press '(key tab))
    ;; With these 3 TAB-events we ensure that
    ;; 1. The longest possible common substring is display in the minibuffer
    ;; 2. All possible completions are displayed
    (dotimes (i 3)
      (setq unread-command-events (cons event unread-command-events))))
  (let ((answer (completing-read
                 (mapcar (function (lambda (x) (list x t)))
                 nil t)))
    (if (string= answer "")
        (car choices)

The advantage of my solution is that in the minibuffer autom. the longest
possible completion is displayed (in your example this would be the following
"Select a name: Klaus"


On Sun, 9 Nov 2003, Ehud Karni wrote:

>  On 08 Nov 2003 13:52:06 +0100, Klaus Berndl <address@hidden> wrote:
> >
> > Suppose i have s command like follows:
> >
> > (defun offer-some-choices ()
> >   (interactive)
> >   (completing-read "Select a name: " '(("Klaus" . t) ("Berndl" . t))))
> >
> > Then this displays in the minibuffer "Select a name: " and then wait for
> > input from the user.
> >
> > How can i achieve that always - *without* the user has to hit TAB - the
> > possible completions are displayed immediately?
>  You have 2 choices:
>    1. Run the function corresponding to [tab] 3 times (by preloading the
>       keyboard buffer or by adding it to `minibuffer-setup-hook'.
>       This will make some extra displays and has built in delay.
>    2. Defining a simple function to display all possible completions
>       and adding it to `minibuffer-setup-hook'.
>  Here is the function and an example to the 2nd solution:
>  (defun minibuffer-all-completion ()
>         (with-output-to-temp-buffer "*Completions*"
>             (display-completion-list (all-completions ""
>             minibuffer-completion-table))))
>  ;; An example.
>  (defun offer-some-choices ()
>    (interactive)
>         (let* ((minibuffer-setup-hook
>                      (append minibuffer-setup-hook
>                      '(minibuffer-all-completion))))
>             (completing-read "Select a name: "
>                     '(("Klaus" . t) ("Klaus-2" . t) ("Klaus-3" . t)))
>             ))
>  Ehud.

Klaus Berndl                    mailto: address@hidden
sd&m AG               
software design & management    
Carl-Wery-Str. 42, 81739 Muenchen, Germany
Tel +49 89 63812-392, Fax -220

reply via email to

[Prev in Thread] Current Thread [Next in Thread]