summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--elisp.el32
1 files changed, 32 insertions, 0 deletions
diff --git a/elisp.el b/elisp.el
index c944040..bb68713 100644
--- a/elisp.el
+++ b/elisp.el
@@ -310,6 +310,38 @@ PARSE-START is the starting position of the parse."
(t
normal-indent))))))
+;;; macro expansion
+
+(defconst elisp-macro-buffer "*ELisp-Macroexpand*"
+ "The name of the buffer that displays the expansion of \
+macros.")
+
+;;;###autoload
+(defun elisp-macro-expand (start end subst)
+ "Expand ELisp macros in the region.
+Normally display output in temp buffer, but
+prefix arg means replace the region with it.
+
+Note that this only expands one Emacs Lisp form. So multiple
+forms have to be expanded separately.
+
+Adapted from `c-macro-expand'."
+ (interactive "r\nP")
+ (let ((form (read (buffer-substring-no-properties start end)))
+ (buf (cond ((not subst)
+ (get-buffer-create elisp-macro-buffer)))))
+ (cond
+ ((not subst)
+ (with-current-buffer buf
+ (erase-buffer)
+ (insert (format "%s" (macroexpand-all form))))
+ (display-buffer buf))
+ (t
+ (delete-region start end)
+ (insert (format "%S" (macroexpand-all form)))))))
+
+(define-key emacs-lisp-mode-map (vector 3 5) #'elisp-macro-expand)
+
(provide 'elisp)
;;; elisp.el ends here