[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat aa112d8 63/99: Implement lookup-key handling of
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat aa112d8 63/99: Implement lookup-key handling of keymap lists |
Date: |
Sun, 17 Oct 2021 05:57:58 -0400 (EDT) |
branch: externals/compat
commit aa112d8bd04174422cf17a2ee8e9a3dca2e9254b
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Implement lookup-key handling of keymap lists
---
compat-27.1.el | 28 ++++++++++++++++++++++++++++
compat-tests.el | 11 +++++++++++
2 files changed, 39 insertions(+)
diff --git a/compat-27.1.el b/compat-27.1.el
index 46847bd..c55aa77 100644
--- a/compat-27.1.el
+++ b/compat-27.1.el
@@ -105,6 +105,34 @@ Letter-case is significant, but text properties are
ignored."
(when (and redisplay recenter-redisplay)
(redisplay)))
+;;;; Defined in keymap.c
+
+(compat-advise lookup-key (keymap key &optional accept-default)
+ "Look up key sequence KEY in KEYMAP. Return the definition.
+A value of nil means undefined. See doc of `define-key'
+for kinds of definitions.
+
+A number as value means KEY is \"too long\"; that is, characters
+or symbols in it except for the last one fail to be a valid
+sequence of prefix characters in KEYMAP. The number is how many
+characters at the front of KEY it takes to reach a non-prefix
+key. KEYMAP can also be a list of keymaps.
+
+Normally, `lookup-key' ignores bindings for t, which act as default
+bindings, used when nothing else in the keymap applies; this makes it
+usable as a general function for probing keymaps. However, if the
+third optional argument ACCEPT-DEFAULT is non-nil, `lookup-key' will
+recognize the default bindings, just as `read-key-sequence' does."
+ (cond
+ ((keymapp keymap)
+ (funcall oldfun keymap key accept-default))
+ ((listp keymap)
+ (catch 'found
+ (dolist (map keymap)
+ (let ((fn (funcall oldfun map key accept-default)))
+ (when fn (throw 'found fn))))))
+ ((signal 'wrong-type-argument (list 'keymapp keymap)))))
+
;;;; Defined in json.c
(declare-function json-encode-string "json" (object))
diff --git a/compat-tests.el b/compat-tests.el
index 213c9a4..f2a4114 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1295,6 +1295,17 @@ the compatibility function."
(should (equal (gethash "key" obj) ["abc" 2]))
(should (equal (gethash "yek" obj) :null))))))
+(ert-deftest compat-lookup-key ()
+ "Check if `compat-lookup-key' was implemented properly."
+ (let ((a-map (make-sparse-keymap))
+ (b-map (make-sparse-keymap)))
+ (define-key a-map "x" 'foo)
+ (define-key b-map "x" 'bar)
+ (compat-test lookup-key
+ (compat--should* 'foo a-map "x")
+ (compat--should* 'bar b-map "x")
+ (compat--should* 'foo (list a-map b-map) "x")
+ (compat--should* 'bar (list b-map a-map) "x"))))
(provide 'compat-tests)
;;; compat-tests.el ends here
- [elpa] externals/compat 2d50e5c 32/99: Implement func-arity, (continued)
- [elpa] externals/compat 2d50e5c 32/99: Implement func-arity, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 36ef438 35/99: Implement and use mounted-file-systems, ELPA Syncer, 2021/10/17
- [elpa] externals/compat e5a573f 37/99: Declare mouse-set-point, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 2089c90 41/99: Declare gensym for with-existing-directory, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 2faab78 42/99: Add debug specification for setq-local, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 5e7698c 45/99: Avoid testing advice compatibility in version to old to compare, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 343bcbb 46/99: Fix if-let implementation, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 32031ea 50/99: Remove unnecessary compat-- prefix from gensym-counter, ELPA Syncer, 2021/10/17
- [elpa] externals/compat f8f4a9f 52/99: Use right function in some compat-maxargs-/= invocations, ELPA Syncer, 2021/10/17
- [elpa] externals/compat fa09ea0 54/99: Factor out multibyte regexp tests for string-search and -replace, ELPA Syncer, 2021/10/17
- [elpa] externals/compat aa112d8 63/99: Implement lookup-key handling of keymap lists,
ELPA Syncer <=
- [elpa] externals/compat 86fb58f 64/99: Move compat--alist-get-full-elisp to emacs-25.1, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 954c97b 67/99: Update compat-tests header, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 5cd751b 68/99: Mention GitHub issue tracker in README, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 598a040 69/99: Add :cond check to lookup-key, ELPA Syncer, 2021/10/17
- [elpa] externals/compat b16122b 71/99: Use explicit symbol names instead of alii, ELPA Syncer, 2021/10/17
- [elpa] externals/compat a7d9649 72/99: Manually advise functions when nadvice is not available, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 904d660 74/99: Add documentation to manual advice wrapper, ELPA Syncer, 2021/10/17
- [elpa] externals/compat e689153 76/99: Merge compile and run into one GitHub Action job, ELPA Syncer, 2021/10/17
- [elpa] externals/compat c37e1d1 80/99: Fix quoting in compat-macs' legacy advice installation, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 18c2bf9 83/99: Autoload advised functions is necessary, ELPA Syncer, 2021/10/17