]> git.lizzy.rs Git - rust.git/commitdiff
Add another case where cindent is correct
authorBrandon Waskiewicz <brandon.waskiewicz@gmail.com>
Fri, 18 Apr 2014 18:12:50 +0000 (14:12 -0400)
committerBrandon Waskiewicz <brandon.waskiewicz@gmail.com>
Fri, 18 Apr 2014 18:12:50 +0000 (14:12 -0400)
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.

src/etc/vim/indent/rust.vim

index 1f08c5190214f68c711c561800b15384de4d0ef0..f7ac357b23a7fe53257bbc6e21eb92ac2dfc4fb7 100644 (file)
@@ -105,6 +105,7 @@ function GetRustIndent(lnum)
        if prevline[len(prevline) - 1] == ","
                                \ && s:get_line_trimmed(a:lnum) !~ "^\\s*[\\[\\]{}]"
                                \ && prevline !~ "^\\s*fn\\s"
+                               \ && prevline !~ "\\([^\\(\\)]\+,$"
                " Oh ho! The previous line ended in a comma! I bet cindent will try to
                " take this too far... For now, let's normally use the previous line's
                " indent.
@@ -119,6 +120,16 @@ function GetRustIndent(lnum)
                " fn foo(baz: Baz,
                "        baz: Baz) // <-- cindent gets this right by itself
                "
+               " Another case is similar to the previous, except calling a function
+               " instead of defining it, or any conditional expression that leaves
+               " an open paren:
+               "
+               " foo(baz,
+               "     baz);
+               "
+               " if baz && (foo ||
+               "            bar) {
+               "
                " There are probably other cases where we don't want to do this as
                " well. Add them as needed.
                return GetRustIndent(a:lnum - 1)