mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-04 08:47:11 +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")))))
|
'("SPC t 2" . "[ ] test mode")))))
|
||||||
|
|
||||||
(ert-deftest which-key-test--maybe-replace-multiple ()
|
(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
|
(let ((which-key-replacement-alist
|
||||||
'(((nil . "helm") . (nil . "HLM"))
|
'(((nil . "helm") . (nil . "HLM"))
|
||||||
((nil . "projectile") . (nil . "PRJTL"))))
|
((nil . "projectile") . (nil . "PRJTL"))))
|
||||||
@ -114,5 +114,13 @@
|
|||||||
(which-key--maybe-replace '("C-c C-c" . "helm-projectile-x"))
|
(which-key--maybe-replace '("C-c C-c" . "helm-projectile-x"))
|
||||||
'("C-c C-c" . "HLM-PRJTL-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)
|
(provide 'which-key-tests)
|
||||||
;;; which-key-tests.el ends here
|
;;; 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))))))
|
str))))))
|
||||||
desc))
|
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)
|
(defun which-key--format-and-replace (unformatted)
|
||||||
"Take a list of (key . desc) cons cells in UNFORMATTED, add
|
"Take a list of (key . desc) cons cells in UNFORMATTED, add
|
||||||
faces and perform replacements according to the three replacement
|
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))
|
(let* ((key (car key-binding))
|
||||||
(orig-desc (cdr key-binding))
|
(orig-desc (cdr key-binding))
|
||||||
(group (which-key--group-p orig-desc))
|
(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))
|
(local (eq (which-key--safe-lookup-key local-map (kbd keys))
|
||||||
(intern orig-desc)))
|
(intern orig-desc)))
|
||||||
(hl-face (which-key--highlight-face 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)
|
(when (consp key-binding)
|
||||||
(push
|
(push
|
||||||
(list (which-key--propertize-key
|
(list (which-key--propertize-key
|
||||||
(car (last (split-string (car key-binding) " "))))
|
(which-key--extract-key (car key-binding)))
|
||||||
sep-w-face
|
sep-w-face
|
||||||
(which-key--propertize-description
|
(which-key--propertize-description
|
||||||
(cdr key-binding) group local hl-face orig-desc))
|
(cdr key-binding) group local hl-face orig-desc))
|
||||||
|
Loading…
Reference in New Issue
Block a user