unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* 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

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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).