Search code examples
emacsmacroselisp

Emacs Lisp macro stepper


Is there an Elisp analogue for the SLIME macrostepper? Specifically, I'm looking for something that expands code at point into the next expansion step (or just the final expansion) in a new buffer.

The naive

(defun macroexpand-point ()
  (interactive)
  (let ((b (get-buffer-create "*el-macroexpansion*"))
        (expansion (format "%s" (macroexpand (thing-at-point 'sexp)))))
    (with-current-buffer b
      (insert expansion)
      (display-buffer b))))

doesn't do what I'm expecting here.


Solution

  • Perhaps you need this:

    (defun macroexpand-sexp-at-point ()
      (macroexpand (sexp-at-point)))
    

    The whole function can be expressed more succintly thus

    (defun macroexpand-point (sexp)
      (interactive (list (sexp-at-point)))
      (with-output-to-temp-buffer "*el-macroexpansion*"
        (pp (macroexpand sexp)))
      (with-current-buffer "*el-macroexpansion*" (emacs-lisp-mode)))