[slime-devel] smarter loop indentation?

Hi, Please accept my apology if this is a faq. Is there a way to make slime indent the loop macro differently to reduce the intentation level? (loop for i from 1 to 100 for x in collection do (setq a b x y)) => (loop for i from 1 to 100 for x in collection do (setq a b x y)) I'd _really_ like to keep my code in 80-column if I can help it. I found that I frequently replace a simple loop with dotimes or dolist just for this purpose. But loop is a lot more malleable because you can add / remove clauses easily. I searched the mailing list and there's one hit that is related to this http://article.gmane.org/gmane.lisp.slime.devel/3407/match=loop+indentation http://thread.gmane.org/gmane.lisp.slime.devel/3398/focus=3407 but I don't see any followup from that thread. I also can't find relevant info in the documenation. If there's a way to configure CVS slime to do this I'd love to know. Or if there is separate emacs module that is not part of slime? TIA, -- Mac

Mac Chan wrote:
Is there a way to make slime indent the loop macro differently to reduce the intentation level?
(loop for i from 1 to 100 for x in collection do (setq a b x y))
=>
(loop for i from 1 to 100 for x in collection do (setq a b x y))
I'd _really_ like to keep my code in 80-column if I can help it.
I seriously doubt if messing with loop indentation is a good way to accomplish that, but to mess with it, you can play with a few variables. (setq lisp-simple-loop-indentation 2 lisp-loop-keyword-indentation 6 lisp-loop-forms-indentation 6) Is what I keep in .emacs. (Thanks to iirc Luis Oliviera.) Setting them all to 2 might be to your taste. Cheers, -- Nikodemus

On 4/19/07, Nikodemus Siivola <nikodemus@random-state.net> wrote:
I'd _really_ like to keep my code in 80-column if I can help it.
I seriously doubt if messing with loop indentation is a good way to accomplish that
Agreed, but a lot of macro forms are indented nicely except for `loop'. (dotimes () ...) (dolist () ...) look a lot nicer than (loop ... ... ...) Maybe it's just me.
(setq lisp-simple-loop-indentation 2 lisp-loop-keyword-indentation 6 lisp-loop-forms-indentation 6)
Is what I keep in .emacs.
Setting them all to 2 might be to your taste.
Thanks for the tip. But it doesn't seem to work. Here's my .emacs (setq lisp-simple-loop-indentation 2 lisp-loop-keyword-indentation 2 lisp-loop-forms-indentation 2) (setq inferior-lisp-program "/usr/bin/sbcl") (require 'slime) I started emacs and then M-x slime to launch sbcl M-x slime-scratch and then type in the following _(loop for i from 1 upto 3 for x in '(a b c) collect (cons i x)) With the cursor at _ I pressed C-M-q indent-sexp and the result is (loop for i from 1 upto 3 for x in '(a b c) collect (cons i x)) Same result if I mark the region and then press C-M-\ indent-sexp I tried `Describe variable' on lisp-simple-loop-indentation, lisp-loop-keyword-indentation and lisp-loop-forms-indentation but there's no documentation for these. Are these slime specific or emacs only? BTW I'm using emacs 21.4, CVS slime and sbcl 0.9.14 on fedora4 Thanks, -- Mac

Mac Chan wrote:
Maybe it's just me.
It's just you. ;-) Seriously, though: I _strongly_ recommend you stick with standard indentation: * Only by using it will you learn to read it without thinking, and only that way will you ever be able to read other people's code fluently. * If you don't use it no-one else will be able to read your code fluently. Saying "this is just playing around" or "just for my own use" is not IMO a good reason to diverge from the goal of universal readability.
With the cursor at _ I pressed C-M-q indent-sexp and the result is
(loop for i from 1 upto 3 for x in '(a b c) collect (cons i x))
What can I say? "Works for me." Possibly your Emacs is too old, in 22.0.92.1: lisp-loop-forms-indentation is a variable defined in `cl-indent.el'. Its value is 6 Documentation: *Indentation of forms in extended loop forms. You can customize this variable.
BTW I'm using emacs 21.4, CVS slime and sbcl 0.9.14 on fedora4
Just FYI: unless there are pressing reasons to stay with 0.9.14, SBCL 1.0.5 is coming out in a week or two. Cheers, -- Nikodemus

* Nikodemus Siivola <46286F05.2060900@random-state.net> : | | Seriously, though: I _strongly_ recommend you stick with standard | indentation: Emacs does not get a lot of lisp indentation right including some basic patterns. No point calling what a particular version of emacs does "the standard". - M-C-q (indent-sexp) and M-x indent-region indent the same code differently. whitespaces appear at different parts. - docstrings are filled according to emacs-lisp-docstring-fill-column - prog should be indented with lisp-indent-tagbody. It isn't. - loop indentation fails for patterns that the developer did not try and fix. - But even basic indentation is weird. As examples: LET and WITH-SLOTS: (let (foobarcar var (bar nil)) ...) Instead of (let (foobarcar var (bar nil)) ,,,) Which would be consistent with: (let (foobarcar (bar nil)) ...) - Problems with macro calls: Same problem as the basic indentation. (with-open-file (foo "0123456789010123456789" :element-type '(unsigned-byte 8) :if-exists :supersede) ,,,) (with-open-file (foo3456789010123456789 "foo" :element-type '(unsigned-byte 8) :if-exists :supersede) ,,,) ^^ Why should the second line be indented any differently from the first example? This is actually a case for "less uniform" via the "standard" - Similar problem with function calls| leading to problems formatting code within some given fill-column-width. etc. -- Madhu
participants (3)
-
Mac Chan
-
Madhu
-
Nikodemus Siivola