(声明(缩进*))是如何工作的?

时间:2012-11-25 15:17:16

标签: emacs elisp

信息页面未提及此声明。我找到了用于设置为1,2或3的用途,但还有哪些其他选项?它到底是做什么的?

在它的表面上,看起来数字意味着宏名称后面的行数进一步向右缩进,但在这种情况下,我如何告诉它将所有表单缩进为第一个?

示例:

(declare (indent 1))这样做:

(-iter 
    (with (a b c))
  (for i from 0 to 5)
  (collect i)
  (message "i: %s" i))

(declare (indent 2))这样做:

(-iter 
    (with (a b c))
    (for i from 0 to 5)
  (collect i)
  (message "i: %s" i))

(declare (indent 256))(或任何足够大的数字)执行此操作:

(-iter 
    (with (a b c))
    (for i from 0 to 5)
    (collect i)
    (message "i: %s" i))

除了提供任意大数字之外,我想做最后一个。有没有办法告诉“全部”或某些事情?

2 个答案:

答案 0 :(得分:1)

这是in the manual

C-h i g (elisp) Indenting Macros RET

declare,FYI的索引条目链接到。 (Emacs 24.2.1)

答案 1 :(得分:0)

由于接受的答案实际上并不能回答问题,并且手册相当晦涩,因此,我要指出this blog,它表明0的值实际上在此处有效,并且与defun

但是,缩进级别不如数字那么大。检查:

使用(indent nil)或不使用(indent ...)声明:

(-iter
 (with (a b c))
 (for i from 0  to 5)
 (collect i)
 (message "i: %s" i))

使用(indent defun)(indent 0)

(-iter
  (with (a b c))
  (for i from 0 to 5)
  (collect i)
  (message "i: %s" i))

使用(indent 256)

(-iter
    (with (a b c))
    (for i from 0 to 5)
    (collect i)
    (message "i: %s" i))

使用(indent (lambda (x y) 4))可获得与(indent 256)相同的结果。不过,对缩进进行硬编码可能与使用lisp-indent-function指定不同缩进样式的机制稍有冲突。