From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Any infrastructure to select one of a few options in Emacs core?
Date: Mon, 09 May 2016 20:36:54 +0200 [thread overview]
Message-ID: <87wpn3axix.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: 877ff3cdec.fsf@mbork.pl
Marcin Borkowski <mbork@mbork.pl> writes:
> On 2016-05-09, at 19:27, Drew Adams <drew.adams@oracle.com> wrote:
>
>>> > completing-read
>>>
>>> Yes and no. I thought about it, and rejected the idea: I want all the
>>> options to be visible without pressing TAB. Also, each option might
>>> need more than one line (and the number of lines may vary between
>>> options), so I don't like the idea of using minibuffer at all.
>>
>> It's still not clear from your description what you mean by "select"
>> one of the options.
>
> OK, so let us assume that I want the user to select one of the three
> strings: "spam", "eggs" and "emacs". (Note: in my use case they would
> not be string literals.) Then, I'd like to be able to say, e.g.,
> something like this:
>
> (ask-user-for-option "What would you like to eat?" '("spam" "ham" "eggs"))
>
> and have something like
>
> Wat would you like to eat?
>
> 1. spam
>
> 2. ham
>
> 3. eggs
>
> displayed (perhaps in a *temp* buffer or so), and wait for the user to
> press 1, 2 or 3. Then, the above form returns the selected string.
>
> It would probably be also useful to be able to give it e.g. cons cells
> with the car being the string and the cdr the value returned in case of
> selecting this particular string. Also, it should be customizable: one
> user might like digit keys, another one letters, for instance. Also,
> the choices should be clickable for those poor souls addicted to
> rodents.
>
> In a more advanced scenario, the menu might be "non-modal", i.e. do not
> use `read-key' or something like that, but a dynamically crafted mode
> (probably descendant of special-mode), in which various keys/clicks would
> launch a callback function given to the hypothetical
> `ask-user-for-option' with the selected choice as a parameter.
You can use a popup menu for that.
(let ((options '("spam" "ham" "eggs")))
(x-popup-menu (let ((mp (mouse-position)))
(list (list (cadr mp)
(cddr mp))
(selected-window)))
(list "menu"
(cons "What would yuo like to eat?"
(mapcar (lambda (option) (cons option option))
options)))))
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
next prev parent reply other threads:[~2016-05-09 18:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-09 10:09 Any infrastructure to select one of a few options in Emacs core? Marcin Borkowski
2016-05-09 14:13 ` Drew Adams
2016-05-09 15:40 ` Marcin Borkowski
2016-05-09 16:37 ` Kaushal Modi
2016-05-09 17:10 ` Marcin Borkowski
2016-05-09 17:27 ` Drew Adams
2016-05-09 18:08 ` Marcin Borkowski
2016-05-09 18:16 ` Drew Adams
2016-05-19 20:06 ` Marcin Borkowski
2016-05-20 1:16 ` John Mastro
2016-05-20 23:52 ` John Mastro
2016-05-21 20:48 ` Marcin Borkowski
2016-05-09 18:36 ` Pascal J. Bourguignon [this message]
2016-05-14 4:20 ` Emanuel Berg
2016-05-21 20:49 ` Marcin Borkowski
2016-05-14 4:18 ` Emanuel Berg
2016-05-21 20:52 ` Marcin Borkowski
[not found] ` <mailman.43.1463863961.1216.help-gnu-emacs@gnu.org>
2016-05-22 6:32 ` Emanuel Berg
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wpn3axix.fsf@kuiper.lan.informatimago.com \
--to=pjb@informatimago.com \
--cc=help-gnu-emacs@gnu.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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.