help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Redisplay inside keyboard macros


From: Bruno Barbier
Subject: Re: Redisplay inside keyboard macros
Date: Wed, 09 Feb 2022 19:28:49 +0100

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]