I'm using Emacs and SLIME to edit Lisp code.

By default, Emacs indents my Lisp LOOP constructs like this:

(loop for x across dna1 
   for y across dna2 
   count (not (eql x y)))

But I expect it to line up subsequent lines with the first parameter:

(loop for x across dna1 
      for y across dna2 
      count (not (eql x y)))

This still works fine for other functions:

(+ 1

Can someone explain to me why this is happening? Is it because LOOP is a macro? Is there a way to fix it? Should I fix it?

  • Lisp mode has an indent function (you can see its value if you do (symbol-plist 'loop) and then look at the value of lisp-indent-function property.
    – wvxvw
    Commented Feb 17, 2017 at 11:49

2 Answers 2


You can use indentation provided by a SLIME contribution:

(require 'slime-cl-indent)

You may want to add that to the list slime-contribs- see Loading Contribs in the SLIME manual.

One can add it to the list of SLIME contributions:

(add-to-list 'slime-contribs 'slime-cl-indent)
  • 3
    What worked for me was adding (setq slime-contribs '(slime-cl-indent)) to .emacs as per the SLIME github page. Commented Feb 17, 2017 at 12:04
  • 1
    I think the symbol to add to slime-contribs is not slime-cl-indent but slime-indentation. The slime source contains both a slime-cl-indent and a slime-indentation. The latter requires slime-cl-indent and contains a define-slime-contrib form with docstring "Contrib interfacing slime-cl-indent and SLIME."
    – Omar
    Commented Sep 2, 2019 at 12:33

I found, it is more appropriate to add into contribs 'slime-indentation. it will load slime-cl-indent.

And after that, you can use this code to choose required indentation style:

(setq lisp-indent-function 'common-lisp-indent-function)
(setq common-lisp-style-default "sbcl")

Available styles are: basic, classic, modern and sbcl. All of them are defined in slime-cl-indent.el file, but you can define your own style as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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