Subject: bug#56210: 29.0.50; Keyboard macros do not trigger after-change-functions

From: Richard Hansen <[email-masked]>
Date: Sat, 25 Jun 2022 16:34:11 -0400

On 2022-06-25 14:56, Eli Zaretskii wrote:
> Maybe we should step back and ask what do you think the below do?
> 
>    (execute-kbd-macro (kbd "x"))
> 
> What is, in your mental model, the effect of the above in Emacs?

I would expect that to be roughly equivalent to typing "x" on the physical keyboard, which would insert an event into some sort of event queue.  (I'm not familiar enough with Emacs to know whether that queue is per-buffer, per-window, per-frame, per-terminal, per-process, or something else.)  Under normal circumstances, the event would be dispatched to the buffer associated with the `selected-window' of the `selected-frame', and insert an "x".

I think my understanding of "current buffer" is incorrect.  My current mental model of `with-current-buffer' is that it behaves as if the window's associated buffer is briefly switched to the specified buffer (like "C-x b" does) except it doesn't actually go to the expense of rendering the other buffer in the window (or update the toolbar, etc.).  Looking at the documentation of `set-window-buffer', that mental model appears to be wrong.

But if my mental model is wrong, why does my original code insert "x" into the temporary buffer?  It is not due to something specific to `ert-with-test-buffer', because if I evaluate the following in *scratch* then I see the same behavior that Lars saw with `with-temp-buffer' (the "x" is inserted into *scratch*):

     (ert-with-test-buffer () (execute-kbd-macro (kbd "x")))

Maybe `ert-run-tests-batch-and-exit' is setting it up to more closely simulate a user interacting with Emacs?  Or maybe the behavior is caused by batch mode?

Regardless, given that the temporary buffer is modified in my original example, shouldn't `after-change-functions' run?