]> code.delx.au - gnu-emacs/commitdiff
Make the read-multiple-choice prompt a bit prettier
authorLars Ingebrigtsen <larsi@gnus.org>
Fri, 5 Feb 2016 01:31:17 +0000 (12:31 +1100)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 5 Feb 2016 01:31:34 +0000 (12:31 +1100)
* doc/lispref/commands.texi (Reading One Event): Mention
read-multiple-choice-face.

* lisp/subr.el (read-multiple-choice): Make the prompting a bit
prettier.

doc/lispref/commands.texi
lisp/subr.el

index 1964ec8e3feb98ce3eecbdff7a2d28d54884ad90..3ea6ea045eb856fd51469a322a08cfcceffbeaef 100644 (file)
@@ -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
index db1baf09c43ca9594826d6abb728c01052df6e24..a45d4a721b7bc110b09d83359733053ce85d599b 100644 (file)
@@ -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