Elisp function selection item from the list

I have an Elisp function that takes one argument (so good). This one argument must be an item from a list, and nothing more.

Is there a way to display the list as a "selection buffer" (for example, dired), where the user can go to the item and select it by pressing enter, instead of entering a line manually?

+6
source share
4 answers

The usual way to do this is through completing-read . Then you can use minibuffer-with-setup-hook , where you call minibuffer-completion-help to immediately open the *Completions* buffer so that the user can click on his choice.

+5
source

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 a phased one, but for users, emacs is often selected from a list using ido or other similar alternatives. You can narrow your search, move between alternatives and long, etc. The Mx type is customize-group RET ido if you want to have an idea of ​​what settings you can configure.

+4
source

What you are looking for is completing-read :

 (defun foo (arg) (interactive (list (completing-read ...))) ....) 
+4
source

I like to use popup menus for things like this:

 (x-popup-menu (list '(50 50) (selected-frame)) ;; where to popup (list "Please choose" ;; the menu itself (cons "" (mapcar (function (lambda (item) (cons item item))) your-list-of-strings)))) 

BTW, I would like to use (mapcar 'cons your-list-of-strings your-list-of-strings) Γ  la Common Lisp, but elisp accepts only unary functions in mapcar :-(

0
source

Source: https://habr.com/ru/post/957357/


All Articles