1

I am learning common lisp and am trying to follow the style guide suggested by lisp-lang.org. In this style guide is an if statement style that I think makes the code more readable:

(if (cond)
    (true-branch)
    (false-branch))

That is, the branches line up. I find this to be syntactically easier to read. Using lisp-mode with no extra goodies the default seems to be:

(if (cond)
    (true-branch)
  (false-branch))

For some strange reason. The false block is pushed back to line up with the f of the if statement. I find this a little jarring.

Is there a way to clean this up so I can have the default formatting conform the linked styleguide?

  • FWIW, I believe the reason behind this indentation style is that the 3rd, 4th, ... args are all part of the "else" (i.e. there's an implicit progn around the rest of the args). The style you want is the one typically used in Scheme where the if traditionally does not accept more than 3 args IIRC. – Stefan Jan 9 at 13:16
1

Why is Emacs so weird?

Emacs indents lisp code as if it were Emacs Lisp, where if accepts unlimited else forms; unlike in Common Lisp, where if accepts at most 3 arguments.

What to do?

Tell Emacs to indent Lisp as if it were Common Lisp:

(custom-set-variables
 '(lisp-indent-function 'common-lisp-indent-function))
(autoload 'common-lisp-indent-function "cl-indent" "Common Lisp indent.")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.