Skip to content

Commit fbd67c4

Browse files
committed
doc: Push use of (execute-kbd-macro) over :keys.
1 parent 03dc5cf commit fbd67c4

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

docs/source/reference.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,11 @@ Minibuffer
271271
- calls to :code:`turtles-with-grab-buffer` to test the content of
272272
the minibuffer or any other window.
273273

274-
- keys passed to the minibuffer, with :keys, see below.
274+
- keys passed to the minibuffer, with (execute-kbd-macro) or :keys (see
275+
below for :keys).
275276

276-
- commands that manipulate the minibuffer, either called directly
277-
or using :command, see below.
277+
- commands that manipulate the minibuffer, called directly, using
278+
(ert-simulate-command) or using :command (see below for :command).
278279

279280
At the end of BODY, the minibuffer is closed, if needed, and
280281
control returns to READ, which checks the result of running BODY.
@@ -285,10 +286,16 @@ Minibuffer
285286
function use the real event loop, triggered by real, external events
286287
(terminal keys). This isn't as simulation.
287288

289+
You can't use these special form except directly in BODY. The
290+
following won't work, for example: :code:`(if cond :keys "abc")`
291+
288292
:keys keys
289293
This expression provides KEYS as user input to the minibuffer.
290294

291295
KEYS is in the same format as passed to :code:`kbd`.
296+
:command:
297+
298+
Prefer :code:`(execute-kbd-macro)`, when it works.
292299

293300
:events events
294301
This expression provides a vector of events as the user input
@@ -297,10 +304,15 @@ Minibuffer
297304
This is more general than the previous function as the events
298305
can be any kind of UI events.
299306

307+
Prefer :code:`(execute-kbd-macro)`, when it works.
308+
300309
:command command
301310
This expression runs the given interactive command in the event
302311
loop, triggered by a key stroke.
303312

313+
Prefer calling the command directly or through
314+
:code:`(ert-simulate-command)`, when it works.
315+
304316
:command-with-keybinding keybinding command
305317
This expression works as above, but makes sure that the command
306318
will find in :code:`(this-command-keys)`, if it asks.

docs/source/tutorial.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,12 @@ This second example illustrates the use of
178178
(turtles-with-grab-buffer (:name "initial prompt" :point "<>")
179179
(should (equal "Choose: <>" (buffer-string))))
180180
181-
:keys "Ch TAB"
181+
(execute-kbd-macro "Ch")
182+
(minibuffer-complete)
182183
(turtles-with-grab-buffer (:name "completion" :point "<>")
183184
(should (equal "Choose: Choice <>" (buffer-string))))
184185
185-
:keys "B"))))
186+
(execute-kbd-macro "B")))))
186187
187188
188189
:code:`turtles-with-minibuffer` takes as argument two separate sections, as shown below:
@@ -226,16 +227,13 @@ that manually; it's just convenient to see the content and the
226227
position of the point in the same string.
227228

228229
This test interacts with :code:`completing-read` by simulating the
229-
user typing some text and pressing :kbd:`TAB`. It uses :ref:`:keys
230-
<minibuffer>` for that, which instructs the macro
231-
:code:`turtles-with-minibuffer` to simulates the user typing some
232-
keys.
230+
user typing some text and pressing :kbd:`TAB`.
233231

234232
The test could have called the command :kbd:`TAB` corresponds to directly:
235233

236234
.. code-block:: elisp
237235
238-
:keys "Ch"
236+
(execute-kbd-macro "Ch")
239237
(minibuffer-complete)
240238
(turtles-with-grab-buffer (:name "completion" :point "<>")
241239
(should (equal "Choose: Choice <>" (buffer-string))))
@@ -244,9 +242,10 @@ Calling interactive commands in such a way in a test is usually
244242
clearer than going through key bindings, and in most cases, it works well.
245243

246244
Some commands that rely on the specific environment provided by the
247-
command loop won't work if called directly.
248-
:ref:`:command <minibuffer>` can help with such commands,
249-
though it might be considered overkill here:
245+
command loop won't work if called directly or even through
246+
:code:`execute-kbd-macro`. :ref:`:keys and :command <minibuffer>` can
247+
help with such tricky commands. Though it would be overkill here, you
248+
could do:
250249

251250
.. code-block:: elisp
252251

test/turtles-examples-test.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@
8686
(turtles-with-grab-buffer (:name "initial prompt" :point "<>")
8787
(should (equal "Choose: <>" (buffer-string))))
8888

