[slim-vim] Indentation fun (was Re: slim-vim Digest, Vol 1, Issue 4)

Peter Wright pete at flooble.net
Wed Mar 22 19:23:07 CST 2006


On 22/03 16:14:36, Stephen Horner wrote:
> Oh, I forgot to ask about one thing in my last email regarding
> indenting lisp code in vim.  Is there a writen guideline that
> details how lisp code should be formatted etc...  I've been
> unsuccessful finding such a reference myself through google.

I've tried to find such a thing myself a few times, but this is the
closest I've got:

http://www.ccs.neu.edu/home/dorai/scmindent/scmindent.html

The scmindent.scm code is pretty close to documentation, as it's quite
nice and short and readable.

As far as I understand, the key interesting detail (for both CL and
Scheme) is working out which head symbols are "special" (and thus
should have different indentation for subsequent subforms). I think
this is where Slime has an advantage over dumb indenters like
scmindent.scm or the default Vim lisp-indentation engine, as it can
ask the Lisp engine how to classify symbols.

For your example:

------------------------------------------------------------
(publish :path "/hello-count"
    :content-type "text/html"
    :function
    (let ((count 0))
      #'(lambda (req ent)
          (with-http-response (req ent)
            (with-http-body (req ent)
              (html
                (:html
                  (:head (:title "Hello Counter"))
                  (:body
                     ((:font :color (nth (random 5)
                                     '("red" "blue"
                                       "green" "purple"
                                       "black")))
                       "Hello World had been called "
                       (:princ (incf count))
                       " times")))))))))
------------------------------------------------------------

...if you add

  nth,with-http-response,with-http-body,publish

to the 'lispwords' variable (in Vim7) and re-indent, you'll find it's
a lot closer to the "correct" indentation, though still not the same:

------------------------------------------------------------
(publish :path "/hello-count"
  :content-type "text/html"
  :function
  (let ((count 0))
    #'(lambda (req ent)
        (with-http-response (req ent)
          (with-http-body (req ent)
            (html
              (:html
                (:head (:title "Hello Counter"))
                (:body
                  ((:font :color (nth (random 5)
                                   '("red" "blue"
                                     "green" "purple"
                                     "black")))
                   "Hello World had been called "
                   (:princ (incf count))
                   " times")))))))))
------------------------------------------------------------

I'm not sure why the subforms of "publish" are indented two extra
spaces (toplevel-specific?), nor why the "Hello World..." expression
is indented an extra space. Hmm...

Okay, this is where a clear and unambiguous lisp-indentation-standard
document would be nice for people like me and Stephen. :)

> Regards,
> Stephen Horner

Pete.
-- 
http://flooble.net/blog
No, I don't want reviewers to give away my endings. I also don't want
them to give away my middles. I would prefer it if they didn't blab
quite so much about my beginnings. Let them summarize my prologues if
they must summarize. People who want to know what happens should read
the books, and sample first hand the pleasures of finding out.
	-- GRRM on story-wrecking summarizers masquerading as reviewers


More information about the slim-vim mailing list