[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/with-simulated-input 334f9f244f 119/134: Implement support
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/with-simulated-input 334f9f244f 119/134: Implement support for characters in KEYS |
Date: |
Mon, 10 Jan 2022 23:00:12 -0500 (EST) |
branch: elpa/with-simulated-input
commit 334f9f244f4a8426f1ee31e884faa1b52975e684
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>
Implement support for characters in KEYS
---
tests/test-with-simulated-input.el | 34 +++++++++++++++++++++++++++++++-
with-simulated-input.el | 40 +++++++++++++++++++++++++-------------
2 files changed, 59 insertions(+), 15 deletions(-)
diff --git a/tests/test-with-simulated-input.el
b/tests/test-with-simulated-input.el
index efeb394a8b..79242da374 100644
--- a/tests/test-with-simulated-input.el
+++ b/tests/test-with-simulated-input.el
@@ -77,6 +77,12 @@ during macro expansion will be caught as well."
(read-string "Enter a string: "))
:to-equal "hello"))
+ (it "is a literal character"
+ (expect
+ (with-simulated-input ?y
+ (read-char "Choose your character: "))
+ :to-equal ?y))
+
;; Deprecated
(it "is a quoted list of literal strings"
(expect-warning
@@ -85,6 +91,15 @@ during macro expansion will be caught as well."
(read-string "Enter a string: "))
:to-equal "hello")))
+ ;; Deprecated
+ (it "is a quoted list of characters"
+ (expect-warning
+ (expect
+ ;; 10 is RET
+ (with-simulated-input '(?h ?e ?l ?l ?o 10)
+ (read-string "Enter a string: "))
+ :to-equal "hello")))
+
;; Deprecated
(it "is a quoted list of lisp forms"
(expect-warning
@@ -94,7 +109,7 @@ during macro expansion will be caught as well."
:to-equal "hello")))
;; Deprecated
- (it "is a quoted list of strings and lisp forms"
+ (it "is a quoted list of strings, characters, and lisp forms"
(expect-warning
(expect
(with-simulated-input '((insert "hello") "RET")
@@ -107,8 +122,14 @@ during macro expansion will be caught as well."
:to-equal "hello"))
(expect-warning
(expect
+ ;; 10 is RET
(with-simulated-input '("hello SPC" (insert "world") "RET")
(read-string "Enter a string: "))
+ :to-equal "hello world"))
+ (expect-warning
+ (expect
+ (with-simulated-input '("hello SPC" (insert "wor") ?l ?d 10)
+ (read-string "Enter a string: "))
:to-equal "hello world")))
(it "is an un-quoted list of literal strings"
@@ -117,6 +138,13 @@ during macro expansion will be caught as well."
(read-string "Enter a string: "))
:to-equal "hello"))
+ (it "is a quoted list of characters"
+ (expect
+ ;; 10 is RET
+ (with-simulated-input (?h ?e ?l ?l ?o 10)
+ (read-string "Enter a string: "))
+ :to-equal "hello"))
+
(it "is an un-quoted list of lisp forms"
(expect
(with-simulated-input ((insert "hello") (exit-minibuffer))
@@ -135,6 +163,10 @@ during macro expansion will be caught as well."
(expect
(with-simulated-input ("hello SPC" (insert "world") "RET")
(read-string "Enter a string: "))
+ :to-equal "hello world")
+ (expect
+ (with-simulated-input '("hello SPC" (insert "wor") ?l ?d 10)
+ (read-string "Enter a string: "))
:to-equal "hello world"))
;; TODO: Decide whether to deprecate this
diff --git a/with-simulated-input.el b/with-simulated-input.el
index 25e0bf0c99..807984c36a 100644
--- a/with-simulated-input.el
+++ b/with-simulated-input.el
@@ -207,13 +207,14 @@ read input."
"Filter out irrelevant elements from KEYS.
Helper function for `with-simulated-input'. The only relevant
-elements of KEYS are strings, nil, and expressions that will have
-side effects (e.g. `(insert \"hello\")'). Other elements are
-filtered out, and an appropriate warning is generated for each
-one unless QUIET is non-nil."
+elements of KEYS are strings, characters, nil, and expressions
+that will have side effects (e.g. `(insert \"hello\")'). Other
+elements are filtered out, and an appropriate warning is
+generated for each one unless QUIET is non-nil."
(cl-loop
for key in keys
if (stringp key) collect key
+ else if (characterp key) collect key
;; It is occasionally useful to include nil as an element of
;; KEYS, so we don't produce a warning for it.
else if (null key) do (ignore)
@@ -253,13 +254,16 @@ typing in some text and pressing RET, KEYS would be
something
like `\"hello RET\"'. Note that spaces must be indicated
explicitly using `SPC', e.g. `\"hello SPC world RET\"'.
-KEYS can also be a list of strings, which will be used as
-consecutive inputs. (This list should not be quoted, since
-`with-simulated-input' is a macro.) Elements of the list can also
-be function calls, which will be evaluated at that point in the
-input sequence. This can be used as an alternative to writing out
-a full key sequence. For example, `\"hello SPC world RET\"' could
-also be written as:
+KEYS can also be a single character, which is equivalent to a
+string of length 1.
+
+KEYS can also be a list of strings (or characters), which will be
+used as consecutive inputs. (This list should not be quoted,
+since `with-simulated-input' is a macro.) Elements of the list
+can also be function calls, which will be evaluated at that point
+in the input sequence. This can be used as an alternative to
+writing out a full key sequence. For example, `\"hello SPC world
+RET\"' could also be written as:
`((insert \"hello world\") \"RET\")'
@@ -337,9 +341,9 @@ in a future release.)"
,@body)
nil))
;; If KEYS is a symbol, then it is a variable reference. This is
- ;; supported if the value is a string or nil. (Other values are
- ;; currently supported for backwards-compatibility, but are
- ;; deprecated.)
+ ;; supported if the value is a string, a character, or nil. (Other
+ ;; values are currently supported for backwards-compatibility, but
+ ;; are deprecated.)
((and keys (symbolp keys))
`(cond
((null ,keys)
@@ -352,6 +356,11 @@ in a future release.)"
(lambda ()
,@body)
,keys))
+ ((characterp ,keys)
+ (with-simulated-input-1
+ (lambda ()
+ ,@body)
+ (key-description (string ,keys))))
((consp ,keys)
(display-warning
'with-simulated-input
@@ -363,6 +372,7 @@ in a future release.)"
(cl-loop
for key in (wsi--remove-irrelevant-keys ,keys)
if (stringp key) collect key
+ else if (characterp key) collect (key-description (string key))
else if key collect `(lambda () ,key))))
(t
(error "KEYS must be a string or list, not %s: %s = %S"
@@ -393,6 +403,7 @@ in a future release.)"
(cl-loop
for key in (wsi--remove-irrelevant-keys ,evaluated-keys-sym)
if (stringp key) collect key
+ else if (characterp key) collect (key-description (string key))
else if key collect `(lambda () ,key))))))
;; The primary supported KEYS syntax: either a string, or an
;; un-quoted list of strings and list expressions to execute as
@@ -411,6 +422,7 @@ in a future release.)"
,@(cl-loop
for key in (wsi--remove-irrelevant-keys keys)
if (stringp key) collect key
+ else if (characterp key) collect (key-description (string key))
else if key collect `(lambda () ,key))))))
(defvar wsi-simulated-idle-time nil
- [nongnu] branch elpa/with-simulated-input created (now 0f43fe46d4), ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 568bfb8e1d 015/134: Version 2.0, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 5bdbde591d 058/134: Eliminate spurious warning in test file, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 433ee087ce 066/134: Test: handle `undercover' not being installed, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input ea6735cf1b 083/134: KEYS: support a single variable, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input d32cbc3ac9 093/134: Revert "Remove interpolation test", ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 39dbadff0b 120/134: Update the README to reflect current supported syntax, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input e7a7a6c39d 109/134: Don't use "define-advice" in tests, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 334f9f244f 119/134: Implement support for characters in KEYS,
ELPA Syncer <=
- [nongnu] elpa/with-simulated-input 00209c2be3 128/134: Test on 27.2 instead of 27.1, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 1006e93000 125/134: Add more tests to improve coverage, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 9c160b2d81 106/134: Add warnings for quoted list KEYS and nil/constant BODY, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 4eedb0eee8 126/134: Use an alternate method to disable eager macro-expansion for testing, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 9d082a372a 113/134: Be more selective about which file changes trigger a CI run, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 681397b90d 130/134: Also test variables containing characters, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 9ecf7c3f84 107/134: Improve code for detecting warnings in tests, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input ddd7bd71b1 011/134: Add "wsi-simulate-idle-time" and tests for it, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 662055c0a5 029/134: Handle non-lexical contexts as well as lexical, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 7f37451dcf 019/134: Use closures instead of quoted expressions, ELPA Syncer, 2022/01/10