Symbols for functions and macros have a
lisp-indent-function property which you can set with
declare or in your case, since
if is already defined, you can just use
You can read about the possible property values here:
(info "(elisp) Indenting Macros") return
if's default setting is
2 which means the second form get's special treatment and is offset.
You can change the property value to
'defun and all the body forms will line up.
(put 'if 'lisp-indent-function 'defun)
It is important to note that there is a reason for the indentation style.
if in Elisp is NOT like
if in Common Lisp.
Note the different signatures:
(if TEST THEN &OPTIONAL ELSE)
(if COND THEN ELSE...)
In Emacs lisp, you can have as many forms after the condition as you want but only the first form is the THEN clause, all other forms are part of the ELSE clause.
This is a valid Elisp
if form that is not valid in CL:
This shows why it is important that the THEN clause is indented more, it is to make it stand out against all the ELSE forms.
In addition to the indentation being important to the users ability to parse the code, it would also go against the accepted styling patterns of elisp. 99.99999% (carfefully calculated) of elisp code you encounter will use the exact same default indentation scheme. Changing the indentation of
if for you own use will make it hard for you to work on other peoples elisp and make it hard for others to work on yours.