Skip to content

Commit e426245

Browse files
committed
runtime(rust): clean-up indent script, handle opening empty line correctly
fixes: #18974 Signed-off-by: Christian Brabandt <[email protected]>
1 parent f99de42 commit e426245

1 file changed

Lines changed: 5 additions & 48 deletions

File tree

runtime/indent/rust.vim

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
" Language: Rust
33
" Author: Chris Morgan <[email protected]>
44
" Last Change: 2023-09-11
5-
" 2024 Jul 04 by Vim Project: use shiftwidth() instead of hard-coding shifted values (#15138)
5+
" 2024 Jul 04 by Vim Project: use shiftwidth() instead of hard-coding shifted values #15138
6+
" 2025 Dec 28 by Vim Project: clean up, handle opening empty line correctly #18974
67

78
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
89
" Note: upstream seems umaintained: https://github.com/rust-lang/rust.vim/issues/502
@@ -86,16 +87,6 @@ function! s:is_string_comment(lnum, col)
8687
endif
8788
endfunction
8889

89-
if exists('*shiftwidth')
90-
function! s:shiftwidth()
91-
return shiftwidth()
92-
endfunc
93-
else
94-
function! s:shiftwidth()
95-
return &shiftwidth
96-
endfunc
97-
endif
98-
9990
function GetRustIndent(lnum)
10091
" Starting assumption: cindent (called at the end) will do it right
10192
" normally. We just want to fix up a few cases.
@@ -240,44 +231,10 @@ function GetRustIndent(lnum)
240231
return indent(prevlinenum)
241232
endif
242233

243-
if !has("patch-7.4.355")
244-
" cindent before 7.4.355 doesn't do the module scope well at all; e.g.::
245-
"
246-
" static FOO : &'static [bool] = [
247-
" true,
248-
" false,
249-
" false,
250-
" true,
251-
" ];
252-
"
253-
" uh oh, next statement is indented further!
254-
255-
" Note that this does *not* apply the line continuation pattern properly;
256-
" that's too hard to do correctly for my liking at present, so I'll just
257-
" start with these two main cases (square brackets and not returning to
258-
" column zero)
259-
260-
call cursor(a:lnum, 1)
261-
if searchpair('{\|(', '', '}\|)', 'nbW',
262-
\ 's:is_string_comment(line("."), col("."))') == 0
263-
if searchpair('\[', '', '\]', 'nbW',
264-
\ 's:is_string_comment(line("."), col("."))') == 0
265-
" Global scope, should be zero
266-
return 0
267-
else
268-
" At the module scope, inside square brackets only
269-
"if getline(a:lnum)[0] == ']' || search('\[', '', '\]', 'nW') == a:lnum
270-
if line =~# "^\\s*]"
271-
" It's the closing line, dedent it
272-
return 0
273-
else
274-
return shiftwidth()
275-
endif
276-
endif
277-
endif
278-
endif
279-
280234
" Fall back on cindent, which does it mostly right
235+
if empty(trim(line))
236+
return cindent(prevlinenum)
237+
endif
281238
return cindent(a:lnum)
282239
endfunction
283240

0 commit comments

Comments
 (0)