I am trying to write a macro. I have read the manual and learned about
macroexpand. However, when I use it, I find the expansion difficult to read and work with.
How can I expand a macro in a readable, workable format?
Let me illustrate.
If I simply call
macroexpand, the result is echoed in the minibuffer. When the expansion is large, the echo is all scrunched up:
(macroexpand '(with-temp-file (make-temp-file "test-file")))
I can go to
C-h e, copy and paste it back into
*scratch*, and then format it. But clearly that gets tiresome.
To save on the copy/paste, I have tried using
eval-last-sexp with a universal argument,
C-u C-x C-e. This indeed prints the output to the buffer...but it's in some weird interactive state that I cannot edit. Pressing
RET causes it to alternate between an abbreviated and expanded form:
C-h k RET shows that
elisp-last-sexp-toggle-display is now the binding for
All of this implies some kind of workflow. However, the documentation for
macroexpand describes none of this behavior. The source code is not distributed with my version of Emacs (Emacs 26.3 for Windows). Scouring the web has found no meaningful explanation of how to work with macro expansions.