blob: d621bfa08b53048d7a76778914aedf62fd250ab4 [file] [log] [blame]
Bram Moolenaar1e015462005-09-25 22:16:38 +00001" Vim indent file
Bram Moolenaar9964e462007-05-05 17:54:07 +00002" Language: eRuby
3" Maintainer: Tim Pope <vimNOSPAM@tpope.info>
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00004" Info: $Id$
5" URL: http://vim-ruby.rubyforge.org
6" Anon CVS: See above site
7" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
Bram Moolenaar1e015462005-09-25 22:16:38 +00008
Bram Moolenaar1e015462005-09-25 22:16:38 +00009if exists("b:did_indent")
10 finish
11endif
12
Bram Moolenaar9964e462007-05-05 17:54:07 +000013runtime! indent/ruby.vim
14unlet! b:did_indent
Bram Moolenaarc6249bb2006-04-15 20:25:09 +000015
Bram Moolenaar9964e462007-05-05 17:54:07 +000016runtime! indent/html.vim
17unlet! b:did_indent
18
19let b:did_indent = 1
20
21setlocal indentexpr=GetErubyIndent(v:lnum)
22setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when
23
24" Only define the function once.
25if exists("*GetErubyIndent")
26 finish
27endif
28
29function! GetErubyIndent(lnum)
30 let vcol = col('.')
31 call cursor(a:lnum,1)
32 let inruby = searchpair('<%','','%>')
33 call cursor(a:lnum,vcol)
34 if inruby && getline(a:lnum) !~ '^<%'
35 let ind = GetRubyIndent()
36 else
37 let ind = HtmlIndentGet(a:lnum)
38 endif
39 let lnum = prevnonblank(a:lnum-1)
40 let line = getline(lnum)
41 let cline = getline(a:lnum)
42 if cline =~# '<%\s*\%(end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%(-\=%>\|$\)'
43 let ind = ind - &sw
44 endif
45 if line =~# '\<do\%(\s*|[^|]*|\)\=\s*-\=%>'
46 let ind = ind + &sw
47 elseif line =~# '<%\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
48 let ind = ind + &sw
49 endif
50 if line =~# '^\s*<%[=#]\=\s*$' && cline !~# '^\s*end\>'
51 let ind = ind + &sw
52 endif
53 if cline =~# '^\s*-\=%>\s*$'
54 let ind = ind - &sw
55 endif
56 return ind
57endfunction
58
59" vim:set sw=2 sts=2 ts=8 noet ff=unix: