mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-03 08:30:09 +00:00
Fix handling of key ranges ("a .. d")
When the last key in the key sequence is a range, extract the whole range instead of just the final key. Fixes #161
This commit is contained in:
parent
ea6f1dc5aa
commit
0d56e4369b
@ -99,7 +99,7 @@
|
||||
'("SPC t 2" . "[ ] test mode")))))
|
||||
|
||||
(ert-deftest which-key-test--maybe-replace-multiple ()
|
||||
"Test `which-key-allow-multiple-replacements'. See #156"
|
||||
"Test `which-key-allow-multiple-replacements'. See #156."
|
||||
(let ((which-key-replacement-alist
|
||||
'(((nil . "helm") . (nil . "HLM"))
|
||||
((nil . "projectile") . (nil . "PRJTL"))))
|
||||
@ -114,5 +114,13 @@
|
||||
(which-key--maybe-replace '("C-c C-c" . "helm-projectile-x"))
|
||||
'("C-c C-c" . "HLM-PRJTL-x")))))
|
||||
|
||||
(ert-deftest which-key-test--key-extraction ()
|
||||
"Test `which-key--extract-key'. See #161."
|
||||
(should (equal (which-key--extract-key "SPC a") "a"))
|
||||
(should (equal (which-key--extract-key "C-x a") "a"))
|
||||
(should (equal (which-key--extract-key "<left> b a") "a"))
|
||||
(should (equal (which-key--extract-key "<left> a .. c") "a .. c"))
|
||||
(should (equal (which-key--extract-key "M-a a .. c") "a .. c")))
|
||||
|
||||
(provide 'which-key-tests)
|
||||
;;; which-key-tests.el ends here
|
||||
|
12
which-key.el
12
which-key.el
@ -1439,6 +1439,14 @@ ORIGINAL-DESCRIPTION is the description given by
|
||||
str))))))
|
||||
desc))
|
||||
|
||||
(defun which-key--extract-key (key-str)
|
||||
"Pull the last key (or key range) out of KEY-STR."
|
||||
(save-match-data
|
||||
(let ((key-range-regexp "\\`.*\\([^ \t]+ \\.\\. [^ \t]+\\)\\'"))
|
||||
(if (string-match key-range-regexp key-str)
|
||||
(match-string 1 key-str)
|
||||
(car (last (split-string key-str " ")))))))
|
||||
|
||||
(defun which-key--format-and-replace (unformatted)
|
||||
"Take a list of (key . desc) cons cells in UNFORMATTED, add
|
||||
faces and perform replacements according to the three replacement
|
||||
@ -1451,7 +1459,7 @@ alists. Returns a list (key separator description)."
|
||||
(let* ((key (car key-binding))
|
||||
(orig-desc (cdr key-binding))
|
||||
(group (which-key--group-p orig-desc))
|
||||
(keys (which-key--current-key-string key))
|
||||
(keys (concat (which-key--current-key-string) " " key))
|
||||
(local (eq (which-key--safe-lookup-key local-map (kbd keys))
|
||||
(intern orig-desc)))
|
||||
(hl-face (which-key--highlight-face orig-desc))
|
||||
@ -1459,7 +1467,7 @@ alists. Returns a list (key separator description)."
|
||||
(when (consp key-binding)
|
||||
(push
|
||||
(list (which-key--propertize-key
|
||||
(car (last (split-string (car key-binding) " "))))
|
||||
(which-key--extract-key (car key-binding)))
|
||||
sep-w-face
|
||||
(which-key--propertize-description
|
||||
(cdr key-binding) group local hl-face orig-desc))
|
||||
|
Loading…
Reference in New Issue
Block a user