From: Lars Ingebrigtsen Date: Fri, 5 Feb 2016 01:31:17 +0000 (+1100) Subject: Make the read-multiple-choice prompt a bit prettier X-Git-Tag: emacs-26.0.90~2736 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b3a28d088ff060df7690ffeaa04ac97f5c072e81;p=emacs.git Make the read-multiple-choice prompt a bit prettier * doc/lispref/commands.texi (Reading One Event): Mention read-multiple-choice-face. * lisp/subr.el (read-multiple-choice): Make the prompting a bit prettier. --- diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi index 1964ec8e3fe..3ea6ea045eb 100644 --- a/doc/lispref/commands.texi +++ b/doc/lispref/commands.texi @@ -2618,7 +2618,7 @@ then continues to wait for a valid input character, or keyboard-quit. @end defun @defun read-multiple-choice prompt choices -Ask user a multiple choice question. @var{prompt} should be a string +Ask user a multiple choice question. @var{prompt} should be a string that will be displayed as the prompt. @var{choices} is an alist where the first element in each entry is a @@ -2636,6 +2636,10 @@ The return value is the matching value from @var{choices}. (?s "session only" "Accept this certificate this session only.") (?n "no" "Refuse to use this certificate, and close the connection."))) @end lisp + +The @code{read-multiple-choice-face} face is used to highlight the +matching characters in the name string on graphical terminals. + @end defun @node Event Mod diff --git a/lisp/subr.el b/lisp/subr.el index db1baf09c43..a45d4a721b7 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2255,7 +2255,7 @@ Usage example: (let* ((altered-names nil) (full-prompt (format - "%s (%s, ?): " + "%s (%s): " prompt (mapconcat (lambda (elem) @@ -2285,19 +2285,25 @@ Usage example: (push (cons (car elem) altered-name) altered-names) altered-name)) - choices ", "))) - tchar buf) + (append choices '((?? "?"))) + ", "))) + tchar buf wrong-char) (save-window-excursion (save-excursion (while (not tchar) - (message "%s" full-prompt) + (message "%s%s" + (if wrong-char + "Invalid choice. " + "") + full-prompt) (setq tchar (condition-case nil (read-char) (error nil))) ;; The user has entered an invalid choice, so display the ;; help messages. (when (not (assq tchar choices)) - (setq tchar nil) + (setq wrong-char (not (memq tchar '(?? ?\C-h))) + tchar nil) (with-help-window (setq buf (get-buffer-create "*Multiple Choice Help*")) (with-current-buffer buf