From 94c25337b2de2f9da60914a7c0c6cca9584c0231 Mon Sep 17 00:00:00 2001 From: Nacho Barrientos Date: Fri, 9 Dec 2022 09:45:57 +0100 Subject: Use help-key-binding as face for keystrokes --- helpful.el | 10 +++++++--- test/helpful-unit-test.el | 11 ++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/helpful.el b/helpful.el index 09752b7..474a10b 100644 --- a/helpful.el +++ b/helpful.el @@ -980,7 +980,8 @@ vector suitable for `key-description', and COMMAND is a smbol." ;; Text of the form \\[foo-command] (rx "\\[" (group (+ (not (in "]")))) "]") (lambda (it) - (let* ((symbol-name (match-string 1 it)) + (let* ((button-face (if (>= emacs-major-version 28) 'help-key-binding 'button)) + (symbol-name (match-string 1 it)) (symbol (intern symbol-name)) (key (where-is-internal symbol keymap t)) (key-description @@ -991,7 +992,8 @@ vector suitable for `key-description', and COMMAND is a smbol." key-description 'helpful-describe-exactly-button 'symbol symbol - 'callable-p t))) + 'callable-p t + 'face button-face))) str t t)) @@ -1632,7 +1634,9 @@ Includes keybindings for aliases, unlike (push (format "%s %s" (propertize map 'face 'font-lock-variable-name-face) - key) + (if (>= emacs-major-version 28) + (propertize key 'face 'help-key-binding) + key)) (if (eq map 'global-map) global-lines mode-lines))))) (setq global-lines (-sort #'string< global-lines)) (setq mode-lines (-sort #'string< mode-lines)) diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el index 664454b..0f5177b 100644 --- a/test/helpful-unit-test.el +++ b/test/helpful-unit-test.el @@ -293,7 +293,16 @@ symbol (not a form)." (get-text-property 0 'button formatted))) ;; If we have quotes around a key sequence, we should not propertize ;; it as the button styling will no longer be visible. - (-let [formatted (helpful--format-docstring "`\\[set-mark-command]'")] + (-let* ((emacs-major-version 28) + (formatted (helpful--format-docstring "`\\[set-mark-command]'"))) + (should + (string-equal formatted "C-SPC")) + (should + (eq + (get-text-property 0 'face formatted) + 'help-key-binding))) + (-let* ((emacs-major-version 27) + (formatted (helpful--format-docstring "`\\[set-mark-command]'"))) (should (string-equal formatted "C-SPC")) (should -- cgit v1.0