Indenting LOOP
Saturday, July 29th, 2006In working on indenting LOOP forms for Climacs (see the latest update here) I’ve come across a couple of competing ideas on how they should be formatted.
From cl-indent-patches.el (”Original version by rst” with patches by “salem” and “bromley” according to the header) we have the following “validation” (line numbers added by me):
1 (loop for i from 0 below 2 2 for j from 0 below 2 3 when foo 4 do (fubar) 5 (bar) 6 (moo) 7 and collect cash 8 into honduras 9 else do ;; this is the body of the first else 10 ;; the body is ... 11 (indented to the above comment) 12 (ZMACS gets this wrong) 13 and do this 14 and do that 15 and when foo 16 do the-other 17 and cry 18 when this-is-a-short-condition do 19 (body code of the when) 20 when here's something I used to botch do (here is a body) 21 (rest of body indented same) 22 do 23 (exdented loop body) 24 (I'm not sure I like this but it's compatible) 25 when funny-predicate do ;; Here's a comment 26 (body filled to comment))
The forms at issue are the DOs at 9-12 (and 25-6; compare with 20-21), 18-19 and 22-24. I would indent these like this:
9 else do ;; this is the body of the first else 10 ;; the body is ... 11 (indented to the above comment) 12 (ZMACS gets this wrong)
(I see no reason for conforming to a dubious commenting style. But I’m interested to know why not doing so is “wrong”.)
18 when this-is-a-short-condition do 19 (body code of the when)
(I see no reason to special-case a “short-condition”, whatever that is.)
22 do 23 (exdented loop body) 24 (I'm not sure I like this but it's compatible)
(Exdenting is just gross - but “compatible” with what?)
Of course, I’m now doubting my own taste, so I’d be interested in what the Planet Lisp community thinks. Answers in the comments for summarising in a later edition…