aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2021-12-26 00:45:50 +0100
committerStefan Kangas2021-12-26 17:03:36 +0100
commit787030b0212d5933c3e4a16ece60b4e2ba8caea4 (patch)
tree3aeb340132f529452612e55dc9d6077d58188003
parent68f15e815e0a475a13d8169cc5d163cf05e7e524 (diff)
downloademacs-787030b0212d5933c3e4a16ece60b4e2ba8caea4.tar.gz
emacs-787030b0212d5933c3e4a16ece60b4e2ba8caea4.zip
read-multiple-choice: Add face when key not in name string
* 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.
-rw-r--r--lisp/emacs-lisp/rmc.el13
-rw-r--r--test/lisp/emacs-lisp/rmc-tests.el10
2 files changed, 15 insertions, 8 deletions
diff --git a/lisp/emacs-lisp/rmc.el b/lisp/emacs-lisp/rmc.el
index 2f4b10efbbd..6264220cd09 100644
--- a/lisp/emacs-lisp/rmc.el
+++ b/lisp/emacs-lisp/rmc.el
@@ -28,15 +28,22 @@
28(defun rmc--add-key-description (elem) 28(defun rmc--add-key-description (elem)
29 (let* ((name (cadr elem)) 29 (let* ((name (cadr elem))
30 (pos (seq-position name (car elem))) 30 (pos (seq-position name (car elem)))
31 (graphical-terminal
32 (display-supports-face-attributes-p
33 '(:underline t) (window-frame)))
31 (altered-name 34 (altered-name
32 (cond 35 (cond
33 ;; Not in the name string. 36 ;; Not in the name string.
34 ((not pos) 37 ((not pos)
35 (format "[%c] %s" (car elem) name)) 38 (let ((ch (char-to-string (car elem))))
39 (format "[%s] %s"
40 (if graphical-terminal
41 (propertize ch 'face 'read-multiple-choice-face)
42 ch)
43 name)))
36 ;; The prompt character is in the name, so highlight 44 ;; The prompt character is in the name, so highlight
37 ;; it on graphical terminals. 45 ;; it on graphical terminals.
38 ((display-supports-face-attributes-p 46 (graphical-terminal
39 '(:underline t) (window-frame))
40 (setq name (copy-sequence name)) 47 (setq name (copy-sequence name))
41 (put-text-property pos (1+ pos) 48 (put-text-property pos (1+ pos)
42 'face 'read-multiple-choice-face 49 'face 'read-multiple-choice-face
diff --git a/test/lisp/emacs-lisp/rmc-tests.el b/test/lisp/emacs-lisp/rmc-tests.el
index e858ed39405..a97254c46dc 100644
--- a/test/lisp/emacs-lisp/rmc-tests.el
+++ b/test/lisp/emacs-lisp/rmc-tests.el
@@ -22,8 +22,6 @@
22 22
23;;; Commentary: 23;;; Commentary:
24 24
25;;
26
27;;; Code: 25;;; Code:
28 26
29(require 'ert) 27(require 'ert)
@@ -45,13 +43,16 @@
45 `(?y . ,(concat (propertize "y" 'face 'read-multiple-choice-face) "es")))) 43 `(?y . ,(concat (propertize "y" 'face 'read-multiple-choice-face) "es"))))
46 (should (equal-including-properties 44 (should (equal-including-properties
47 (rmc--add-key-description '(?n "foo")) 45 (rmc--add-key-description '(?n "foo"))
48 '(?n . "[n] foo"))))) 46 `(?n . ,(concat "[" (propertize "n" 'face 'read-multiple-choice-face) "] foo"))))))
49 47
50(ert-deftest test-rmc--add-key-description/non-graphical-display () 48(ert-deftest test-rmc--add-key-description/non-graphical-display ()
51 (cl-letf (((symbol-function 'display-supports-face-attributes-p) (lambda (_ _) nil))) 49 (cl-letf (((symbol-function 'display-supports-face-attributes-p) (lambda (_ _) nil)))
52 (should (equal-including-properties 50 (should (equal-including-properties
53 (rmc--add-key-description '(?y "yes")) 51 (rmc--add-key-description '(?y "yes"))
54 '(?y . "[Y]es"))))) 52 '(?y . "[Y]es")))
53 (should (equal-including-properties
54 (rmc--add-key-description '(?n "foo"))
55 '(?n . "[n] foo")))))
55 56
56(ert-deftest test-read-multiple-choice () 57(ert-deftest test-read-multiple-choice ()
57 (dolist (char '(?y ?n)) 58 (dolist (char '(?y ?n))
@@ -60,6 +61,5 @@
60 (should (equal (list char str) 61 (should (equal (list char str)
61 (read-multiple-choice "Do it? " '((?y "yes") (?n "no")))))))) 62 (read-multiple-choice "Do it? " '((?y "yes") (?n "no"))))))))
62 63
63
64(provide 'rmc-tests) 64(provide 'rmc-tests)
65;;; rmc-tests.el ends here 65;;; rmc-tests.el ends here