Function: sc-ask

sc-ask is a byte-compiled function defined in supercite.el.gz.

Signature

(sc-ask ALIST)

Documentation

Ask a question in the minibuffer requiring a single character answer.

This function is kind of an extension of y-or-n-p where a single letter is used to answer a question. Question is formed from ALIST
which has members of the form: (WORD . LETTER). WORD is the long
word form, while LETTER is the letter for selecting that answer. The selected letter is returned, or nil if the question was not answered. Note that WORD is a string and LETTER is a character. All LETTERs in the list should be unique.

Source Code

;; Defined in /usr/src/emacs/lisp/mail/supercite.el.gz
;; ======================================================================
;; utility functions

(defun sc-ask (alist)
  "Ask a question in the minibuffer requiring a single character answer.
This function is kind of an extension of `y-or-n-p' where a single
letter is used to answer a question.  Question is formed from ALIST
which has members of the form:  (WORD . LETTER).  WORD is the long
word form, while LETTER is the letter for selecting that answer.  The
selected letter is returned, or nil if the question was not answered.
Note that WORD is a string and LETTER is a character.  All LETTERs in
the list should be unique."
  (let* ((prompt (concat
                  (mapconcat #'car alist ", ")
		  "? ("
		  (mapconcat
		   (lambda (elt) (char-to-string (cdr elt))) alist "/")
		  ") "))
	 (p prompt)
         event)
    (while (stringp p)
      (if (let ((cursor-in-echo-area t)
		(inhibit-quit t))
	    (message "%s" p)
	    (setq event (read-event))
	    (prog1 quit-flag (setq quit-flag nil)))
	  (progn
	    (message "%s%s" p (single-key-description event))
	    (setq quit-flag nil)
	    (signal 'quit '())))
      (let ((char event)
	    elt)
	(if char (setq char (downcase char)))
	(cond
	 ((setq elt (rassq char alist))
	  (message "%s%s" p (car elt))
	  (setq p (cdr elt)))
	 (t
	  (message "%s%s" p (single-key-description event))
	  (ding)
	  (discard-input)
	  (if (eq p prompt)
	      (setq p (concat "Try again.  " prompt)))))))
    p))