unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Thien-Thi Nguyen <ttn@gnuvola.org>
Cc: emacs-devel@gnu.org
Subject: Re: menu system in recent Emacs?
Date: Wed, 02 May 2012 21:47:58 -0400	[thread overview]
Message-ID: <jwv1un2vy8t.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <871un2m5j8.fsf@gnuvola.org> (Thien-Thi Nguyen's message of "Thu,  03 May 2012 03:12:27 +0200")

>    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)
                                       (cond
                                        ((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



  parent reply	other threads:[~2012-05-03  1:47 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-28  0:45 auth-source change default spec Tim Cross
2012-04-28  8:46 ` Tim Cross
2012-04-28 15:08   ` Stefan Monnier
2012-04-29  0:04     ` Tim Cross
2012-04-30 12:23 ` Ted Zlatanov
2012-04-30 12:51   ` Richard Riley
2012-04-30 22:41     ` Tim Cross
2012-05-01 14:00     ` Ted Zlatanov
2012-05-01 21:41       ` Tim Cross
2012-05-02 12:25         ` Ted Zlatanov
2012-05-02 13:59           ` menu system in recent Emacs? (was: auth-source change default spec) Ted Zlatanov
2012-05-02 14:37             ` menu system in recent Emacs? Davis Herring
2012-05-02 15:07               ` Ted Zlatanov
2012-05-02 18:52             ` Tassilo Horn
2012-05-02 19:35               ` Ted Zlatanov
2012-05-02 18:00                 ` Eric Schulte
2012-05-02 21:34                   ` Ted Zlatanov
2012-05-02 23:52                     ` Thien-Thi Nguyen
2012-05-03  0:53                       ` Ted Zlatanov
2012-05-03  1:12                         ` Thien-Thi Nguyen
2012-05-03  1:44                           ` Ted Zlatanov
2012-05-03  1:47                           ` Stefan Monnier [this message]
2012-05-03  5:21                           ` Thierry Volpiatto
2012-05-03  6:25                             ` Thierry Volpiatto
2012-05-03  7:13                             ` Thien-Thi Nguyen
2012-05-03  7:28                               ` Thierry Volpiatto
2012-05-03  6:18                   ` Stefan Reichör
2012-05-03 12:01                     ` Ted Zlatanov
2012-05-03  4:09           ` auth-source change default spec Tim Cross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv1un2vy8t.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=ttn@gnuvola.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).