emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master b3a28d0: Make the read-multiple-choice prompt a bit


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master b3a28d0: Make the read-multiple-choice prompt a bit prettier
Date: Fri, 05 Feb 2016 01:31:42 +0000

branch: master
commit b3a28d088ff060df7690ffeaa04ac97f5c072e81
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    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.
---
 doc/lispref/commands.texi |    6 +++++-
 lisp/subr.el              |   16 +++++++++++-----
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi
index 1964ec8..3ea6ea0 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 db1baf0..a45d4a7 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]