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