[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: |
John Mastro |
Subject: |
Re: Any infrastructure to select one of a few options in Emacs core? |
Date: |
Fri, 20 May 2016 16:52:30 -0700 |
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")))))
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.
John
- 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?, 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 <=
- 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?, 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