开发者

How can I tell emacs how the arguments to my elisp function should be indented?

开发者 https://www.devze.com 2023-01-10 12:49 出处:网络
I have written function (actually a macro, but whatever) that works similarly to progn. How can I tell emacs that this function should be ind开发者_如何转开发ented in the same way as progn?This should

I have written function (actually a macro, but whatever) that works similarly to progn. How can I tell emacs that this function should be ind开发者_如何转开发ented in the same way as progn?


This should do it

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

Documentation for lisp-indent-function (found by 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.


As it's "actually a macro":

C-hig (elisp) Indenting Macros RET

In this instance:

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

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

精彩评论

暂无评论...
验证码 换一张
取 消