From: Stefan Kangas Date: Sat, 18 Jun 2022 14:01:45 +0000 (+0200) Subject: Respect no-face argument in literal key substitutions X-Git-Tag: emacs-29.0.90~1447^2~1631 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4f3c1eb4c5c1404c2f2726e36a4803f4fd6257b1;p=emacs.git 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. --- diff --git a/lisp/help.el b/lisp/help.el index 766bae0845c..2d02b22e526 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -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 diff --git a/test/lisp/help-tests.el b/test/lisp/help-tests.el index 9c9dddcd19c..14a1fb49aec 100644 --- a/test/lisp/help-tests.el +++ b/test/lisp/help-tests.el @@ -100,11 +100,19 @@ (should-error (substitute-command-keys "\\`c-c'")) (should-error (substitute-command-keys "\\`'"))) -(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."