6

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
   2
   3)

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?

Rainer Joswig
  • 252
  • 1
  • 7
Gustav Bertram
  • 165
  • 1
  • 8
  • 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 Feb 17 '17 at 11:49

2 Answers2

7

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)
Rainer Joswig
  • 252
  • 1
  • 7
  • 3
    What worked for me was adding `(setq slime-contribs '(slime-cl-indent))` to `.emacs` as per the [SLIME github page](https://github.com/slime/slime#quick-setup-instructions). – Gustav Bertram Feb 17 '17 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 Sep 02 '19 at 12:33
3

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.

JeanPierre
  • 7,323
  • 1
  • 18
  • 37