summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <bram@vim.org>2011-05-25 13:34:04 +0200
committerBram Moolenaar <bram@vim.org>2011-05-25 13:34:04 +0200
commitd83a1dce581a7f6f896175fd090e5b89bc341221 (patch)
tree19a6dfeaa9d6379a38d586e46029ad64cf9cda8c
parentcddefcfed143e6b2752f800b9c69ec65658f1356 (diff)
downloadvim-d83a1dce581a7f6f896175fd090e5b89bc341221.tar.gz
updated for version 7.3.201v7.3.201v7-3-201
Problem: "} else" still causes following lines to be indented too much. Solution: Better detection for the "else" block. (Lech Lorens)
-rw-r--r--src/misc1.c22
-rw-r--r--src/testdir/test3.in15
-rw-r--r--src/testdir/test3.ok11
-rw-r--r--src/version.c2
4 files changed, 43 insertions, 7 deletions
diff --git a/src/misc1.c b/src/misc1.c
index 0959e2a2..0fc02ba9 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -7541,17 +7541,25 @@ get_c_indent()
/*
* When searching for a terminated line, don't use the
- * one between the "if" and the "else".
+ * one between the "if" and the matching "else".
* Need to use the scope of this "else". XXX
* If whilelevel != 0 continue looking for a "do {".
*/
- if (cin_iselse(l)
- && whilelevel == 0
- && ((trypos = find_start_brace(ind_maxcomment))
- == NULL
+ if (cin_iselse(l) && whilelevel == 0)
+ {
+ /* If we're looking at "} else", let's make sure we
+ * find the opening brace of the enclosing scope,
+ * not the one from "if () {". */
+ if (*l == '}')
+ curwin->w_cursor.col =
+ (l - ml_get_curline()) + 1;
+
+ if ((trypos = find_start_brace(ind_maxcomment))
+ == NULL
|| find_match(LOOKFOR_IF, trypos->lnum,
- ind_maxparen, ind_maxcomment) == FAIL))
- break;
+ ind_maxparen, ind_maxcomment) == FAIL)
+ break;
+ }
}
/*
diff --git a/src/testdir/test3.in b/src/testdir/test3.in
index 05efa984..0d372053 100644
--- a/src/testdir/test3.in
+++ b/src/testdir/test3.in
@@ -1413,6 +1413,21 @@ void func(void)
}
STARTTEST
+:set cino&
+2kdd=][
+ENDTEST
+
+void func(void)
+{
+ for (int i = 0; i < 10; ++i)
+ if (i & 1) {
+ foo(1);
+ } else
+ foo(0);
+baz();
+}
+
+STARTTEST
:g/^STARTTEST/.,/^ENDTEST/d
:1;/start of AUTO/,$wq! test.out
ENDTEST
diff --git a/src/testdir/test3.ok b/src/testdir/test3.ok
index 2e622728..852a4c59 100644
--- a/src/testdir/test3.ok
+++ b/src/testdir/test3.ok
@@ -1262,3 +1262,14 @@ void func(void)
foo();
}
+
+void func(void)
+{
+ for (int i = 0; i < 10; ++i)
+ if (i & 1) {
+ foo(1);
+ } else
+ foo(0);
+ baz();
+}
+
diff --git a/src/version.c b/src/version.c
index 14537c6f..64f49af8 100644
--- a/src/version.c
+++ b/src/version.c
@@ -710,6 +710,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 201,
+/**/
200,
/**/
199,