Bram Moolenaar | 1e01546 | 2005-09-25 22:16:38 +0000 | [diff] [blame] | 1 | " Vim indent file |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 2 | " Language: eRuby |
| 3 | " Maintainer: Tim Pope <vimNOSPAM@tpope.info> |
Bram Moolenaar | c6249bb | 2006-04-15 20:25:09 +0000 | [diff] [blame] | 4 | " Info: $Id$ |
| 5 | " URL: http://vim-ruby.rubyforge.org |
| 6 | " Anon CVS: See above site |
| 7 | " Release Coordinator: Doug Kearns <dougkearns@gmail.com> |
Bram Moolenaar | 1e01546 | 2005-09-25 22:16:38 +0000 | [diff] [blame] | 8 | |
Bram Moolenaar | 1e01546 | 2005-09-25 22:16:38 +0000 | [diff] [blame] | 9 | if exists("b:did_indent") |
| 10 | finish |
| 11 | endif |
| 12 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 13 | runtime! indent/ruby.vim |
| 14 | unlet! b:did_indent |
Bram Moolenaar | c6249bb | 2006-04-15 20:25:09 +0000 | [diff] [blame] | 15 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 16 | runtime! indent/html.vim |
| 17 | unlet! b:did_indent |
| 18 | |
| 19 | let b:did_indent = 1 |
| 20 | |
| 21 | setlocal indentexpr=GetErubyIndent(v:lnum) |
| 22 | setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when |
| 23 | |
| 24 | " Only define the function once. |
| 25 | if exists("*GetErubyIndent") |
| 26 | finish |
| 27 | endif |
| 28 | |
| 29 | function! 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 |
| 57 | endfunction |
| 58 | |
| 59 | " vim:set sw=2 sts=2 ts=8 noet ff=unix: |