* Question to completion
@ 2003-11-08 12:52 Klaus Berndl
2003-11-08 14:14 ` Klaus Berndl
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Klaus Berndl @ 2003-11-08 12:52 UTC (permalink / raw)
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?
Or with other words: How to simulate that the user has already pressed TAB as
often as necessary to display all possible completions? Best would be if the
longest common substring of all possible completions is displayed immediately
in the minibuffer (OK, this i could precompute with `try-completion' and then
insert as argument INITIAL-INPUT - but AFAIK this is deprecated?!).
But most important is that the user has not to hit any key to see all possible
completions. How to do this with completing-read - or is there a better way to
do this?
What i want is to (mis?)use the completion-feature of Emacs to offer the user
some choices which he can select either via mouse or via keyboard from the
minibuffer.
Thanks a lot in advance!
Klaus
--
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Question to completion
2003-11-08 12:52 Question to completion Klaus Berndl
@ 2003-11-08 14:14 ` Klaus Berndl
2003-11-09 14:36 ` Ehud Karni
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Klaus Berndl @ 2003-11-08 14:14 UTC (permalink / raw)
Until now i have written a first solution which does what i want:
(defun offer-some-choices ()
(interactive)
;; 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
(setq unread-command-events (cons 9 unread-command-events))
(setq unread-command-events (cons 9 unread-command-events))
(setq unread-command-events (cons 9 unread-command-events))
(let ((file (completing-read
"Select a file: "
'(("c:/Programme/emacs-21/site-lisp/semantic/semanticdb-test.el" . t)
("c:/Programme/emacs-21/site-lisp/ecb-navigate.el" . t)))))
(message "Choosen file: %s" file)))
Now my question: Is this completely an ugly hack and what to do to write this
better?
Thanks for help,
Klaus
On 08 Nov 2003, Klaus Berndl 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? Or with other words: How to
> simulate that the user has already pressed TAB as often as necessary to
> display all possible completions? Best would be if the longest common
> substring of all possible completions is displayed immediately in the
> minibuffer (OK, this i could precompute with `try-completion' and then
> insert as argument INITIAL-INPUT - but AFAIK this is deprecated?!).
>
> But most important is that the user has not to hit any key to see all
> possible completions. How to do this with completing-read - or is there a
> better way to do this?
>
> What i want is to (mis?)use the completion-feature of Emacs to offer the
> user some choices which he can select either via mouse or via keyboard from
> the minibuffer.
>
> Thanks a lot in advance!
> Klaus
--
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Question to completion
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 19:04 ` jan
3 siblings, 0 replies; 6+ messages in thread
From: Ehud Karni @ 2003-11-09 14:36 UTC (permalink / raw)
Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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.
- --
Ehud Karni Tel: +972-3-7966-561 /"\
Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign
Insurance agencies (USA) voice mail and X Against HTML Mail
http://www.mvs.co.il FAX: 1-815-5509341 / \
GnuPG: 98EA398D <http://www.keyserver.net/> Better Safe Than Sorry
-----BEGIN PGP SIGNATURE-----
Comment: use http://www.keyserver.net/ to get my key (and others)
iD8DBQE/rlDxLFvTvpjqOY0RAiDLAJ47APX46csdk5+W+vQS093NKS1jpACeIjp3
1oKBBDBs6ICQY2S5ZWl4BPk=
=qqew
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Question to completion
[not found] ` <mailman.73.1068392321.2005.help-gnu-emacs@gnu.org>
@ 2003-11-09 17:21 ` Klaus Berndl
2003-11-10 16:20 ` Stefan Monnier
1 sibling, 0 replies; 6+ messages in thread
From: Klaus Berndl @ 2003-11-09 17:21 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Question to completion
2003-11-08 12:52 Question to completion Klaus Berndl
` (2 preceding siblings ...)
[not found] ` <mailman.73.1068392321.2005.help-gnu-emacs@gnu.org>
@ 2003-11-09 19:04 ` jan
3 siblings, 0 replies; 6+ messages in thread
From: jan @ 2003-11-09 19:04 UTC (permalink / raw)
Klaus Berndl <klaus.berndl@sdm.de> writes:
> 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? Or with other
> words: How to simulate that the user has already pressed TAB as
> often as necessary to display all possible completions? Best would
> be if the longest common substring of all possible completions is
> displayed immediately in the minibuffer (OK, this i could precompute
> with `try-completion' and then insert as argument INITIAL-INPUT -
> but AFAIK this is deprecated?!).
>
> But most important is that the user has not to hit any key to see
> all possible completions. How to do this with completing-read - or
> is there a better way to do this?
>
> What i want is to (mis?)use the completion-feature of Emacs to offer
> the user some choices which he can select either via mouse or via
> keyboard from the minibuffer.
`icomplete-mode' might be a good starting point.
--
jan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Question to completion
[not found] ` <mailman.73.1068392321.2005.help-gnu-emacs@gnu.org>
2003-11-09 17:21 ` Klaus Berndl
@ 2003-11-10 16:20 ` Stefan Monnier
1 sibling, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2003-11-10 16:20 UTC (permalink / raw)
> (defun minibuffer-all-completion ()
> (with-output-to-temp-buffer "*Completions*"
> (display-completion-list (all-completions "" minibuffer-completion-table))))
Better just use minibuffer-completion-help.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2003-11-10 16:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2003-11-10 16:20 ` Stefan Monnier
2003-11-09 19:04 ` jan
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).