[slim-vim] vim indentation

Larry Clapp larry at theclapp.org
Thu Mar 23 06:49:14 CST 2006


On Wed, Mar 22, 2006 at 04:10:51PM -0800, Stephen Horner wrote:
> What I would like to know is how doable it would be to do something
> similar to what we currently do with \es except have it pass the
> sexpr to ecl(?) to format the expression, and then have it replace
> the current code?

I think I could do it fairly easily, but remember the Lisp reader
removes comments by default.  I suppose we could use our own readtable
to keep them, but I suspect that adding words to 'lispwords'
automatically or writing an indent function (that interacts with ecl,
if necessary) would be easier.

> Nice, and purdy. And now how it looked when I wrote it in vim...
[ snip ugly code ]

This at least makes it easier to add words to 'lispwords' and
reindent:

function! Add_lispword_and_reindent()
  exec "set lispwords+=" . expand( "<cword>" )
  normal mz99[(=%`z
  " ) -- keep Vim's [ command balanced
endfunction

map <Leader>lw :call Add_lispword_and_reindent()<cr>

Put the cursor on the new lispword, e.g. with-http-body, press \lw (or
use whatever you use for your Leader character), and this should add
the offending word to 'lispwords', reindent the current expression,
and return you to your starting point.  It destroys the 'z mark,
though.

I'll include a somewhat more fully-featured version of this in my
ecl-repl.vim, forthcoming.  In particular, this version doesn't deal
with unbalanced parens in comments or strings; the ecl-repl version
will, and it won't destroy the 'z mark.

Later, perhaps someone (maybe me) could write a tree walker and ask
ECL whether any given symbol is a function/macro/special form, and if
so add it to lispwords, and then we could do that for any given subset
of a file, including the whole file on file load, via an autocommand.
Just thinking out loud.

-- Larry



More information about the slim-vim mailing list