Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 774
Inaimathi Avatar asked May 08 '11 03:05

Inaimathi


2 Answers

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)))
like image 162
huaiyuan Avatar answered Sep 23 '22 23:09

huaiyuan


You may find that imacroexpand.el does what you want.

like image 21
zev Avatar answered Sep 24 '22 23:09

zev