Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elisp function select argument from list

Tags:

emacs

elisp

I have an Elisp function which takes one argument (so far so good). This one argument is supposed to be an item from a list, and nothing else.

Is there a way I can display the list in kind of a "selection buffer" (like dired), where the user can navigate to the item and select it by hitting enter, instead of having to type out the string manually?

like image 426
cbrst Avatar asked Nov 04 '13 16:11

cbrst


3 Answers

The usual way to do that is via completing-read. You can then use a minibuffer-with-setup-hook where you call minibuffer-completion-help so as to pop up a *Completions* buffer right away, so the user can click on his choice.

like image 78
Stefan Avatar answered Nov 05 '22 01:11

Stefan


What you are looking for is completing-read:

(defun foo (arg)
  (interactive (list (completing-read ...)))
  ....)
like image 23
sds Avatar answered Nov 05 '22 00:11

sds


If I understood the question correctly, you are looking for something like this:

(defun foo (list)
  (interactive)
  (let ((arg (ido-completing-read "Select from list: " list))))
     ...)

The selection process is not like dired, but it is common for emacs users to select from a list using ido or other similar alternatives. You can narrow your search, move between alternatives and a long etc. Type M-x customize-group RET ido if you want to have a feeling of what preferences you may customize.

like image 38
juanleon Avatar answered Nov 05 '22 00:11

juanleon