Merge branch 'vim-with-runtime' into feat/quickfix-title
[vim_extended.git] / runtime / indent / eruby.vim
blob931eaac3859ebc42ebdc699ad5da3baf9530fc88
1 " Vim indent file
2 " Language:             eRuby
3 " Maintainer:           Tim Pope <vimNOSPAM@tpope.info>
4 " Info:                 $Id: eruby.vim,v 1.16 2008/06/29 04:18:43 tpope Exp $
5 " URL:                  http://vim-ruby.rubyforge.org
6 " Anon CVS:             See above site
7 " Release Coordinator:  Doug Kearns <dougkearns@gmail.com>
9 if exists("b:did_indent")
10   finish
11 endif
13 runtime! indent/ruby.vim
14 unlet! b:did_indent
15 setlocal indentexpr=
17 if exists("b:eruby_subtype")
18   exe "runtime! indent/".b:eruby_subtype.".vim"
19 else
20   runtime! indent/html.vim
21 endif
22 unlet! b:did_indent
24 if &l:indentexpr == ''
25   if &l:cindent
26     let &l:indentexpr = 'cindent(v:lnum)'
27   else
28     let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'
29   endif
30 endif
31 let b:eruby_subtype_indentexpr = &l:indentexpr
33 let b:did_indent = 1
35 setlocal indentexpr=GetErubyIndent()
36 setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when
38 " Only define the function once.
39 if exists("*GetErubyIndent")
40   finish
41 endif
43 function! GetErubyIndent(...)
44   if a:0 && a:1 == '.'
45     let v:lnum = line('.')
46   elseif a:0 && a:1 =~ '^\d'
47     let v:lnum = a:1
48   endif
49   let vcol = col('.')
50   call cursor(v:lnum,1)
51   let inruby = searchpair('<%','','%>','W')
52   call cursor(v:lnum,vcol)
53   if inruby && getline(v:lnum) !~ '^<%\|^\s*-\=%>'
54     let ind = GetRubyIndent()
55   else
56     exe "let ind = ".b:eruby_subtype_indentexpr
57   endif
58   let lnum = prevnonblank(v:lnum-1)
59   let line = getline(lnum)
60   let cline = getline(v:lnum)
61   if cline =~# '<%-\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%(-\=%>\|$\)'
62     let ind = ind - &sw
63   endif
64   if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*-\=%>'
65     let ind = ind + &sw
66   elseif line =~# '<%-\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
67     let ind = ind + &sw
68   endif
69   if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
70     let ind = ind + &sw
71   endif
72   if cline =~# '^\s*-\=%>\s*$'
73     let ind = ind - &sw
74   endif
75   return ind
76 endfunction
78 " vim:set sw=2 sts=2 ts=8 noet: