ERuby indenting
Tim Pope
vim-ruby-devel at tpope.info
Tue Nov 7 15:55:22 EST 2006
Hi all,
I have written and attached an ERuby indent plugin. It outsources
most of the heavy lifting to the HTML and Ruby indent plugins, and
works quite well. I would think it would be appropriate for inclusion
in vim-ruby.
I emailed this to Doug Kearns a bit earlier (and have not received a
response), but have since decided this list would be a more
appropriate place to share it.
Enjoy,
Tim Pope
-------------- next part --------------
" Vim indent file
" Language: ERuby
" Author: Tim Pope <vimNOSPAM at tpope.info>
" $Id: eruby.vim,v 1.1 2006/11/07 20:51:03 tpope Exp $
if exists("b:did_indent")
finish
endif
runtime! indent/ruby.vim
unlet! b:did_indent
runtime! indent/html.vim
unlet! b:did_indent
let b:did_indent = 1
setlocal indentexpr=GetErubyIndent(v:lnum)
setlocal indentkeys=o,O,*<Return>,<>>,{,},!^F,=end,=else,=elsif,=rescue,=ensure,=when
" Only define the function once.
if exists("*GetErubyIndent")
finish
endif
function! GetErubyIndent(lnum)
let vcol = col('.')
call cursor(a:lnum,1)
let inruby = searchpair('<%','','%>')
call cursor(a:lnum,vcol)
if inruby
let ind = GetRubyIndent()
else
let ind = HtmlIndentGet(a:lnum)
endif
let lnum = prevnonblank(a:lnum-1)
let line = getline(lnum)
let cline = getline(a:lnum)
if cline =~# '<%\s*\%(end\|else\|\%(elsif\|rescue\|ensure\|case\|when\).\{-\}\)\s*-\=%>'
let ind = ind - &sw
endif
if line =~# '\<do\%(\s*|[^|]*|\)\=\s*-\=%>'
let ind = ind + &sw
elseif line =~# '<%\s*\%(if\|unless\|for\|while\|until\|def\|class\|module\|begin\|else\|elsif\|rescue\|ensure\|when\)\>.*%>'
let ind = ind + &sw
endif
if line =~# '^\s*<%[=#]\=\s*$'
let ind = ind + &sw
endif
if cline =~# '^\s*-\=%>\s*$'
let ind = ind - &sw
endif
return ind
endfunction
" vim:set sw=2 sts=2 et:
More information about the vim-ruby-devel
mailing list