Mercurial > vim
annotate runtime/indent/eruby.vim @ 20706:666c23d18e53
Added tag v8.2.0906 for changeset 5481c982a279c191fd8806546ab865e80f15847f
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 05 Jun 2020 19:45:04 +0200 |
parents | f0f06837a699 |
children |
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> |
15512 | 6 " Last Change: 2019 Jan 06 |
532 | 7 |
8 if exists("b:did_indent") | |
9 finish | |
10 endif | |
11 | |
1121 | 12 runtime! indent/ruby.vim |
13 unlet! b:did_indent | |
1668 | 14 setlocal indentexpr= |
1121 | 15 |
15512 | 16 if exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=# 'eruby' |
1200 | 17 exe "runtime! indent/".b:eruby_subtype.".vim" |
18 else | |
19 runtime! indent/html.vim | |
20 endif | |
1121 | 21 unlet! b:did_indent |
22 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
23 " 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
|
24 let b:html_indent_usestate = 0 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
25 |
1200 | 26 if &l:indentexpr == '' |
27 if &l:cindent | |
28 let &l:indentexpr = 'cindent(v:lnum)' | |
29 else | |
30 let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))' | |
31 endif | |
32 endif | |
33 let b:eruby_subtype_indentexpr = &l:indentexpr | |
34 | |
1121 | 35 let b:did_indent = 1 |
36 | |
1200 | 37 setlocal indentexpr=GetErubyIndent() |
1121 | 38 setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when |
39 | |
40 " Only define the function once. | |
41 if exists("*GetErubyIndent") | |
42 finish | |
43 endif | |
831 | 44 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
45 " this file uses line continuations |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
46 let s:cpo_sav = &cpo |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
47 set cpo&vim |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
48 |
1668 | 49 function! GetErubyIndent(...) |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
50 " The value of a single shift-width |
15512 | 51 if exists('*shiftwidth') |
52 let sw = shiftwidth() | |
53 else | |
54 let sw = &sw | |
55 endif | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
56 |
1668 | 57 if a:0 && a:1 == '.' |
58 let v:lnum = line('.') | |
59 elseif a:0 && a:1 =~ '^\d' | |
60 let v:lnum = a:1 | |
61 endif | |
1121 | 62 let vcol = col('.') |
1200 | 63 call cursor(v:lnum,1) |
1620 | 64 let inruby = searchpair('<%','','%>','W') |
1200 | 65 call cursor(v:lnum,vcol) |
4869 | 66 if inruby && getline(v:lnum) !~ '^<%\|^\s*[-=]\=%>' |
67 let ind = GetRubyIndent(v:lnum) | |
1121 | 68 else |
1200 | 69 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
|
70 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
71 " 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
|
72 " 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
|
73 if b:eruby_subtype_indentexpr =~# '^HtmlIndent(' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
74 \ && exists('b:indent') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
75 \ && type(b:indent) == type({}) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
76 \ && has_key(b:indent, 'lnum') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
77 " 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
|
78 let b:indent.lnum = -1 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
79 endif |
1121 | 80 endif |
1200 | 81 let lnum = prevnonblank(v:lnum-1) |
1121 | 82 let line = getline(lnum) |
1200 | 83 let cline = getline(v:lnum) |
4869 | 84 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
|
85 let ind = ind - sw |
2225 | 86 endif |
4869 | 87 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
|
88 let ind = ind - sw |
1121 | 89 endif |
4869 | 90 if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*[-=]\=%>' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
91 let ind = ind + sw |
4869 | 92 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
|
93 let ind = ind + sw |
1121 | 94 endif |
1668 | 95 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
|
96 let ind = ind + sw |
1121 | 97 endif |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
98 if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>' |
15512 | 99 \ && synID(v:lnum, match(cline, '\S') + 1, 1) != hlID('htmlEndTag') |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
100 let ind = ind - sw |
4869 | 101 endif |
102 if cline =~# '^\s*[-=]\=%>\s*$' | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
103 let ind = ind - sw |
1121 | 104 endif |
105 return ind | |
106 endfunction | |
107 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
108 let &cpo = s:cpo_sav |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
109 unlet! s:cpo_sav |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
110 |
1620 | 111 " vim:set sw=2 sts=2 ts=8 noet: |