]> git.eshelyaron.com Git - emacs.git/commitdiff
read-multiple-choice: Add face when key not in name string
authorStefan Kangas <stefan@marxist.se>
Sat, 25 Dec 2021 23:45:50 +0000 (00:45 +0100)
committerStefan Kangas <stefan@marxist.se>
Sun, 26 Dec 2021 16:03:36 +0000 (17:03 +0100)
* lisp/emacs-lisp/rmc.el (rmc--add-key-description): Add face
property also when key is not in the name string.
* test/lisp/emacs-lisp/rmc-tests.el
(test-rmc--add-key-description/with-attributes)
(test-rmc--add-key-description/non-graphical-display): Update tests.

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

index 2f4b10efbbdba2ee093795983f31417d9b5b3c41..6264220cd0929ee7b1562af485a128fbe4e234b9 100644 (file)
 (defun rmc--add-key-description (elem)
   (let* ((name (cadr elem))
          (pos (seq-position name (car elem)))
+         (graphical-terminal
+          (display-supports-face-attributes-p
+           '(:underline t) (window-frame)))
          (altered-name
           (cond
            ;; Not in the name string.
            ((not pos)
-            (format "[%c] %s" (car elem) name))
+            (let ((ch (char-to-string (car elem))))
+              (format "[%s] %s"
+                      (if graphical-terminal
+                          (propertize ch 'face 'read-multiple-choice-face)
+                        ch)
+                      name)))
            ;; The prompt character is in the name, so highlight
            ;; it on graphical terminals.
-           ((display-supports-face-attributes-p
-             '(:underline t) (window-frame))
+           (graphical-terminal
             (setq name (copy-sequence name))
             (put-text-property pos (1+ pos)
                                'face 'read-multiple-choice-face
index e858ed39405ce6e24762629f7e2e88ff86ed1bf1..a97254c46dcab8a8d02632af24213158dbb01954 100644 (file)
@@ -22,8 +22,6 @@
 
 ;;; Commentary:
 
-;;
-
 ;;; Code:
 
 (require 'ert)
              `(?y . ,(concat (propertize "y" 'face 'read-multiple-choice-face) "es"))))
     (should (equal-including-properties
              (rmc--add-key-description '(?n "foo"))
-             '(?n . "[n] foo")))))
+             `(?n . ,(concat "[" (propertize "n" 'face 'read-multiple-choice-face) "] foo"))))))
 
 (ert-deftest test-rmc--add-key-description/non-graphical-display ()
   (cl-letf (((symbol-function 'display-supports-face-attributes-p) (lambda (_ _) nil)))
     (should (equal-including-properties
              (rmc--add-key-description '(?y "yes"))
-             '(?y . "[Y]es")))))
+             '(?y . "[Y]es")))
+    (should (equal-including-properties
+             (rmc--add-key-description '(?n "foo"))
+             '(?n . "[n] foo")))))
 
 (ert-deftest test-read-multiple-choice ()
   (dolist (char '(?y ?n))
@@ -60,6 +61,5 @@
       (should (equal (list char str)
                      (read-multiple-choice "Do it? " '((?y "yes") (?n "no"))))))))
 
-
 (provide 'rmc-tests)
 ;;; rmc-tests.el ends here