532
|
1 " Vim indent file
|
1121
|
2 " Language: eRuby
|
|
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.info>
|
831
|
4 " Info: $Id$
|
|
5 " URL: http://vim-ruby.rubyforge.org
|
|
6 " Anon CVS: See above site
|
|
7 " Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
532
|
8
|
|
9 if exists("b:did_indent")
|
|
10 finish
|
|
11 endif
|
|
12
|
1121
|
13 runtime! indent/ruby.vim
|
|
14 unlet! b:did_indent
|
1668
|
15 setlocal indentexpr=
|
1121
|
16
|
1200
|
17 if exists("b:eruby_subtype")
|
|
18 exe "runtime! indent/".b:eruby_subtype.".vim"
|
|
19 else
|
|
20 runtime! indent/html.vim
|
|
21 endif
|
1121
|
22 unlet! b:did_indent
|
|
23
|
1200
|
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
|
|
32
|
1121
|
33 let b:did_indent = 1
|
|
34
|
1200
|
35 setlocal indentexpr=GetErubyIndent()
|
1121
|
36 setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when
|
|
37
|
|
38 " Only define the function once.
|
|
39 if exists("*GetErubyIndent")
|
|
40 finish
|
|
41 endif
|
831
|
42
|
1668
|
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
|
1121
|
49 let vcol = col('.')
|
1200
|
50 call cursor(v:lnum,1)
|
1620
|
51 let inruby = searchpair('<%','','%>','W')
|
1200
|
52 call cursor(v:lnum,vcol)
|
1668
|
53 if inruby && getline(v:lnum) !~ '^<%\|^\s*-\=%>'
|
1121
|
54 let ind = GetRubyIndent()
|
|
55 else
|
1200
|
56 exe "let ind = ".b:eruby_subtype_indentexpr
|
1121
|
57 endif
|
1200
|
58 let lnum = prevnonblank(v:lnum-1)
|
1121
|
59 let line = getline(lnum)
|
1200
|
60 let cline = getline(v:lnum)
|
1668
|
61 if cline =~# '<%-\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%(-\=%>\|$\)'
|
1121
|
62 let ind = ind - &sw
|
|
63 endif
|
1668
|
64 if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*-\=%>'
|
1121
|
65 let ind = ind + &sw
|
1668
|
66 elseif line =~# '<%-\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
|
1121
|
67 let ind = ind + &sw
|
|
68 endif
|
1668
|
69 if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
|
1121
|
70 let ind = ind + &sw
|
|
71 endif
|
|
72 if cline =~# '^\s*-\=%>\s*$'
|
|
73 let ind = ind - &sw
|
|
74 endif
|
|
75 return ind
|
|
76 endfunction
|
|
77
|
1620
|
78 " vim:set sw=2 sts=2 ts=8 noet:
|