89-
:keys "Ch"
89+
(execute-kbd-macro "Ch")
9090
(minibuffer-complete)
9191
(turtles-with-grab-buffer (:name "completion" :point "<>")
9292
(should (equal "Choose: Choice <>" (buffer-string))))
9393

94-
:keys "B"))))
94+
(execute-kbd-macro "B")))))
9595

9696
(ert-deftest turtles-examples-test-isearch ()
9797
(turtles-ert-test)

turtles.texi

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,12 @@ This second example illustrates the use of
362362
(turtles-with-grab-buffer (:name "initial prompt" :point "<>")
363363
(should (equal "Choose: <>" (buffer-string))))
364364
365-
:keys "Ch TAB"
365+
(execute-kbd-macro "Ch")
366+
(minibuffer-complete)
366367
(turtles-with-grab-buffer (:name "completion" :point "<>")
367368
(should (equal "Choose: Choice <>" (buffer-string))))
368369
369-
:keys "B"))))
370+
(execute-kbd-macro "B")))))
370371
@end example
371372

372373
@code{turtles-with-minibuffer} takes as argument two separate sections, as shown below:
@@ -409,14 +410,12 @@ that manually; it’s just convenient to see the content and the
409410
position of the point in the same string.
410411

411412
This test interacts with @code{completing-read} by simulating the
412-
user typing some text and pressing @code{TAB}. It uses @ref{10,,;keys} for that, which instructs the macro
413-
@code{turtles-with-minibuffer} to simulates the user typing some
414-
keys.
413+
user typing some text and pressing @code{TAB}.
415414

416415
The test could have called the command @code{TAB} corresponds to directly:
417416

418417
@example
419-
:keys "Ch"
418+
(execute-kbd-macro "Ch")
420419
(minibuffer-complete)
421420
(turtles-with-grab-buffer (:name "completion" :point "<>")
422421
(should (equal "Choose: Choice <>" (buffer-string))))
@@ -426,9 +425,10 @@ Calling interactive commands in such a way in a test is usually
426425
clearer than going through key bindings, and in most cases, it works well.
427426

428427
Some commands that rely on the specific environment provided by the
429-
command loop won’t work if called directly.
430-
@ref{10,,;command} can help with such commands,
431-
though it might be considered overkill here:
428+
command loop won’t work if called directly or even through
429+
@code{execute-kbd-macro}. @ref{10,,;keys and ;command} can
430+
help with such tricky commands. Though it would be overkill here, you
431+
could do:
432432

433433
@example
434434
:keys "Ch"
@@ -839,11 +839,12 @@ calls to @code{turtles-with-grab-buffer} to test the content of
839839
the minibuffer or any other window.
840840

841841
@item
842-
keys passed to the minibuffer, with :keys, see below.
842+
keys passed to the minibuffer, with (execute-kbd-macro) or :keys (see
843+
below for :keys).
843844

844845
@item
845-
commands that manipulate the minibuffer, either called directly
846-
or using :command, see below.
846+
commands that manipulate the minibuffer, called directly, using
847+
(ert-simulate-command) or using :command (see below for :command).
847848
@end itemize
848849

849850
At the end of BODY, the minibuffer is closed, if needed, and
@@ -855,6 +856,9 @@ events using the command loop. In contrast to @code{execute-kbd-macro},
855856
function use the real event loop, triggered by real, external events
856857
(terminal keys). This isn’t as simulation.
857858

859+
You can’t use these special form except directly in BODY. The
860+
following won’t work, for example: @code{(if cond :keys "abc")}
861+
858862

859863
@table @asis
860864

@@ -863,6 +867,9 @@ function use the real event loop, triggered by real, external events
863867
This expression provides KEYS as user input to the minibuffer.
864868

865869
KEYS is in the same format as passed to @code{kbd}.
870+
:command:
871+
872+
Prefer @code{(execute-kbd-macro)}, when it works.
866873

867874
@item :events events
868875

@@ -872,11 +879,16 @@ to the minibuffer.
872879
This is more general than the previous function as the events
873880
can be any kind of UI events.
874881

882+
Prefer @code{(execute-kbd-macro)}, when it works.
883+
875884
@item :command command
876885

877886
This expression runs the given interactive command in the event
878887
loop, triggered by a key stroke.
879888

889+
Prefer calling the command directly or through
890+
@code{(ert-simulate-command)}, when it works.
891+
880892
@item :command-with-keybinding keybinding command
881893

882894
This expression works as above, but makes sure that the command

0 commit comments

Comments
 (0)