【问题标题】:difference between two ways of specifying emacs lisp macro indent style指定emacs lisp宏缩进样式的两种方法之间的区别
【发布时间】:2013-08-14 17:21:17
【问题描述】:

为我定义的 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 宏复制而来的,该宏旨在用作照应宏。)

【问题讨论】:

    标签: emacs macros elisp auto-indent


    【解决方案1】:

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

    例如,你可以做类似的事情

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

    控制clojure-mode 缩进特定表单的方式。

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

    【讨论】:

      【解决方案2】:

      除了 jbm 所说的,declare 不是 Emacs Lisp 22 版之前的一部分(或者可能是 21 版)。因此,如果您希望您的代码也可用于较旧的 Emacs 版本,请不要使用 declare

      【讨论】:

        【解决方案3】:

        第一个扩展到第二个,因此没有技术差异。现在第一个是推荐的,第二个是底层实现。

        【讨论】:

          猜你喜欢
          • 2018-03-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-06-11
          • 1970-01-01
          • 2021-11-07
          相关资源
          最近更新 更多