The question is really more about printing Lisp sexps (including results of evaluation) than it is about macro expansion, per se. It's just that macro expansion typically results in a large Lisp sexp that can be difficult to work with or read, especially if parts of it are elided (...
).
I use pp-eval-last-sexp
, which I bind to C-x C-e
. (With C-u
it inserts the result at point, like eval-last-sexp
.)
You've pointed out some difficulties with this. But try the version of it you get with library PP+ (pp+.el
).
It respects user options pp-eval-expression-print-length
,
pp-eval-expression-print-level
, and pp-max-tooltip-size
. The first two are similar to but separate from the standard options with the same names but without prefix pp-
. So you can have separate values for pretty printing and non-pretty printing.
I also bind M-:
to pp-eval-expression
, instead of eval-expression
.
Both of these commands also let you use M-0
to toggle between using a tooltip for the result (when it is no larger than pp-max-tooltip-size
) and the usual handling (echo area or insertion in current buffer).
(The commands also respect option eval-expression-debug-on-error
.)