Skip to content

Commit d4beeb5

Browse files
committed
Fix indentation for closing parentheses
To help explain this problem, consider this input (where | is the cursor): foo(|) Prior to this commit, pressing Enter would result in the following: foo( |) That is, the closing parenthesis is indented by one level. This is the case regardless of the cindent options/keys chosen. To fix this, we manually indent lines that start with a ")" (ignoring leading whitespace). Such lines are indented according to the indentation of the line that contained the opening parenthesis. Fixes #443
1 parent 87c745d commit d4beeb5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

indent/rust.vim

+25
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,31 @@ function GetRustIndent(lnum)
272272
endif
273273
endif
274274

275+
" cindent by messes up indentation of parentheses. It does so regardless of
276+
" the cindent options.
277+
"
278+
" Consider this input example, where | is the cursor:
279+
"
280+
" foo(|)
281+
"
282+
" When pressing Enter, the indentation will be this:
283+
"
284+
" foo(
285+
" |)
286+
"
287+
" But that's not what we want, we want it to be this instead:
288+
"
289+
" foo(
290+
" |)
291+
if line =~# '\V\^\s\*)'
292+
let l:paren_start = searchpair('(', '', ')', 'nbW',
293+
\ 's:is_string_comment(line("."), col("."))')
294+
295+
if l:paren_start != 0 && l:paren_start < a:lnum
296+
return indent(l:paren_start)
297+
endif
298+
endif
299+
275300
" Fall back on cindent, which does it mostly right
276301
return cindent(a:lnum)
277302
endfunction

0 commit comments

Comments
 (0)