Respect no-face argument in literal key substitutions

* 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.
This commit is contained in:
Stefan Kangas 2022-06-18 16:01:45 +02:00
parent e8bb4aba71
commit 4f3c1eb4c5
2 changed files with 17 additions and 8 deletions

View 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

View file

@ -100,11 +100,19 @@
(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."