* Redisplay inside keyboard macros
@ 2022-02-08 15:17 Eduardo Ochs
2022-02-08 16:47 ` Eli Zaretskii
2022-02-08 17:31 ` Eduardo Ochs
0 siblings, 2 replies; 6+ messages in thread
From: Eduardo Ochs @ 2022-02-08 15:17 UTC (permalink / raw)
To: help-gnu-emacs
Hi list,
I am trying to write a keyboard macro that does some things, pauses
for one second, and then does more things, but I discovered that the
obvious ways to do sleep-and-redisplay don't work. Try to run the code
below with your favorite variant of C-e C-x C-e after each sexp:
(defun eek (str)
"Execute STR as a keyboard macro. See `edmacro-mode' for the exact
format.\n
An example: (eek \"C-x 4 C-h\")"
(interactive "sKeys: ")
(execute-kbd-macro (read-kbd-macro str)))
;; Choose one:
(defun s () (interactive) (sleep-for 1))
(defun s () (interactive) (redisplay) (sleep-for 1) (redisplay))
(defun s () (interactive) (redisplay 'force) (sleep-for 1) (redisplay
'force))
(eek "RET ab <<s>> cd")
I expected to see an "ab", then a pause, then the "cd", but that's not
what happens - I get a pause and then "abcd".
What am I doing wrong? I just triple-checked the docs about redisplay
and this behavior makes no sense to me...
Thanks in advance!!!
Eduardo Ochs
http://angg.twu.net/#eev
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Redisplay inside keyboard macros
2022-02-08 15:17 Redisplay inside keyboard macros Eduardo Ochs
@ 2022-02-08 16:47 ` Eli Zaretskii
2022-02-08 19:42 ` Bruno Barbier
2022-02-08 17:31 ` Eduardo Ochs
1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2022-02-08 16:47 UTC (permalink / raw)
To: help-gnu-emacs
> From: Eduardo Ochs <eduardoochs@gmail.com>
> Date: Tue, 8 Feb 2022 12:17:52 -0300
>
> I am trying to write a keyboard macro that does some things, pauses
> for one second, and then does more things, but I discovered that the
> obvious ways to do sleep-and-redisplay don't work. Try to run the code
> below with your favorite variant of C-e C-x C-e after each sexp:
>
> (defun eek (str)
> "Execute STR as a keyboard macro. See `edmacro-mode' for the exact
> format.\n
> An example: (eek \"C-x 4 C-h\")"
> (interactive "sKeys: ")
> (execute-kbd-macro (read-kbd-macro str)))
>
> ;; Choose one:
> (defun s () (interactive) (sleep-for 1))
> (defun s () (interactive) (redisplay) (sleep-for 1) (redisplay))
> (defun s () (interactive) (redisplay 'force) (sleep-for 1) (redisplay
> 'force))
>
> (eek "RET ab <<s>> cd")
>
> I expected to see an "ab", then a pause, then the "cd", but that's not
> what happens - I get a pause and then "abcd".
>
> What am I doing wrong? I just triple-checked the docs about redisplay
> and this behavior makes no sense to me...
'redisplay' exits immediately if called from a keyboard macro. It's a
feature.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Redisplay inside keyboard macros
2022-02-08 16:47 ` Eli Zaretskii
@ 2022-02-08 19:42 ` Bruno Barbier
2022-02-08 21:00 ` Eduardo Ochs
0 siblings, 1 reply; 6+ messages in thread
From: Bruno Barbier @ 2022-02-08 19:42 UTC (permalink / raw)
To: Eli Zaretskii, help-gnu-emacs
Hi,
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Eduardo Ochs <eduardoochs@gmail.com>
>> Date: Tue, 8 Feb 2022 12:17:52 -0300
...
>> I expected to see an "ab", then a pause, then the "cd", but that's not
>> what happens - I get a pause and then "abcd".
>>
>> What am I doing wrong? I just triple-checked the docs about redisplay
>> and this behavior makes no sense to me...
>
> 'redisplay' exits immediately if called from a keyboard macro. It's a
> feature.
In my case, some macros didn't replay correctly, because redisplay
wasn't done (like editing org mode links).
It's probably unsafe and unreliable, but, using a post-command-hook,
I've managed to force redisplays anyway. Macros are way slower than
before, but they now replay correctly.
Eduardo, your 'eek' function just works fine in my emacs, using
just the (sleep-for 1) definition. I can cleanup and share my hack if
you're interested.
Bruno.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Redisplay inside keyboard macros
2022-02-08 19:42 ` Bruno Barbier
@ 2022-02-08 21:00 ` Eduardo Ochs
2022-02-09 18:28 ` Bruno Barbier
0 siblings, 1 reply; 6+ messages in thread
From: Eduardo Ochs @ 2022-02-08 21:00 UTC (permalink / raw)
To: Bruno Barbier; +Cc: help-gnu-emacs
On Tue, 8 Feb 2022 at 17:39, Bruno Barbier <brubar.cs@gmail.com> wrote:
>
> In my case, some macros didn't replay correctly, because redisplay
> wasn't done (like editing org mode links).
>
> It's probably unsafe and unreliable, but, using a post-command-hook,
> I've managed to force redisplays anyway. Macros are way slower than
> before, but they now replay correctly.
>
> Eduardo, your 'eek' function just works fine in my emacs, using
> just the (sleep-for 1) definition. I can cleanup and share my hack if
> you're interested.
>
> Bruno.
Hi Bruno!
I'm interested! Please share! =)
[[]], Eduardo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Redisplay inside keyboard macros
2022-02-08 21:00 ` Eduardo Ochs
@ 2022-02-09 18:28 ` Bruno Barbier
0 siblings, 0 replies; 6+ messages in thread
From: Bruno Barbier @ 2022-02-09 18:28 UTC (permalink / raw)
To: Eduardo Ochs; +Cc: help-gnu-emacs
Hi Eduardo,
Eduardo Ochs <eduardoochs@gmail.com> writes:
> On Tue, 8 Feb 2022 at 17:39, Bruno Barbier <brubar.cs@gmail.com> wrote:
>> Eduardo, your 'eek' function just works fine in my emacs, using
>> just the (sleep-for 1) definition. I can cleanup and share my hack if
>> you're interested.
>>
>> Bruno.
>
> Hi Bruno!
> I'm interested! Please share! =)
Here is my hack to force a redisplay between each command, when
executing a keyboard macro; this ensures that running the macro does
the same thing as when recording it, and the same thing as when
running it step by step.
Not that I'm adding my hack to 'post-command-hook', so, be careful, and
only try it in a *new* instance of emacs, just to be safe.
#+begin_src elisp
(defun bba-kmacros-force-redisplay ()
"Hack to force redisplay when running keyboard macros."
(when executing-kbd-macro
(let (;; Hide any pending events.
(unread-command-events nil)
;; Pretend that we are not currently executing a keyboard
;; macro ...
(executing-kbd-macro nil)
(defining-kbd-macro nil)
)
;; Make emacs believe that we're asking something to the user: that
;; triggers a redisplay.
(let ((mb-oops (read-event "kmacro replay (hack): don't touch anything ..." nil .0))
)
(when mb-oops
;; Really ? Got an event before 0 second ? ... sweeping it
;; under the carpet, hoping that nobody notices ...
(message "ERROR: bba-kmacros-force-redisplay: loosing one event %S..."
mb-oops))
)
)))
;; Tell emacs to run `bba-kmacros-force-redisplay' after each command.
(add-hook 'post-command-hook
'bba-kmacros-force-redisplay
:better-at-the-end)
#+end_src
I just tested your example with GNU Emacs 27.2, and no personal config
(-Q) and it seems to do what you want.
Bruno.
> [[]], Eduardo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Redisplay inside keyboard macros
2022-02-08 15:17 Redisplay inside keyboard macros Eduardo Ochs
2022-02-08 16:47 ` Eli Zaretskii
@ 2022-02-08 17:31 ` Eduardo Ochs
1 sibling, 0 replies; 6+ messages in thread
From: Eduardo Ochs @ 2022-02-08 17:31 UTC (permalink / raw)
To: help-gnu-emacs
On Tue, 8 Feb 2022 at 12:17, Eduardo Ochs <eduardoochs@gmail.com> wrote:
>
> Hi list,
>
> I am trying to write a keyboard macro that does some things, pauses
> for one second, and then does more things, but I discovered that the
> obvious ways to do sleep-and-redisplay don't work. Try to run the code
> below with your favorite variant of C-e C-x C-e after each sexp:
>
> (defun eek (str)
> "Execute STR as a keyboard macro. See `edmacro-mode' for the exact format.\n
> An example: (eek \"C-x 4 C-h\")"
> (interactive "sKeys: ")
> (execute-kbd-macro (read-kbd-macro str)))
>
> ;; Choose one:
> (defun s () (interactive) (sleep-for 1))
> (defun s () (interactive) (redisplay) (sleep-for 1) (redisplay))
> (defun s () (interactive) (redisplay 'force) (sleep-for 1) (redisplay 'force))
>
> (eek "RET ab <<s>> cd")
>
> I expected to see an "ab", then a pause, then the "cd", but that's not
> what happens - I get a pause and then "abcd".
>
> What am I doing wrong? I just triple-checked the docs about redisplay
> and this behavior makes no sense to me...
>
> Thanks in advance!!!
> Eduardo Ochs
> http://angg.twu.net/#eev
Hi Eli,
> 'redisplay' exits immediately if called from a keyboard macro. It's a
> feature.
Aha! Thanks!
This works:
(defun eek (str)
"Execute STR as a keyboard macro. See `edmacro-mode' for the exact format.\n
An example: (eek \"C-x 4 C-h\")"
(interactive "sKeys: ")
(execute-kbd-macro (read-kbd-macro str)))
(defun rd () (interactive) (redisplay 'force))
(defun s () (interactive) (rd) (sleep-for 1) (rd))
(defun eeks (str &rest rest)
(eek str)
(if rest (progn (s) (apply 'eeks rest))))
(eeks "RET ab" "cd" "ef")
Cheers =),
Eduardo Ochs
http://angg.twu.net/#eev
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-02-09 18:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-08 15:17 Redisplay inside keyboard macros Eduardo Ochs
2022-02-08 16:47 ` Eli Zaretskii
2022-02-08 19:42 ` Bruno Barbier
2022-02-08 21:00 ` Eduardo Ochs
2022-02-09 18:28 ` Bruno Barbier
2022-02-08 17:31 ` Eduardo Ochs
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).