emacs-diffs
[Top][All Lists]
Advanced

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

master a936335aa0: Fix return value of help--key-description-fontified


From: Stefan Kangas
Subject: master a936335aa0: Fix return value of help--key-description-fontified
Date: Fri, 19 Aug 2022 14:38:34 -0400 (EDT)

branch: master
commit a936335aa02bd6d142ce61563e6cf70a1a7c271b
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>

    Fix return value of help--key-description-fontified
    
    This fixes a bug with warning about obsolete commands in
    `command-execute', where we incorrectly showed empty parenthesis
    instead of the empty string when there was no keybinding for the new
    command.
    
    * lisp/help.el (help--key-description-fontified): Return nil instead
    of the empty string if KEYS argument is nil.
    * test/lisp/help-tests.el (help--key-description-fontified): New test.
    (with-substitute-command-keys-test): Fix indentation.
---
 lisp/help.el            | 17 ++++++++++-------
 test/lisp/help-tests.el | 18 ++++++++++++------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/lisp/help.el b/lisp/help.el
index 37aab15df0..15ab3192ad 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -566,13 +566,16 @@ To record all your input, use `open-dribble-file'."
 ;; Key bindings
 
 (defun help--key-description-fontified (keys &optional prefix)
-  "Like `key-description' but add face for \"*Help*\" buffers."
-  ;; We add both the `font-lock-face' and `face' properties here, as this
-  ;; seems to be the only way to get this to work reliably in any
-  ;; buffer.
-  (propertize (key-description keys prefix)
-              'font-lock-face 'help-key-binding
-              'face 'help-key-binding))
+  "Like `key-description' but add face for \"*Help*\" buffers.
+KEYS is the return value of `(where-is-internal \\='foo-cmd nil t)'.
+Return nil if KEYS is nil."
+  (when keys
+    ;; We add both the `font-lock-face' and `face' properties here, as this
+    ;; seems to be the only way to get this to work reliably in any
+    ;; buffer.
+    (propertize (key-description keys prefix)
+                'font-lock-face 'help-key-binding
+                'face 'help-key-binding)))
 
 (defcustom describe-bindings-outline t
   "Non-nil enables outlines in the output buffer of `describe-bindings'."
diff --git a/test/lisp/help-tests.el b/test/lisp/help-tests.el
index 7f30b27b00..833c32ffb2 100644
--- a/test/lisp/help-tests.el
+++ b/test/lisp/help-tests.el
@@ -55,18 +55,24 @@
     (should (equal (help-split-fundoc nil t 'usage)  nil))
     (should (equal (help-split-fundoc nil t 'doc)    nil))))
 
+(ert-deftest help--key-description-fontified ()
+  (should (equal (help--key-description-fontified
+                  (where-is-internal #'next-line nil t))
+                 "C-n"))
+  (should-not (help--key-description-fontified nil)))
+
 
 ;;; substitute-command-keys
 
 (defmacro with-substitute-command-keys-test (&rest body)
   `(cl-flet* ((test
-               (lambda (orig result)
-                 (should (equal (substitute-command-keys orig)
-                                result))))
+                (lambda (orig result)
+                  (should (equal (substitute-command-keys orig)
+                                 result))))
               (test-re
-               (lambda (orig regexp)
-                 (should (string-match (concat "\\`" regexp "\\'")
-                                       (substitute-command-keys orig))))))
+                (lambda (orig regexp)
+                  (should (string-match (concat "\\`" regexp "\\'")
+                                        (substitute-command-keys orig))))))
      ,@body))
 
 (ert-deftest help-tests-substitute-command-keys/no-change ()



reply via email to

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