[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Any infrastructure to select one of a few options in Emacs core?
From: |
Marcin Borkowski |
Subject: |
Re: Any infrastructure to select one of a few options in Emacs core? |
Date: |
Sat, 21 May 2016 22:48:14 +0200 |
User-agent: |
mu4e 0.9.16; emacs 25.1.50.1 |
On 2016-05-21, at 01:52, John Mastro <john.b.mastro@gmail.com> wrote:
> John Mastro <john.b.mastro@gmail.com> wrote:
>
>> I played around with a few cosmetic changes to your function and ended
>> up with this:
>
> I realized that, for my use case, it makes more sense to let the caller
> specify the characters rather than automatically using the digits 1-9.
> So I ended up with this instead, which is also a bit shorter and
> simpler.
>
> (defun read-choice (prompt choices)
> (let ((cursor-in-echo-area t)
> (prompt (if (get-text-property 0 'face prompt)
> prompt
> (propertize prompt
> 'face
> 'minibuffer-prompt))))
> (save-window-excursion
> (pop-to-buffer " *Read choice*" t t)
> (setq-local cursor-type nil)
> (erase-buffer)
> (pcase-dolist (`(,char ,description) choices)
> (insert (propertize (string char)
> 'face
> 'font-lock-variable-name-face)
> (format " %s\n" description)))
> (goto-char (point-min))
> (fit-window-to-buffer)
> (or (assoc (read-key prompt) choices)
> (user-error "Invalid selection")))))
Nice, thanks! I didn't know about several things you used here - every
day is an opportunity to learn! (I'll finally have to read about pcase,
too.) I like especially the `fit-window-to-buffer' function - it seems
it's exactly what I needed, much better than my `delete-other-windows'!
Also, it seems you don't need `setq-local' here, since `cursor-type' is
automatically buffer-local anyway.
> In Emacs's master branch (but not the emacs-25 release branch) there's a
> new function `read-multiple-choice' that's similar in purpose and worth
> a look.
Yes, I've seen that. Not useful for me, though -- in my use case the
descriptions of the choices are too long (maybe even several lines!).
> John
Best,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
- RE: Any infrastructure to select one of a few options in Emacs core?, (continued)
- RE: Any infrastructure to select one of a few options in Emacs core?, Drew Adams, 2016/05/09
- Re: Any infrastructure to select one of a few options in Emacs core?, Marcin Borkowski, 2016/05/09
- Re: Any infrastructure to select one of a few options in Emacs core?, Kaushal Modi, 2016/05/09
- Re: Any infrastructure to select one of a few options in Emacs core?, Marcin Borkowski, 2016/05/09
- RE: Any infrastructure to select one of a few options in Emacs core?, Drew Adams, 2016/05/09
- Re: Any infrastructure to select one of a few options in Emacs core?, Marcin Borkowski, 2016/05/09
- RE: Any infrastructure to select one of a few options in Emacs core?, Drew Adams, 2016/05/09
- Re: Any infrastructure to select one of a few options in Emacs core?, Marcin Borkowski, 2016/05/19
- Re: Any infrastructure to select one of a few options in Emacs core?, John Mastro, 2016/05/19
- Re: Any infrastructure to select one of a few options in Emacs core?, John Mastro, 2016/05/20
- Re: Any infrastructure to select one of a few options in Emacs core?,
Marcin Borkowski <=
- Re: Any infrastructure to select one of a few options in Emacs core?, Pascal J. Bourguignon, 2016/05/09
- Re: Any infrastructure to select one of a few options in Emacs core?, Emanuel Berg, 2016/05/16
- Re: Any infrastructure to select one of a few options in Emacs core?, Marcin Borkowski, 2016/05/21
Re: Any infrastructure to select one of a few options in Emacs core?, Emanuel Berg, 2016/05/16