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