robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:5ed3723: runtime(ruby): Update for Vim 9.2 release (#37806)c3defb4b45

master
2.9 KiB110 linesraw
1" Vim indent file
2" Language:		eRuby
3" Maintainer:		Tim Pope <vimNOSPAM@tpope.org>
4" URL:			https://github.com/vim-ruby/vim-ruby
5" Last Change:		2019 Jan 06
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") && b:eruby_subtype != '' && b:eruby_subtype !=# 'eruby'
16  exe "runtime! indent/".b:eruby_subtype.".vim"
17else
18  runtime! indent/html.vim
19endif
20unlet! b:did_indent
21
22" Force HTML indent to not keep state.
23let b:html_indent_usestate = 0
24
25if &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
31endif
32let b:eruby_subtype_indentexpr = &l:indentexpr
33
34let b:did_indent = 1
35
36setlocal indentexpr=GetErubyIndent()
37setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when
38
39" Only define the function once.
40if exists("*GetErubyIndent")
41  finish
42endif
43
44" this file uses line continuations
45let s:cpo_sav = &cpo
46set cpo&vim
47
48function! GetErubyIndent(...)
49  " The value of a single shift-width
50  if exists('*shiftwidth')
51    let sw = shiftwidth()
52  else
53    let sw = &sw
54  endif
55
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
61  let vcol = col('.')
62  call cursor(v:lnum,1)
63  let inruby = searchpair('<%','','%>','W')
64  call cursor(v:lnum,vcol)
65  if inruby && getline(v:lnum) !~ '^<%\|^\s*[-=]\=%>'
66    let ind = GetRubyIndent(v:lnum)
67  else
68    exe "let ind = ".b:eruby_subtype_indentexpr
69
70    " Workaround for Andy Wokula's HTML indent. This should be removed after
71    " some time, since the newest version is fixed in a different way.
72    if b:eruby_subtype_indentexpr =~# '^HtmlIndent('
73	  \ && exists('b:indent')
74	  \ && type(b:indent) == type({})
75	  \ && has_key(b:indent, 'lnum')
76      " Force HTML indent to not keep state
77      let b:indent.lnum = -1
78    endif
79  endif
80  let lnum = prevnonblank(v:lnum-1)
81  let line = getline(lnum)
82  let cline = getline(v:lnum)
83  if cline =~# '^\s*<%[-=]\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%([-=]\=%>\|$\)'
84    let ind = ind - sw
85  endif
86  if line =~# '\S\s*<%[-=]\=\s*\%(}\|end\).\{-\}\s*\%([-=]\=%>\|$\)'
87    let ind = ind - sw
88  endif
89  if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*[-=]\=%>'
90    let ind = ind + sw
91  elseif line =~# '<%[-=]\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
92    let ind = ind + sw
93  endif
94  if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
95    let ind = ind + sw
96  endif
97  if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>'
98	\ && synID(v:lnum, match(cline, '\S') + 1, 1) != hlID('htmlEndTag')
99    let ind = ind - sw
100  endif
101  if cline =~# '^\s*[-=]\=%>\s*$'
102    let ind = ind - sw
103  endif
104  return ind
105endfunction
106
107let &cpo = s:cpo_sav
108unlet! s:cpo_sav
109
110" vim:set sw=2 sts=2 ts=8 noet: