]> git.eshelyaron.com Git - emacs.git/commitdiff
Respect no-face argument in literal key substitutions
authorStefan Kangas <stefan@marxist.se>
Sat, 18 Jun 2022 14:01:45 +0000 (16:01 +0200)
committerStefan Kangas <stefan@marxist.se>
Sat, 18 Jun 2022 17:56:07 +0000 (19:56 +0200)
* lisp/help.el (substitute-command-keys): Respect 'no-face' argument
also in literal key substitutions.
* test/lisp/help-tests.el
(help-tests-substitute-key-bindings/help-key-binding-face): Rename
from help-tests-substitute-key-bindings/face-help-key-binding.
(help-tests-substitute-key-bindings/help-key-binding-no-face): New test.

lisp/help.el
test/lisp/help-tests.el

index 766bae0845cd331b21aa272c7a599bf4e3fb0089..2d02b22e5264add9d3658e24cf6221e85f839ff0 100644 (file)
@@ -1176,9 +1176,10 @@ Otherwise, return a new string."
                         ((and (not (string-match-p "\\`M-x " k))
                               (not (key-valid-p k)))
                          (error "Invalid key sequence in substitution: `%s'" k))))
-                (add-text-properties orig-point (point)
-                                     '( face help-key-binding
-                                        font-lock-face help-key-binding)))
+                (unless no-face
+                  (add-text-properties orig-point (point)
+                                       '( face help-key-binding
+                                          font-lock-face help-key-binding))))
                ;; 1C. \[foo] is replaced with the keybinding.
                ((and (= (following-char) ?\[)
                      (save-excursion
index 9c9dddcd19ca691bbd1fa3bd379fb4c70702767e..14a1fb49aeca81c5eeb56de38743fe5632fc5c3d 100644 (file)
   (should-error (substitute-command-keys "\\`c-c'"))
   (should-error (substitute-command-keys "\\`<foo bar baz>'")))
 
-(ert-deftest help-tests-substitute-key-bindings/face-help-key-binding ()
-  (should (eq (get-text-property 0 'face (substitute-command-keys "\\[next-line]"))
-              'help-key-binding))
-  (should (eq (get-text-property 0 'face (substitute-command-keys "\\`f'"))
-              'help-key-binding)))
+(ert-deftest help-tests-substitute-key-bindings/help-key-binding-face ()
+  (let ((A (substitute-command-keys "\\[next-line]"))
+        (B (substitute-command-keys "\\`f'")))
+    (should (eq (get-text-property 0 'face A) 'help-key-binding))
+    (should (eq (get-text-property 0 'face B) 'help-key-binding))))
+
+(ert-deftest help-tests-substitute-key-bindings/help-key-binding-no-face ()
+  (let ((A (substitute-command-keys "\\[next-line]" t))
+        (B (substitute-command-keys "\\`f'" t)))
+    (should (eq (get-text-property 0 'face A) nil))
+    (should (eq (get-text-property 0 'face B) nil))
+    (should (equal A "C-n"))
+    (should (equal B "f"))))
 
 (defvar-keymap help-tests--test-keymap
   :doc "Just some keymap for testing."