[Top][All Lists]

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

Re: menu system in recent Emacs?

From: Stefan Monnier
Subject: Re: menu system in recent Emacs?
Date: Wed, 02 May 2012 21:47:58 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

>    I would really like it to show the list of choices immediately,
>    as if the user pressed `TAB'.  Can that be fed into the
>    function somehow as a synthetic keypress?

> That would be:

> (progn
>   (push ?\t unread-command-events)
>   (completing-read 
>    "Here are some choices:\n- A\t- B\n- C\t- D\nChoose one: "

Note: this will only work when the minibuffer can grow to have
enough lines.  E.g. my minibuffer-only frame would display this prompt
in a way that's rather incomprehensible.

> (progn
>   (push ?\t unread-command-events)
>   (completing-read 
>    "CHOICE EXPLANATION\nChoose one: "
>    '("A" "B" "C" "D")))

That's pretty ugly.
I recommend something more like

   (minibuffer-with-setup-hook #'minibuffer-completion-help
     (completing-read ...))

As for the explanation, you could add an `annotation-function' metadata
to the completion-table.  Something like

   (let ((table (lambda (string pred action)
                  (if (eq action 'metadata)
                      `(metadata (annotation-function
                                  . ,(lambda (s)
                                        ((equal s "A") " explanation a")
                                        ((equal s "B") " explanation b")
                                        ((equal s "C") " explanation c")
                                        ((equal s "D") " explanation d")))))
                    (complete-with-action action '("A" "B" "C" "D")
                                          string pred)))))
     (minibuffer-with-setup-hook #'minibuffer-completion-help
       (completing-read "prompt:" table)))

-- Stefan

reply via email to

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