Skip to content

Commit b75683c

Browse files
committed
auto merge of #13600 : brandonw/rust/master, r=brson
When calling a function, or anything with nested parens, default to cindent's indent. The least error-prone way I could think of identifying this is to look for a line that ends with a ',', as well as a non-zero number of any character except parens before the comma, and then an open paren. This will overlap with the previous rule accounting for function definitions, but that should be fine because it is also using cindent.
2 parents c44c7ab + 59f3414 commit b75683c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/etc/vim/indent/rust.vim

+11
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ function GetRustIndent(lnum)
105105
if prevline[len(prevline) - 1] == ","
106106
\ && s:get_line_trimmed(a:lnum) !~ "^\\s*[\\[\\]{}]"
107107
\ && prevline !~ "^\\s*fn\\s"
108+
\ && prevline !~ "\\([^\\(\\)]\+,$"
108109
" Oh ho! The previous line ended in a comma! I bet cindent will try to
109110
" take this too far... For now, let's normally use the previous line's
110111
" indent.
@@ -119,6 +120,16 @@ function GetRustIndent(lnum)
119120
" fn foo(baz: Baz,
120121
" baz: Baz) // <-- cindent gets this right by itself
121122
"
123+
" Another case is similar to the previous, except calling a function
124+
" instead of defining it, or any conditional expression that leaves
125+
" an open paren:
126+
"
127+
" foo(baz,
128+
" baz);
129+
"
130+
" if baz && (foo ||
131+
" bar) {
132+
"
122133
" There are probably other cases where we don't want to do this as
123134
" well. Add them as needed.
124135
return GetRustIndent(a:lnum - 1)

0 commit comments

Comments
 (0)