Skip to content

Commit b31c1f5

Browse files
committed
Add: emacs-lisp-macroreplace
1 parent 1e93612 commit b31c1f5

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

README.org

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,30 @@ Byte-compile and load all elisp files in ~DIRECTORY~. Interactively, directory
718718
(byte-compile-file file 'load)))))
719719
#+END_SRC
720720

721+
**** =emacs-lisp-macroreplace=
722+
723+
Replace macro form before or after point with its expansion.
724+
725+
#+BEGIN_SRC elisp :exports code :eval no-export :tangle epdh.el
726+
(defun epdh/emacs-lisp-macroreplace ()
727+
"Replace macro form before or after point with its expansion."
728+
(interactive)
729+
(if-let* ((beg (point))
730+
(end t)
731+
(form (or (ignore-errors
732+
(save-excursion
733+
(prog1 (read (current-buffer))
734+
(setq end (point)))))
735+
(ignore-errors
736+
(forward-sexp -1)
737+
(setq beg (point))
738+
(prog1 (read (current-buffer))
739+
(setq end (point))))))
740+
(expansion (macroexpand-all form)))
741+
(setf (buffer-substring beg end) (pp-to-string expansion))
742+
(user-error "Unable to expand")))
743+
#+END_SRC
744+
721745
** Highlighting / font-locking :highlighting:font_lock:
722746

723747
*** Packages :packages:

epdh.el

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ for confirmation."
5050
(dolist (file files)
5151
(byte-compile-file file 'load)))))
5252

53+
(defun epdh/emacs-lisp-macroreplace ()
54+
"Replace macro form before or after point with its expansion."
55+
(interactive)
56+
(if-let* ((beg (point))
57+
(end t)
58+
(form (or (ignore-errors
59+
(save-excursion
60+
(prog1 (read (current-buffer))
61+
(setq end (point)))))
62+
(ignore-errors
63+
(forward-sexp -1)
64+
(setq beg (point))
65+
(prog1 (read (current-buffer))
66+
(setq end (point))))))
67+
(expansion (macroexpand-all form)))
68+
(setf (buffer-substring beg end) (pp-to-string expansion))
69+
(user-error "Unable to expand")))
70+
5371
;;;; Profiling / Optimization
5472

5573
(cl-defmacro bench (&optional (times 100000) &rest body)

index.html

Lines changed: 33 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)