On 15-May-2011 Bram Moolenaar <[email protected]> wrote:
> Lech Lorens wrote:
> > > > 9   "} else" causes following lines to be indented too much. (Rouben
> > > >     Rostamian, 2008 Aug 30)
> > > 
> > 
> > Unfortunately the patch I proposed to solve this problem introduces 
> > 2 new ones:

> OK.  Please add the broken text to the test.

Managed to find a solution to the problem. Also added 3 more tests.
Find the patch attached.

-- 
Cheers,
Lech

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/src/misc1.c b/src/misc1.c
index f1ab848..ed47c53 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -5482,8 +5482,8 @@ cin_islinecomment(p)
  * Recognize a line that starts with '{' or '}', or ends with ';', ',', '{' or
  * '}'.
  * Don't consider "} else" a terminated line.
- * Don't consider a line where there are unmatched opening braces before '}',
- * ';' or ',' a terminated line.
+ * If a line begins with an "else", only consider it terminated if no unmatched
+ * opening braces follow (handle "else { foo();" correctly).
  * Return the character terminating the line (ending char's have precedence if
  * both apply in order to determine initializations).
  */
@@ -5495,19 +5495,23 @@ cin_isterminated(s, incl_open, incl_comma)
 {
     char_u found_start = 0;
     unsigned n_open = 0;
+    int is_else = FALSE;
 
     s = cin_skipcomment(s);
 
     if (*s == '{' || (*s == '}' && !cin_iselse(s)))
 	found_start = *s;
 
+    if (!found_start)
+	is_else = cin_iselse(s);
+
     while (*s)
     {
 	/* skip over comments, "" strings and 'c'haracters */
 	s = skip_string(cin_skipcomment(s));
 	if (*s == '}' && n_open > 0)
 	    --n_open;
-	if (n_open == 0
+	if ((is_else == FALSE || n_open == 0)
 		&& (*s == ';' || *s == '}' || (incl_comma && *s == ','))
 		&& cin_nocode(s + 1))
 	    return *s;
diff --git a/src/testdir/test3.in b/src/testdir/test3.in
index 56a1dc8..05efa98 100644
--- a/src/testdir/test3.in
+++ b/src/testdir/test3.in
@@ -1345,7 +1345,7 @@ func(int a
 
 STARTTEST
 :set cino&
-2kdd=][
+2kdd=4][
 ENDTEST
 
 void func(void)
@@ -1359,6 +1359,34 @@ void func(void)
 	printf("Foo!\n");
 }
 
+void func1(void)
+{
+	char* tab[] = {"foo", "bar",
+		"baz", "quux",
+			"this line used", "to be indented incorrectly"};
+	foo();
+}
+
+void func2(void)
+{
+	int tab[] =
+	{1, 2,
+		3, 4,
+		5, 6};
+
+		printf("This line used to be indented incorrectly.\n");
+}
+
+void func3(void)
+{
+	int tab[] = {
+	1, 2,
+	3, 4,
+	5, 6};
+
+printf("Don't you dare indent this line incorrectly!\n);
+}
+
 STARTTEST
 :set cino&
 2kdd=][
diff --git a/src/testdir/test3.ok b/src/testdir/test3.ok
index 656b16e..2e62272 100644
--- a/src/testdir/test3.ok
+++ b/src/testdir/test3.ok
@@ -1216,6 +1216,34 @@ void func(void)
 	printf("Foo!\n");
 }
 
+void func1(void)
+{
+	char* tab[] = {"foo", "bar",
+		"baz", "quux",
+		"this line used", "to be indented incorrectly"};
+	foo();
+}
+
+void func2(void)
+{
+	int tab[] =
+	{1, 2,
+		3, 4,
+		5, 6};
+
+	printf("This line used to be indented incorrectly.\n");
+}
+
+void func3(void)
+{
+	int tab[] = {
+		1, 2,
+		3, 4,
+		5, 6};
+
+	printf("Don't you dare indent this line incorrectly!\n);
+}
+
 
 void func(void)
 {

Raspunde prin e-mail lui