* Reading char choices
@ 2011-01-07 16:14 Chong Yidong
2011-01-07 17:16 ` Davis Herring
0 siblings, 1 reply; 3+ messages in thread
From: Chong Yidong @ 2011-01-07 16:14 UTC (permalink / raw)
To: emacs-devel
There are a couple of places in Emacs where we do a multiple-choice
query, looping until the user inputs one of a list of acceptable chars.
See, e.g., dired-query and hack-local-variables-confirm.
I think we should assign a standard function to this, as shown below.
Thoughts?
(defun read-char-choice (prompt chars &optional inhibit-keyboard-quit)
"Read and return one of CHARS, prompting for PROMPT.
Any input that is not one of CHARS is ignored.
If optional argument INHIBIT-KEYBOARD-QUIT is non-nil, ignore
keyboard-quit events while waiting for a valid input."
(let ((cursor-in-echo-area t)
(executing-kbd-macro executing-kbd-macro)
char done)
(while (not done)
(message "%s" prompt)
(setq char (read-event))
(if (numberp char)
(cond ((and executing-kbd-macro (= char -1))
;; read-event returns -1 if we are in a kbd macro and
;; there are no more events in the macro. Attempt to
;; get an event interactively.
(setq executing-kbd-macro nil))
((eq (key-binding (vector char)) 'keyboard-quit)
(if inhibit-keyboard-quit (keyboard-quit)))
((setq done (memq char chars))))))
;; Display the question with the answer.
(message "%s" (concat prompt (char-to-string char)))
char))
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Reading char choices
2011-01-07 16:14 Reading char choices Chong Yidong
@ 2011-01-07 17:16 ` Davis Herring
2011-01-08 19:35 ` Chong Yidong
0 siblings, 1 reply; 3+ messages in thread
From: Davis Herring @ 2011-01-07 17:16 UTC (permalink / raw)
To: Chong Yidong; +Cc: emacs-devel
> (message "%s" prompt)
> (setq char (read-event))
Couldn't we pass the prompt to read-event? Also, how does this inhibit
quitting out of the whole function?
> ((eq (key-binding (vector char)) 'keyboard-quit)
> (if inhibit-keyboard-quit (keyboard-quit)))
If I'm missing something and we really do inhibit quitting, surely this
should be (unless inhibit-keyboard-quit ...).
> ((setq done (memq char chars))))))
So if it's not valid, we just ignore it. Would we rather display a
message (as for `y-or-n-p'), at least optionally?
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Reading char choices
2011-01-07 17:16 ` Davis Herring
@ 2011-01-08 19:35 ` Chong Yidong
0 siblings, 0 replies; 3+ messages in thread
From: Chong Yidong @ 2011-01-08 19:35 UTC (permalink / raw)
To: herring; +Cc: emacs-devel
"Davis Herring" <herring@lanl.gov> writes:
> Couldn't we pass the prompt to read-event? Also, how does this
> inhibit quitting out of the whole function?
> ...
> If I'm missing something and we really do inhibit quitting, surely
> this should be (unless inhibit-keyboard-quit ...).
Fixed, thanks. Seems that dired-query, from which I factored out this
code, was a bit buggy.
>> ((setq done (memq char chars))))))
>
> So if it's not valid, we just ignore it. Would we rather display a
> message (as for `y-or-n-p'), at least optionally?
That's fine if someone wants to implement it. Currently, we don't do
this for the risky local variables prompt, nor for dired-query.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-01-08 19:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-07 16:14 Reading char choices Chong Yidong
2011-01-07 17:16 ` Davis Herring
2011-01-08 19:35 ` Chong Yidong
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.