我写了一个函数(实际上是宏,但无所谓),其工作方式类似于progn
。我该如何告诉emacs这个函数应该像progn
一样缩进?
我写了一个函数(实际上是宏,但无所谓),其工作方式类似于progn
。我该如何告诉emacs这个函数应该像progn
一样缩进?
(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.
myfunc
改成函数的实际名称,第一次就可以运行了。最后我选择使用(put 'myfunc 'lisp-indent-function (get 'progn 'lisp-indent-function))
,即“做任何 progn
所做的事情”。 - Ryan C. Thompson因为它“实际上是一个宏”:
C-hig (elisp) 缩进宏
RET
在这种情况下:
(defmacro my-macro (&rest body)
"Does things"
(declare (indent defun))
`(progn ,@body))
(my-macro
(message "foo")
(message "bar"))
(declare (indent x))
表单适用于函数。我以前从未尝试过这个。字节编译器不会抱怨,所以我想使用它应该是可以的。有趣! - phils
emacs-lisp-mode
中实现这种缩进方式吗? - Noufal Ibrahimfont-lock-keywords
控制。你能发布一张“错误”行为的截图吗? - Joel J. Adamson