emacs - 指定 emacs lisp 宏缩进样式的两种方法之间的区别

标签 emacs macros elisp auto-indent

为我定义的 Emacs Lisp 宏指定缩进样式的两种流行方法之间有何区别或优缺点?

声明方式:

(defmacro my-dotimes-1 (num &rest body)
  (declare (indent 1))  ; <---
  `(let ((it 0))
     (while (< it ,num)
       ,@body
       (setq it (1+ it)))))

放置方式:

(defmacro my-dotimes-2 (num &rest body)
  `(let ((it 0))
     (while (< it ,num)
       ,@body
       (setq it (1+ it)))))
(put 'my-dotimes-2 'lisp-indent-function 1) ; <---

(名称 it 不是 gensym,因为该示例是从 dash.el--dotimes 宏复制而来,其目的是作为照应宏。)

最佳答案

我知道的唯一区别是 declare 仅适用于 Emacs Lisp,而 put 方法也适用于其他语言(也就是说,如果它们使用管理缩进的类似技术)。

例如,您可以执行以下操作

(put 'match 'clojure-indent-function 2)

控制clojure-mode如何缩进特定表单。

还值得注意的是,虽然缩进级别通常是为宏指定的,但它也适用于函数。

关于emacs - 指定 emacs lisp 宏缩进样式的两种方法之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18238230/

相关文章:

emacsclient 不评估颜色主题?

emacs - 如何使用 Emacs/deftheme 更改所选文本的突出显示颜色?

c++ - 如何使用 '#define'定义一个宏来执行多个方法?

c++ - 如何在编译时静态比较两个字符串

Emacs Helm : Adding new sources to helm-mini

emacs - Emacs 中 sexp 和 list 的区别?

emacs - Emacs切换到下一个窗口,而不考虑框架

emacs - 从交互函数内部调用kill-rectangle

c++ - 是否可以使作为默认参数的宏在调用站点展开?

python - 如何在 emacs 中进行特殊的正则表达式查找和替换