From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Klaus Berndl Newsgroups: gmane.emacs.help Subject: Re: Question to completion Date: 09 Nov 2003 18:21:06 +0100 Organization: "sd&m AG, Muenchen, Germany" Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1068398988 1350 80.91.224.253 (9 Nov 2003 17:29:48 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 9 Nov 2003 17:29:48 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Nov 09 18:29:46 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AItNi-0005ur-00 for ; Sun, 09 Nov 2003 18:29:46 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AIuKh-0002O3-Vv for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Nov 2003 13:30:43 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewsoutpeer00.lnd.ops.eu.uu.net!lnewsinpeer01.lnd.ops.eu.uu.net!emea.uu.net!news.sdm.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 85 Original-NNTP-Posting-Host: callin10.muc.sdm.de Original-X-Trace: news.sdm.de 1068398472 8994 195.125.139.10 (9 Nov 2003 17:21:12 GMT) Original-X-Complaints-To: usenet@news.sdm.de Original-NNTP-Posting-Date: Sun, 9 Nov 2003 17:21:12 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Original-Xref: shelby.stanford.edu gnu.emacs.help:118034 X-Originally-To: ehud@unix.mvs.co.il Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:13973 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:13973 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 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