Subject: Add macro expansion commands that use macroexpand-all

From: Okamsn <[email-masked]>
Date: Fri, 07 Mar 2025 00:14:00 +0000

Hello,

The attached patch adds for at expanding the sexp before point using 
`macroexpand-all` instead of `macroexpand`.  This is useful when the 
expansion contains macros that could be further expanded. I have been 
using it for several years in my own config.

I have named these commands 'pp-macroexpand-all-last-sexp ' and 
'pp-macroexpand-all-expression '. They could also be called 
'pp-macroexpand-last-sexp-all' and 'pp-macroexpand-expression-all'. 
Please let me know if you would prefer different names.

Thank you.

From 7310a89b1e5803d90a38900a5435e99fb0e9c845 Mon Sep 17 00:00:00 2001
From: Earl Hyatt <[email-masked]>
Date: Fri, 28 Feb 2025 20:13:55 -0500
Subject: [PATCH] Add PP commands that use macroexpand-all

* lisp/emacs-lisp/pp.el (pp-macroexpand-all-expression):
(pp-macroexpand-all-last-sexp): Add commands that use 'macroexpand-all'
instead of 'macroexpand-1'.
* etc/NEWS (PP): Mention new commands.
---
 etc/NEWS              |  9 +++++++++
 lisp/emacs-lisp/pp.el | 18 ++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 0867822a7d8..1cb40e1c9a2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1336,6 +1336,15 @@ Major-mode authors can customize the variables
 'yank-media-autoselect-function' and/or 'yank-media-preferred-types' to
 change the selection rules.
 
+** PP
+
+---
+*** New commands 'pp-macroexpand-all-last-sexp ' and 'pp-macroexpand-all-expression '
+These commands are like 'pp-macroexpand-last-sexp' and
+'pp-macroexpand-expression', but they use the function 'macroexpand-all'
+instead of 'macroexpand-1'.  They can be useful when a macro's expansion
+contains more macros that could be expanded.
+
 ** Miscellaneous
 
 ---
diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index 3e75807f757..4239d514c1e 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -405,6 +405,14 @@ pp-macroexpand-expression
   (pp-display-expression (macroexpand-1 expression) "*Pp Macroexpand Output*"
                          pp-use-max-width))
 
+;;;###autoload
+(defun pp-macroexpand-all-expression (expression)
+  "Use `macroexpand-all' on EXPRESSION and pretty-print its value."
+  (interactive
+   (list (read--expression "Macroexpand: ")))
+  (pp-display-expression (macroexpand-all expression) "*Pp Macroexpand Output*"
+                         pp-use-max-width))
+
 (defun pp-last-sexp ()
   "Read sexp before point.  Ignore leading comment characters."
   (with-syntax-table emacs-lisp-mode-syntax-table
@@ -450,6 +458,16 @@ pp-macroexpand-last-sexp
       (insert (pp-to-string (macroexpand-1 (pp-last-sexp))))
     (pp-macroexpand-expression (pp-last-sexp))))
 
+;;;###autoload
+(defun pp-macroexpand-all-last-sexp (arg)
+  "Run `pp-macroexpand-all-expression' on sexp before point.
+With ARG, pretty-print output into current buffer.
+Ignores leading comment characters."
+  (interactive "P")
+  (if arg
+      (insert (pp-to-string (macroexpand-all (pp-last-sexp))))
+    (pp-macroexpand-all-expression (pp-last-sexp))))
+
 ;;;###autoload
 (defun pp-emacs-lisp-code (sexp &optional end)
   "Insert SEXP into the current buffer, formatted as Emacs Lisp code.
-- 
2.43.0