[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/which-key 4c27fc0 30/32: Improve which-key-add-keymap-b
From: |
ELPA Syncer |
Subject: |
[elpa] externals/which-key 4c27fc0 30/32: Improve which-key-add-keymap-based-replacements. |
Date: |
Wed, 30 Jun 2021 18:57:32 -0400 (EDT) |
branch: externals/which-key
commit 4c27fc0c565cdda58270dae4024ad03a0017de43
Author: Justin Burkett <justin@burkett.cc>
Commit: Justin Burkett <justin@burkett.cc>
Improve which-key-add-keymap-based-replacements.
Also, teach which-key--safe-lookup-key to handle numeric results.
---
which-key.el | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/which-key.el b/which-key.el
index 8598fa6..67b185f 100644
--- a/which-key.el
+++ b/which-key.el
@@ -909,20 +909,16 @@ For backwards compatibility, REPLACEMENT can also be a
string,
but the above format is preferred, and the option to use a string
for REPLACEMENT will eventually be removed."
(while key
- (cond ((consp replacement)
- (define-key keymap (kbd key) replacement))
- ((stringp replacement)
- (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")))
+ (let ((def
+ (cond
+ ((consp replacement) replacement)
+ ((stringp replacement)
+ (cons replacement
+ (or (which-key--safe-lookup-key keymap (kbd key))
+ (make-sparse-keymap))))
+ (t
+ (user-error "replacement is neither a cons cell or a string")))))
+ (define-key keymap (kbd key) def))
(setq key (pop more)
replacement (pop more))))
(put 'which-key-add-keymap-based-replacements 'lisp-indent-function 'defun)
@@ -1445,8 +1441,13 @@ local bindings coming first. Within these categories
order using
(if (stringp maybe-string) (string-width maybe-string) 0))
(defsubst which-key--safe-lookup-key (keymap key)
- "Version of `lookup-key' that allows KEYMAP to be nil. KEY is not checked."
- (when (keymapp keymap) (lookup-key keymap key)))
+ "Version of `lookup-key' that allows KEYMAP to be nil.
+Also convert numeric results of `lookup-key' to nil. KEY is not
+checked."
+ (when (keymapp keymap)
+ (let ((result (lookup-key keymap key)))
+ (when (and result (not (numberp result)))
+ result))))
(defsubst which-key--butlast-string (str)
(mapconcat #'identity (butlast (split-string str)) " "))
- [elpa] externals/which-key 8d6d81d 09/32: Expand get-keymap-bindings test, (continued)
- [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, 2021/06/30
- [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 <=
- [elpa] externals/which-key 8a558e6 06/32: Update tests, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key e42d946 11/32: Fix prefix sorting, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key fc88551 05/32: Remove pseudo binding stuff, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 465d2fb 10/32: Fix add-keymap-based-bindings and associated test, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 6ae80f5 22/32: Try without cask, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key d621634 19/32: Try with cask again, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key a55b908 04/32: Alternative approach to retrieving bindings (WIP), ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 1f9c37d 03/32: Merge pull request #305 from tarsiiformes/first-line, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key 4e592ed 08/32: Fix type usage and arglists for new functions, ELPA Syncer, 2021/06/30
- [elpa] externals/which-key d6b56f3 13/32: Fix detection of named prefix bindings, ELPA Syncer, 2021/06/30