为我定义的 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/