Subject: Re: bug#37396: 26.3; execute-kbd-macro changes current buffer inside with-temp-buffer and similar forms

From: martin rudalics <[email-masked]>
Date: Fri, 13 Sep 2019 09:36:49 +0200

> When inside a form that temporarily changes the current buffer, such
 > as "with-temp-buffer", running "execute-kbd-macro" appears to switch
 > the current buffer back to whatever buffer was current when the
 > current command started executing.

'execute-kbd-macro' calls command_loop_1 which sets the current buffer
to the buffer shown in the selected window.

 > For example:
 >
 > (with-temp-buffer
 >    (list
 >     ;; Returns the temp buffer
 >     (current-buffer)
 >     (execute-kbd-macro "hello")
 >     ;; Returns the buffer that was current when evaluation began
 >     (current-buffer)))

Try with

(with-temp-buffer
   (let ((restore (window-buffer))
	temp)
     (setq temp (current-buffer))
     (set-window-buffer (selected-window) temp)
     (execute-kbd-macro "hello")
     (set-window-buffer (selected-window) restore)
     (list temp (current-buffer))))

martin