如何判断emacs如何缩进我的elisp函数的参数?

时间:2010-08-05 05:57:44

标签: elisp indentation auto-indent

我编写的函数(实际上是一个宏,但无论如何)与progn的工作方式类似。如何告诉emacs这个函数应该以与progn相同的方式缩进?

2 个答案:

答案 0 :(得分:6)

这应该这样做

(put 'myfunc 'lisp-indent-function 0)

lisp-indent-function的文档(由 C-h f lisp-indent-function RET 找到):

lisp-indent-function is a compiled Lisp function in `lisp-mode.el'.

(lisp-indent-function indent-point state)

This function is the normal value of the variable
`lisp-indent-function`. It is used when indenting a line within
a function call, to see if the called function says anything
special about how to indent the line.

indent-point is the position where the user typed TAB, or
equivalent. Point is located at the point to indent under
(for default indentation); state is the `parse-partial-sexp`
state for that position.

If the current line is in a call to a Lisp function which has
a non-nil property `lisp-indent-function`, that specifies how
to do the indentation.  The property value can be:

* `defun`, meaning indent `defun`-style;

* an integer N, meaning indent the first N arguments specially
  like ordinary function arguments and then indent any further
  arguments like a body;

* a function to call just as this function was called. If that
  function returns nil, that means it doesn't specify
  the indentation.

This function also returns nil meaning don't specify the
indentation.

答案 1 :(得分:3)

因为它“实际上是一个宏”:

C-h i g (elisp) Indenting Macros RET

在这种情况下:

(defmacro my-macro (&rest body)
  "Does things"
  (declare (indent defun))
  `(progn ,@body))

(my-macro
  (message "foo")
  (message "bar"))