[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: |
Thu, 19 May 2016 22:06:49 +0200 |
User-agent: |
mu4e 0.9.16; emacs 25.1.50.1 |
On 2016-05-09, at 20:16, Drew Adams <drew.adams@oracle.com> wrote:
>> (ask-user-for-option "What would you like to eat?" '("spam" "ham" "eggs"))
>
> So this has nothing to do with Emacs _options_.
>
> You are asking how to present some choices to a user for
> selection.
Yes, sorry for the confusion.
I went with this code:
--8<---------------cut here---------------start------------->8---
(defun select-choice (message choices)
"Display a buffer with MESSAGE and then CHOICES.
Each element of CHOICES should be a cons cell, whose car is the
result and the cdr is the description. The user may select one
by pressing a digit."
;; TODO: This function is way too simple and not fool-proof!
(if (> (length choices) 9)
(error "Too many choices!")
(save-window-excursion
(pop-to-buffer " *amsrefs doi selection*" t t)
(delete-other-windows) ; TODO: this should be fixed
(erase-buffer)
(insert message "\n\n")
(let ((i 0))
(dolist (choice choices)
(setq i (1+ i))
(insert (format "%d. %s\n\n" i (cdr choice)))))
(let ((key (read-key)))
(if (<= 49 key 57)
(car (nth (- key 49) choices))
(error "Wrong key pressed!"))))))
--8<---------------cut here---------------end--------------->8---
As it is said in the comment, it is far from ideal, but the whole
program I've been writing for my friend is one big quick hack, so
I didn't bother too much.
Still, it would be really nice if Emacs offered a canonical (and
configurable) way to do things like that.
Best,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
- 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 <=
- 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, 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