Skip to content

Commit 39116d0

Browse files
author
Julian Orth
committed
fix for vim < 7.4.355
1 parent 9c72da5 commit 39116d0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/etc/vim/indent/rust.vim

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,43 @@ function GetRustIndent(lnum)
154154
return indent(prevlinenum)
155155
endif
156156

157+
if !has("patch-7.4.355")
158+
" cindent before 7.4.355 doesn't do the module scope well at all; e.g.::
159+
"
160+
" static FOO : &'static [bool] = [
161+
" true,
162+
" false,
163+
" false,
164+
" true,
165+
" ];
166+
"
167+
" uh oh, next statement is indented further!
168+
169+
" Note that this does *not* apply the line continuation pattern properly;
170+
" that's too hard to do correctly for my liking at present, so I'll just
171+
" start with these two main cases (square brackets and not returning to
172+
" column zero)
173+
174+
call cursor(a:lnum, 1)
175+
if searchpair('{\|(', '', '}\|)', 'nbW',
176+
\ 's:is_string_comment(line("."), col("."))') == 0
177+
if searchpair('\[', '', '\]', 'nbW',
178+
\ 's:is_string_comment(line("."), col("."))') == 0
179+
" Global scope, should be zero
180+
return 0
181+
else
182+
" At the module scope, inside square brackets only
183+
"if getline(a:lnum)[0] == ']' || search('\[', '', '\]', 'nW') == a:lnum
184+
if line =~ "^\\s*]"
185+
" It's the closing line, dedent it
186+
return 0
187+
else
188+
return &shiftwidth
189+
endif
190+
endif
191+
endif
192+
endif
193+
157194
" Fall back on cindent, which does it mostly right
158195
return cindent(a:lnum)
159196
endfunction

0 commit comments

Comments
 (0)