help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Any standard function to prompt for multiple comma-separated items?


From: Klaus Berndl
Subject: Re: Any standard function to prompt for multiple comma-separated items?
Date: 17 Nov 2002 10:27:08 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

On Fri, 15 Nov 2002, Peter S. Galbraith wrote:



>  Hello,
>  
>  For MH-E, I'm looking for code already available in Emacs to do
>  completing-read for multiple comma-separated items.  e.g.
>  
>  To: p.gal[TAB]
>  ->
>  To: p.galbraith
>  ->
>  To: p.galbraith, psg[TAB]
>  ->
>  To: p.galbraith, psg@home
>  
>  Does anyone now of such code already existing?
>  
>  There's multi-prompt.el bundled with AUC-TeX that comes close (doesn't
>  allow whitespace after the field separator), but I need something I can
>  use in MH-E without external packages.

Hmm, i do not know if i understand your problem in the right way...Do you want
this completion in the minibuffer or is it more like dabbrev-completion in a
"normal" buffer?
Even more: What should be the domain of the completion, i.e. the set of
allowed completions??

If you are searching for something in the minibuffer, here is a function:

,----
| ;; stolen from query.el and slightly enhanced
| (defun ecb-query-string (prompt choices &optional other-prompt)
|   "Prints PROMPT and returns a string which must be one of CHOICES.
| CHOICES is either a list of strings whereas the first choice is the default
| \(which is returned if the user simply types RET) or nil \(then only a simple
| RET quits the query and returns nil). If OTHER-PROMPT is not nil and a string
| then the choice \"other\" is added to CHOICES and after selecting this choice
| the user is prompted with OTHER-PROMPT to insert any arbitrary string."
|   (let* ((new-choices (if other-prompt
|                           (add-to-list 'choices "other" t)
|                         choices))
|          (default (car new-choices))
|          answer)
|     (setq prompt (concat prompt
|                          " ["
|                          (if new-choices
|                              (mapconcat (function (lambda (x) x))
|                                         new-choices ", ")
|                            "RET")
|                          "] "))
|     (setq new-choices (nconc (mapcar (function (lambda (x) (list x t)))
|                                      new-choices)
|                              '('("" t))))
|     (setq answer (completing-read prompt new-choices nil t ""))
|     (cond ((string= answer "")
|            (setq answer default))
|           ((string= answer "other")
|            (setq answer (read-string (concat other-prompt ": ")))))
|     answer))
`----

Klaus

-- 
Klaus Berndl                    mailto: klaus.berndl@sdm.de
sd&m AG                         http://www.sdm.de
software design & management
Thomas-Dehler-Str. 27, 81737 München, Germany
Tel +49 89 63812-392, Fax -220


reply via email to

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