Mercurial > vim
annotate runtime/indent/eruby.vim @ 10263:b758a787983a
Added tag v8.0.0028 for changeset d69ee8806ec993208ae429dc8fbc452cfecf2fed
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 12 Oct 2016 12:15:05 +0200 |
parents | 43efa4f5a8ea |
children | 63b0b7b79b25 |
rev | line source |
---|---|
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 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
22 " Force HTML indent to not keep state. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
23 let b:html_indent_usestate = 0 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
24 |
1200 | 25 if &l:indentexpr == '' |
26 if &l:cindent | |
27 let &l:indentexpr = 'cindent(v:lnum)' | |
28 else | |
29 let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))' | |
30 endif | |
31 endif | |
32 let b:eruby_subtype_indentexpr = &l:indentexpr | |
33 | |
1121 | 34 let b:did_indent = 1 |
35 | |
1200 | 36 setlocal indentexpr=GetErubyIndent() |
1121 | 37 setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when |
38 | |
39 " Only define the function once. | |
40 if exists("*GetErubyIndent") | |
41 finish | |
42 endif | |
831 | 43 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
44 " this file uses line continuations |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
45 let s:cpo_sav = &cpo |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
46 set cpo&vim |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
47 |
1668 | 48 function! GetErubyIndent(...) |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
49 " The value of a single shift-width |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
50 if exists('*shiftwidth') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
51 let sw = shiftwidth() |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
52 else |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
53 let sw = &sw |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
54 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
55 |
1668 | 56 if a:0 && a:1 == '.' |
57 let v:lnum = line('.') | |
58 elseif a:0 && a:1 =~ '^\d' | |
59 let v:lnum = a:1 | |
60 endif | |
1121 | 61 let vcol = col('.') |
1200 | 62 call cursor(v:lnum,1) |
1620 | 63 let inruby = searchpair('<%','','%>','W') |
1200 | 64 call cursor(v:lnum,vcol) |
4869 | 65 if inruby && getline(v:lnum) !~ '^<%\|^\s*[-=]\=%>' |
66 let ind = GetRubyIndent(v:lnum) | |
1121 | 67 else |
1200 | 68 exe "let ind = ".b:eruby_subtype_indentexpr |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
69 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
70 " Workaround for Andy Wokula's HTML indent. This should be removed after |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
71 " some time, since the newest version is fixed in a different way. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
72 if b:eruby_subtype_indentexpr =~# '^HtmlIndent(' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
73 \ && exists('b:indent') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
74 \ && type(b:indent) == type({}) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
75 \ && has_key(b:indent, 'lnum') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
76 " Force HTML indent to not keep state |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
77 let b:indent.lnum = -1 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
78 endif |
1121 | 79 endif |
1200 | 80 let lnum = prevnonblank(v:lnum-1) |
1121 | 81 let line = getline(lnum) |
1200 | 82 let cline = getline(v:lnum) |
4869 | 83 if cline =~# '^\s*<%[-=]\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%([-=]\=%>\|$\)' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
84 let ind = ind - sw |
2225 | 85 endif |
4869 | 86 if line =~# '\S\s*<%[-=]\=\s*\%(}\|end\).\{-\}\s*\%([-=]\=%>\|$\)' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
87 let ind = ind - sw |
1121 | 88 endif |
4869 | 89 if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*[-=]\=%>' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
90 let ind = ind + sw |
4869 | 91 elseif line =~# '<%[-=]\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
92 let ind = ind + sw |
1121 | 93 endif |
1668 | 94 if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
95 let ind = ind + sw |
1121 | 96 endif |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
97 if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
98 let ind = ind - sw |
4869 | 99 endif |
100 if cline =~# '^\s*[-=]\=%>\s*$' | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
101 let ind = ind - sw |
1121 | 102 endif |
103 return ind | |
104 endfunction | |
105 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
106 let &cpo = s:cpo_sav |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
107 unlet! s:cpo_sav |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
108 |
1620 | 109 " vim:set sw=2 sts=2 ts=8 noet: |