[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/which-key 6290c9e 26/32: Improve which-key-add-keymap-b
From: |
ELPA Syncer |
Subject: |
[elpa] externals/which-key 6290c9e 26/32: Improve which-key-add-keymap-based-bindings |
Date: |
Wed, 30 Jun 2021 18:57:31 -0400 (EDT) |
branch: externals/which-key
commit 6290c9e21710c3ebbcdec795c916994682e07c94
Author: Justin Burkett <justin@burkett.cc>
Commit: Justin Burkett <justin@burkett.cc>
Improve which-key-add-keymap-based-bindings
Add a test
---
which-key-tests.el | 7 +++++--
which-key.el | 11 +++++++++--
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/which-key-tests.el b/which-key-tests.el
index 40566e7..877f009 100644
--- a/which-key-tests.el
+++ b/which-key-tests.el
@@ -36,11 +36,14 @@
(define-key map "\C-b" prefix-map)
(which-key-add-keymap-based-replacements map
"C-a" '("mycomplete" . complete)
- "C-b" "mymap")
+ "C-b" "mymap"
+ "C-c" "mymap2")
+ (define-key map "\C-ca" 'foo)
(should (equal
(which-key--get-keymap-bindings map)
'(("C-a" . "mycomplete")
- ("C-b" . "group:mymap"))))))
+ ("C-b" . "group:mymap")
+ ("C-c" . "group:mymap2"))))))
(ert-deftest which-key-test--prefix-declaration ()
"Test `which-key-declare-prefixes' and
diff --git a/which-key.el b/which-key.el
index 2d81d2e..2bfbb39 100644
--- a/which-key.el
+++ b/which-key.el
@@ -922,8 +922,15 @@ actually bound to write-file before performing the
replacement."
(cond ((consp replacement)
(define-key keymap (kbd key) replacement))
((stringp replacement)
- (define-key keymap (kbd key) (cons replacement
- (lookup-key keymap (kbd key)))))
+ (let ((binding (lookup-key keymap (kbd key))))
+ (if (or (null binding)
+ (numberp binding))
+ ;; using a keymap in case someone intends to make this a
+ ;; prefix. If they want to bind something else, they will just
+ ;; end up overriding the prefix map
+ (define-key keymap (kbd key)
+ (cons replacement (make-sparse-keymap)))
+ (define-key keymap (kbd key) (cons replacement binding)))))
(t
(user-error "replacement is neither a cons cell or a string")))
(setq key (pop more)
- [elpa] externals/which-key updated (fc29864 -> 27d9fec), ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 0f6bda6 02/32: Improve first doc-string line in trivial cases, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 12f743c 01/32: Fix whitespace, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key d8445fd 24/32: Try again to fix tests, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key fffd3e5 07/32: Fix default of which-key-replacement-alist, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 8d6d81d 09/32: Expand get-keymap-bindings test, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 6290c9e 26/32: Improve which-key-add-keymap-based-bindings,
ELPA Syncer <=
- [elpa] externals/which-key 063b867 18/32: Fix github action, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 28f386c 25/32: Fix key sort order functions, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 11471fb 21/32: Add install python step to github action, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key e236920 14/32: Merge branch 'alt-get-bindings', ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 7cfbf8c 23/32: Turn off fail-fast in github action, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key eb5a2e3 28/32: Clean up some docstrings, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key cd0c48c 29/32: Clarify usage of keymap replacements in docstrings and README, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 27d9fec 32/32: Fix compiler warnings, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 4c27fc0 30/32: Improve which-key-add-keymap-based-replacements., ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 8a558e6 06/32: Update tests, ELPA Syncer, 2021/06/30