Skip to content

Commit

Permalink
Use help-key-binding as face for keystrokes
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarrientos authored and Wilfred committed Dec 9, 2022
1 parent 4a8d576 commit 94c2533
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 7 additions & 3 deletions helpful.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 10 additions & 1 deletion test/helpful-unit-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 94c2533

Please sign in to comment.