14.6 Indenting Macros

Within a macro definition, you can use the declare form (see Defining Macros) to specify how TAB should indent calls to the macro. An indentation specification is written like this:

(declare (indent indent-spec))

This results in the lisp-indent-function property being set on the macro name.

Here are the possibilities for indent-spec:

nil

This is the same as no property—use the standard indentation pattern.

defun

Handle this function like a ‘def’ construct: treat the second line as the start of a body.

an integer, number

The first number arguments of the function are distinguished arguments; the rest are considered the body of the expression. A line in the expression is indented according to whether the first argument on it is distinguished or not. If the argument is part of the body, the line is indented lisp-body-indent more columns than the open-parenthesis starting the containing expression. If the argument is distinguished and is either the first or second argument, it is indented twice that many extra columns. If the argument is distinguished and not the first or second argument, the line uses the standard pattern.

a symbol, symbol

symbol should be a function name; that function is called to calculate the indentation of a line within this expression. The function receives two arguments:

pos

The position at which the line being indented begins.

state

The value returned by parse-partial-sexp (a Lisp primitive for indentation and nesting computation) when it parses up to the beginning of this line.

It should return either a number, which is the number of columns of indentation for that line, or a list whose car is such a number. The difference between returning a number and returning a list is that a number says that all following lines at the same nesting level should be indented just like this one; a list says that following lines might call for different indentations. This makes a difference when the indentation is being computed by C-M-q; if the value is a number, C-M-q need not recalculate indentation for the following lines until the end of the list.

Variable: lisp-indent-local-overrides

This variable can be used to override the indentation specification used for certain symbol, as specified using their lisp-indent-function symbol property (see Symbol Properties). It is intended to be used as a file-local or directory-local variable; See Local Variables in Files in The GNU Emacs Manual.

Each key is a symbol and each value is an indent specification, which overrides the value of the symbol’s lisp-indent-function property. The value can take the same forms as the value of the symbol property, documented above. Note that using a function is not safe and should be avoided, else all users, who visit the file, would have to explicitly approve or decline their use.

This variable is used by the functions lisp-indent-function and common-lisp-indent-function. In case of the latter, the symbol properties common-lisp-indent-function-for-elisp and common-lisp-indent-function take precedence not only over the lisp-indent-function property but also over this variable.