Comment puis-je savoir comment emacs les arguments à ma fonction elisp devrait être en retrait?

StackOverflow https://stackoverflow.com/questions/3412109

  •  26-09-2019
  •  | 
  •  

Question

Je fonction écrit (en fait une macro, mais peu importe) qui fonctionne de façon similaire à progn. Comment puis-je dire à emacs que cette fonction devrait être en retrait de la même manière que progn?

Était-ce utile?

La solution

Cela devrait le faire

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

Documentation pour lisp-indent-function (trouvé par C-H f-Lisp fonction tiret 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.

Autres conseils

Comme il est "en fait une macro":

C-h i g (elisp) Indenting Macros RET

Dans ce cas:

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

(my-macro
  (message "foo")
  (message "bar"))
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top