[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/with-simulated-input 1b9123c708 112/134: Cache the return
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/with-simulated-input 1b9123c708 112/134: Cache the return value of wsi-get-unbound-key |
Date: |
Mon, 10 Jan 2022 23:00:10 -0500 (EST) |
branch: elpa/with-simulated-input
commit 1b9123c708632a53b00d3ffa7a713167abd9a2d8
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>
Cache the return value of wsi-get-unbound-key
---
tests/test-with-simulated-input.el | 6 ++++--
with-simulated-input.el | 33 +++++++++++++++++++++++----------
2 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/tests/test-with-simulated-input.el
b/tests/test-with-simulated-input.el
index c2c2f9d646..6931bc09e1 100644
--- a/tests/test-with-simulated-input.el
+++ b/tests/test-with-simulated-input.el
@@ -21,8 +21,10 @@
(it "should report an error if it fails to find an unbound key"
;; Now we call it with an empty list of modifiers and keys to
;; search, so it definitely should not find a binding.
- (expect (wsi-get-unbound-key "" '("abc" "123"))
- :to-throw 'error)))
+ (expect
+ (let ((wsi-last-used-next-action-bind nil))
+ (wsi-get-unbound-key "" '("abc" "123")))
+ :to-throw 'error)))
(defmacro progn-at-runtime (&rest body)
"Like `progn', but evaluate BODY entirely at runtime.
diff --git a/with-simulated-input.el b/with-simulated-input.el
index 48b9f8de0c..500c36b2ec 100644
--- a/with-simulated-input.el
+++ b/with-simulated-input.el
@@ -47,6 +47,9 @@
(require 'files)
(require 'cl-lib)
+(defvar wsi-last-used-next-action-bind nil
+ "Last keybind used by `with-simulated-input', if any.")
+
(cl-defun wsi-key-bound-p (key)
"Return non-nil if KEY is bound in any keymap.
@@ -85,21 +88,31 @@ modifier combinations, e.g.:
'(\"C-\" \"M-\" \"C-M-\")
for control, meta, or both. KEYS is a string containing all keys
-to check."
+to check.
+
+When this function returns, it also sets
+`wsi-last-used-next-action-bind' to the return value. The next
+time it is called, it checks this variable to see if it is still
+usable, and returns it if so, even if it isn't a valid choice
+given the value of MODIFIERS and KEYS."
(declare (advertised-calling-convention (&optional modifiers keys) nil))
(when (stringp modifiers)
(setq modifiers (list modifiers)))
(when (listp keys)
(setq keys (apply #'concat keys)))
- (cl-loop
- named findkey
- for modifier in modifiers
- do (cl-loop
- for char across keys
- for bind = (concat modifier (string char))
- when (not (wsi-key-bound-p bind))
- do (cl-return-from findkey bind))
- finally do (error "Could not find an unbound key with the specified
modifiers")))
+ (if (and wsi-last-used-next-action-bind
+ (not (wsi-key-bound-p wsi-last-used-next-action-bind)))
+ wsi-last-used-next-action-bind
+ (cl-loop
+ named findkey
+ for modifier in modifiers
+ do (cl-loop
+ for char across keys
+ for bind = (concat modifier (string char))
+ when (not (wsi-key-bound-p bind))
+ do (cl-return-from findkey
+ (setq wsi-last-used-next-action-bind bind)))
+ finally do (error "Could not find an unbound key with the specified
modifiers"))))
;;;###autoload
(defun with-simulated-input-1 (main &rest keys)
- [nongnu] elpa/with-simulated-input abe9c855a8 075/134: `with-simulated-input' support `list' KEYS, (continued)
- [nongnu] elpa/with-simulated-input abe9c855a8 075/134: `with-simulated-input' support `list' KEYS, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 1f48107e92 081/134: Add nbfalcon as Author, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 5713495a1c 067/134: Refactor: `with-simulated-input' function, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 2a4866984a 080/134: No longer handle variables specially in KEYS, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 6c2e0ece2d 084/134: Use #' for advice-add/-remove, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 582844da4c 085/134: Add a failing test for byte-compiled closures, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input dca9d87d50 091/134: Move issue-specific tests to their own block, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input c5b3f7ac70 097/134: Add tests for nil input, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 0a1b0dea0a 101/134: Clean up with-simulated-input-1, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 138106c256 116/134: Skip coverage calculation on older Emacsen, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 1b9123c708 112/134: Cache the return value of wsi-get-unbound-key,
ELPA Syncer <=
- [nongnu] elpa/with-simulated-input 4abf2f0e6b 103/134: Replace def-form with form in debug declaration, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input c0b765c7fb 115/134: Add debug declarations to macros in test file, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 445df9edfd 110/134: Eliminate unnecessary quotes in test suite, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 80d57be458 099/134: Make all the tests pass, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 41f4547339 132/134: Clarify a comment, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input a30bd8e6e4 129/134: Fix the test for variables in KEYS, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 9813acf396 114/134: Enable undercover on all tested Emacs versions, ELPA Syncer, 2022/01/10