]> git.eshelyaron.com Git - emacs.git/commitdiff
read-multiple-choice: Display "SPC" instead of " "
authorStefan Kangas <stefan@marxist.se>
Sun, 26 Dec 2021 05:47:15 +0000 (06:47 +0100)
committerStefan Kangas <stefan@marxist.se>
Sun, 26 Dec 2021 16:05:39 +0000 (17:05 +0100)
* lisp/emacs-lisp/rmc.el (rmc--add-key-description): Improve display
of the keys TAB, RET, SPC, DEL, and ESC.  This fixes a bug where " "
was highlighted in the description in a confusing way.
* test/lisp/emacs-lisp/rmc-tests.el
(test-rmc--add-key-description)
(test-rmc--add-key-description/with-attributes): Update tests for the
above change.

lisp/emacs-lisp/rmc.el
test/lisp/emacs-lisp/rmc-tests.el

index 90fd8b370e8e653e00bf68c3551e481c9922cac1..522d395eba70eb4229c0324f7d965f0081772d12 100644 (file)
 (require 'seq)
 
 (defun rmc--add-key-description (elem)
-  (let* ((name (cadr elem))
-         (pos (seq-position name (car elem)))
+  (let* ((char (car elem))
+         (name (cadr elem))
+         (pos (seq-position name char))
+         (desc (key-description (char-to-string char)))
          (graphical-terminal
           (display-supports-face-attributes-p
            '(:underline t) (window-frame)))
          (altered-name
           (cond
-           ;; Not in the name string.
-           ((not pos)
-            (let ((ch (char-to-string (car elem))))
-              (format "[%s] %s"
-                      (if graphical-terminal
-                          (propertize ch 'face 'read-multiple-choice-face)
-                        ch)
-                      name)))
+           ;; Not in the name string, or a special character.
+           ((or (not pos)
+                (member desc '("ESC" "TAB" "RET" "DEL" "SPC")))
+            (format "[%s] %s"
+                    (if graphical-terminal
+                        (propertize desc 'face 'read-multiple-choice-face)
+                      desc)
+                    name))
            ;; The prompt character is in the name, so highlight
            ;; it on graphical terminals.
            (graphical-terminal
@@ -57,7 +59,7 @@
              (upcase (substring name pos (1+ pos)))
              "]"
              (substring name (1+ pos)))))))
-    (cons (car elem) altered-name)))
+    (cons char altered-name)))
 
 (defun rmc--show-help (prompt help-string show-help choices altered-names)
   (let* ((buf-name (if (stringp show-help)
index a97254c46dcab8a8d02632af24213158dbb01954..5a79c505ae29846a662e70e4363a2c7e669926a4 100644 (file)
@@ -34,7 +34,9 @@
     (should (equal (rmc--add-key-description '(?y "yes"))
                    '(?y . "yes")))
     (should (equal (rmc--add-key-description '(?n "foo"))
-                   '(?n . "[n] foo")))))
+                   '(?n . "[n] foo")))
+    (should (equal (rmc--add-key-description '(?\s "foo bar"))
+                   `(?\s . "[SPC] foo bar")))))
 
 (ert-deftest test-rmc--add-key-description/with-attributes ()
   (cl-letf (((symbol-function 'display-supports-face-attributes-p) (lambda (_ _) t)))
              `(?y . ,(concat (propertize "y" 'face 'read-multiple-choice-face) "es"))))
     (should (equal-including-properties
              (rmc--add-key-description '(?n "foo"))
-             `(?n . ,(concat "[" (propertize "n" 'face 'read-multiple-choice-face) "] foo"))))))
+             `(?n . ,(concat "[" (propertize "n" 'face 'read-multiple-choice-face) "] foo"))))
+    (should (equal-including-properties
+             (rmc--add-key-description '(?\s "foo bar"))
+             `(?\s . ,(concat "[" (propertize "SPC" 'face 'read-multiple-choice-face) "] foo bar"))))))
 
 (ert-deftest test-rmc--add-key-description/non-graphical-display ()
   (cl-letf (((symbol-function 'display-supports-face-attributes-p) (lambda (_ _) nil)))