Emacs Lisp 宏步进器

发布于 2024-11-05 09:34:35 字数 382 浏览 1 评论 0原文

SLIME 宏步进器有 Elisp 类似物吗?具体来说,我正在寻找将代码扩展到新缓冲区中的下一个扩展步骤(或只是最终扩展)的东西。

天真的

(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))))

不会做我在这里期待的事情。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天生の放荡 2024-11-12 09:34:35

也许你需要这个:

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

整个函数可以更简洁地表达

(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)))

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)))
兮子 2024-11-12 09:34:35

您可能会发现 imacroexpand.el做你想做的事。

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

自找没趣 2024-11-12 09:34:35

人们可能会发现 macrostep 包很有用。

关于 Macrostep 的快速指南:

安装软件包后,无需进一步自定义,您可以执行以下操作:

将光标移至要扩展的表达式之前,然后执行 Mx Macrostep-expand eeee e 来扩展它的步骤一步一步。简短的帮助消息显示在回显区域中,说明如何退出和如何取消展开。

可以在 dash.el 中的 ->> 宏示例上对此进行测试页面,不太简单也不太复杂。

One might find the macrostep package useful.

Quick howto on macrostep:

After you install the package, and without further customization, you can do this:

Move cursor before the expression you want to expand, then do M-x macrostep-expand e e e e e to expand it step by step. Short help message gets displayed in the echo area on how to quit and how to unexpand.

One can test this out on the ->> macro examples from dash.el page, which are not too simple and not too complicated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文