Skip to content

Commit 1ad8dbe

Browse files
committed
Fix Vim indent for wrapped function arguments.
1 parent c20186b commit 1ad8dbe

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/etc/vim/indent/rust.vim

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Vim indent file
22
" Language: Rust
33
" Author: Chris Morgan <[email protected]>
4-
" Last Change: 2013 Jul 10
4+
" Last Change: 2013 Oct 29
55

66
" Only load this indent file when no other was loaded.
77
if exists("b:did_indent")
@@ -104,8 +104,23 @@ function GetRustIndent(lnum)
104104
let prevline = s:get_line_trimmed(prevnonblank(a:lnum - 1))
105105
if prevline[len(prevline) - 1] == ","
106106
\ && s:get_line_trimmed(a:lnum) !~ "^\\s*[\\[\\]{}]"
107+
\ && prevline !~ "^\\s*fn\\s"
107108
" Oh ho! The previous line ended in a comma! I bet cindent will try to
108-
" take this too far... For now, let's use the previous line's indent
109+
" take this too far... For now, let's normally use the previous line's
110+
" indent.
111+
112+
" One case where this doesn't work out is where *this* line contains
113+
" square or curly brackets; then we normally *do* want to be indenting
114+
" further.
115+
"
116+
" Another case where we don't want to is one like a function
117+
" definition with arguments spread over multiple lines:
118+
"
119+
" fn foo(baz: Baz,
120+
" baz: Baz) // <-- cindent gets this right by itself
121+
"
122+
" There are probably other cases where we don't want to do this as
123+
" well. Add them as needed.
109124
return GetRustIndent(a:lnum - 1)
110125
endif
111126

0 commit comments

Comments
 (0)