all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Klaus Berndl <klaus.berndl@sdm.de>
Subject: Re: Question to completion
Date: 09 Nov 2003 18:21:06 +0100	[thread overview]
Message-ID: <ubrrlwj99.fsf@sdm.de> (raw)
In-Reply-To: mailman.73.1068392321.2005.help-gnu-emacs@gnu.org


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))
                 9)))
    ;; 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
                 prompt
                 (mapcar (function (lambda (x) (list x t)))
                         choices)
                 nil t)))
    (if (string= answer "")
        (car choices)
      answer)))

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
minibuffer-content:
"Select a name: Klaus"

Ciao,
Klaus

On Sun, 9 Nov 2003, Ehud Karni wrote:

>  On 08 Nov 2003 13:52:06 +0100, Klaus Berndl <klaus.berndl@sdm.de> 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: klaus.berndl@sdm.de
sd&m AG				http://www.sdm.de
software design & management	
Carl-Wery-Str. 42, 81739 Muenchen, Germany
Tel +49 89 63812-392, Fax -220

  parent reply	other threads:[~2003-11-09 17:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-08 12:52 Question to completion Klaus Berndl
2003-11-08 14:14 ` Klaus Berndl
2003-11-09 14:36 ` Ehud Karni
     [not found] ` <mailman.73.1068392321.2005.help-gnu-emacs@gnu.org>
2003-11-09 17:21   ` Klaus Berndl [this message]
2003-11-10 16:20   ` Stefan Monnier
2003-11-09 19:04 ` jan

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ubrrlwj99.fsf@sdm.de \
    --to=klaus.berndl@sdm.de \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.