emacs-diffs
[Top][All Lists]
Advanced

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

master 787030b021 2/5: read-multiple-choice: Add face when key not in na


From: Stefan Kangas
Subject: master 787030b021 2/5: read-multiple-choice: Add face when key not in name string
Date: Sun, 26 Dec 2021 11:06:55 -0500 (EST)

branch: master
commit 787030b0212d5933c3e4a16ece60b4e2ba8caea4
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    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.
---
 lisp/emacs-lisp/rmc.el            | 13 ++++++++++---
 test/lisp/emacs-lisp/rmc-tests.el | 10 +++++-----
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/lisp/emacs-lisp/rmc.el b/lisp/emacs-lisp/rmc.el
index 2f4b10efbb..6264220cd0 100644
--- a/lisp/emacs-lisp/rmc.el
+++ b/lisp/emacs-lisp/rmc.el
@@ -28,15 +28,22 @@
 (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
diff --git a/test/lisp/emacs-lisp/rmc-tests.el 
b/test/lisp/emacs-lisp/rmc-tests.el
index e858ed3940..a97254c46d 100644
--- a/test/lisp/emacs-lisp/rmc-tests.el
+++ b/test/lisp/emacs-lisp/rmc-tests.el
@@ -22,8 +22,6 @@
 
 ;;; Commentary:
 
-;;
-
 ;;; Code:
 
 (require 'ert)
@@ -45,13 +43,16 @@
              `(?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



reply via email to

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