Was it intentional that the version of cl-indent.el in SLIME changed the indentation for the LOOP macro? In particular cl-indent in SLIME now does this indentation:
(loop for x in l for y for = (foo x) do (mumble x y))
whereas cl-indent in EMACS does this indentation:
(loop for x in l for y for = (foo x) do (mumble x y))
I much prefer the EMACS indentation.
Lynn Quam quam@ai.sri.com writes:
Was it intentional that the version of cl-indent.el in SLIME changed the indentation for the LOOP macro? In particular cl-indent in SLIME now does this indentation:
(loop for x in l for y for = (foo x) do (mumble x y))
This wasn't our change; it's a change in CVS Emacs. According to ChangeLogs, the LOOP indentation code in CVS Emacs was changed in March 2002 by Gerd Moellmann. It seems that the intention was that loops should be indented as:
(loop for x in l for y = (foo x) do (mumble x y))
whereas cl-indent in EMACS does this indentation:
(loop for x in l for y for = (foo x) do (mumble x y))
I much prefer the EMACS indentation.
I prefer this style too. I have
(setq lisp-simple-loop-indentation 1) (setq lisp-loop-keyword-indentation 6) (setq lisp-loop-forms-indentation 6)
in my .emacs. With this settings most code gets indented as before. Only stuff like
(loop for x = ...)
i.e no clause in the first line, is now indented as:
(loop for x = ...)
No big loss, because this style is ugly anyway.
Helmut.
Helmut Eller replied:
This wasn't our change; it's a change in CVS Emacs. According to ChangeLogs, the LOOP indentation code in CVS Emacs was changed in March 2002 by Gerd Moellmann. It seems that the intention was that loops should be indented as:
Thanks for the info. Yes, indeed the file date for cl-indent.el /usr/share/emacs/21.2/lisp/emacs-lisp is Aug 15 2001. That explains why I haven't seen the change. I find it curious that Emacs 21.2 in the RedHat 9 distribution that I am running does not contain the March 2002 Gerd Moellman version of cl-indent.el.
I much prefer the EMACS indentation.
I prefer this style too. I have
(setq lisp-simple-loop-indentation 1) (setq lisp-loop-keyword-indentation 6) (setq lisp-loop-forms-indentation 6)
in my .emacs. With this settings most code gets indented as before.
I added the above to my emacs/slime initialization but there are still some problems. For example:
;;; new cl-indent (loop with (lines package-decl property-list) for line-num from 1 for line = (read-line in-stream nil nil) while line when (search "(in-package" line :test #'char-equal) do (setq package-decl (read-from-string line) package-decl-line line-num *package* (eval package-decl)) else when (search "(FILE-PROPERTY-LIST" line :test #'char-equal) do (file-position in-stream file-pos) (setq property-list (read in-stream)) else collect line into lines when (and (>= (length line) 2) (string-equal line "|#" :end1 2)) do (setq comment-lines lines) finally (return (values lines package-decl property-list)))
;;; old cl-indent (loop with (lines package-decl property-list) for line-num from 1 for line = (read-line in-stream nil nil) while line when (search "(in-package" line :test #'char-equal) do (setq package-decl (read-from-string line) package-decl-line line-num *package* (eval package-decl)) else when (search "(FILE-PROPERTY-LIST" line :test #'char-equal) do (file-position in-stream file-pos) (setq property-list (read in-stream)) else collect line into lines when (and (>= (length line) 2) (string-equal line "|#" :end1 2)) do (setq comment-lines lines) finally (return (values lines package-decl property-list)))
Lynn Quam quam@ai.sri.com writes:
Thanks for the info. Yes, indeed the file date for cl-indent.el /usr/share/emacs/21.2/lisp/emacs-lisp is Aug 15 2001. That explains why I haven't seen the change. I find it curious that Emacs 21.2 in the RedHat 9 distribution that I am running does not contain the March 2002 Gerd Moellman version of cl-indent.el.
CVS Emacs and the Emacs 21.X series are different branches. I think only bug fixes are backported. New features only appear in the CVS version.
;;; old cl-indent (loop with (lines package-decl property-list) for line-num from 1 for line = (read-line in-stream nil nil) while line when (search "(in-package" line :test #'char-equal) do (setq package-decl (read-from-string line) package-decl-line line-num *package* (eval package-decl)) else when (search "(FILE-PROPERTY-LIST" line :test #'char-equal) do (file-position in-stream file-pos) (setq property-list (read in-stream)) else collect line into lines
when (and (>= (length line) 2) (string-equal line "|#" :end1 2))
do (setq comment-lines lines) finally (return (values lines package-decl property-list)))
Hmm.. are you sure the indentation here wasn't manually tuned or written with some other indentation package?
With Emacs 21.3 (non-CVS version) I get the same "bad" indentation as with the CVS version and my custom settings.
I also don't see any code in the 21.3 cl-indent that would be able to recognize "else" clauses and the like. If your version can actually do that, please post it.
[It should also be noted that a suboptimal LOOP indentation function is actually a feature because it stops people from writing monster loops as the one above.]
Helmut.
Helmut Eller replied:
Hmm.. are you sure the indentation here wasn't manually tuned or written with some other indentation package?
With Emacs 21.3 (non-CVS version) I get the same "bad" indentation as with the CVS version and my custom settings.
Again, you are correct:
I am loading a file called loop-indent.el that does:
(put 'loop 'common-lisp-indent-function 'cl-indent-indent-loop-macro )
The problem is that slime/cl-indent.el has the following change to COMMON-LISP-INDENT-FUNCTION that prevents the common-lisp-indent-function of loop from even being considered.
(defun common-lisp-indent-function (indent-point state) (if (save-excursion (goto-char (elt state 1)) (looking-at "([Ll][Oo][Oo][Pp]")) (common-lisp-loop-part-indentation indent-point state) (common-lisp-indent-function-1 indent-point state)))
Thus, common-lisp-loop-part-indentation gets called instead of (get 'loop 'common-lisp-indent-function)
I managed a workaround, but it might be better to fold loop-indent.el into SLIME.