Skip to content

Commit 42e346c

Browse files
committed
updated for version 7.3.195
Problem: "} else" causes following lines to be indented too much. (Rouben Rostamian) Solution: Better detection for the "else". (Lech Lorens)
1 parent ed5764a commit 42e346c

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed

src/misc1.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5482,8 +5482,8 @@ cin_islinecomment(p)
54825482
* Recognize a line that starts with '{' or '}', or ends with ';', ',', '{' or
54835483
* '}'.
54845484
* Don't consider "} else" a terminated line.
5485-
* Don't consider a line where there are unmatched opening braces before '}',
5486-
* ';' or ',' a terminated line.
5485+
* If a line begins with an "else", only consider it terminated if no unmatched
5486+
* opening braces follow (handle "else { foo();" correctly).
54875487
* Return the character terminating the line (ending char's have precedence if
54885488
* both apply in order to determine initializations).
54895489
*/
@@ -5493,21 +5493,25 @@ cin_isterminated(s, incl_open, incl_comma)
54935493
int incl_open; /* include '{' at the end as terminator */
54945494
int incl_comma; /* recognize a trailing comma */
54955495
{
5496-
char_u found_start = 0;
5497-
unsigned n_open = 0;
5496+
char_u found_start = 0;
5497+
unsigned n_open = 0;
5498+
int is_else = FALSE;
54985499

54995500
s = cin_skipcomment(s);
55005501

55015502
if (*s == '{' || (*s == '}' && !cin_iselse(s)))
55025503
found_start = *s;
55035504

5505+
if (!found_start)
5506+
is_else = cin_iselse(s);
5507+
55045508
while (*s)
55055509
{
55065510
/* skip over comments, "" strings and 'c'haracters */
55075511
s = skip_string(cin_skipcomment(s));
55085512
if (*s == '}' && n_open > 0)
55095513
--n_open;
5510-
if (n_open == 0
5514+
if ((!is_else || n_open == 0)
55115515
&& (*s == ';' || *s == '}' || (incl_comma && *s == ','))
55125516
&& cin_nocode(s + 1))
55135517
return *s;

src/testdir/test3.in

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ func(int a
13451345

13461346
STARTTEST
13471347
:set cino&
1348-
2kdd=][
1348+
2kdd=4][
13491349
ENDTEST
13501350

13511351
void func(void)
@@ -1359,6 +1359,34 @@ void func(void)
13591359
printf("Foo!\n");
13601360
}
13611361

1362+
void func1(void)
1363+
{
1364+
char* tab[] = {"foo", "bar",
1365+
"baz", "quux",
1366+
"this line used", "to be indented incorrectly"};
1367+
foo();
1368+
}
1369+
1370+
void func2(void)
1371+
{
1372+
int tab[] =
1373+
{1, 2,
1374+
3, 4,
1375+
5, 6};
1376+
1377+
printf("This line used to be indented incorrectly.\n");
1378+
}
1379+
1380+
void func3(void)
1381+
{
1382+
int tab[] = {
1383+
1, 2,
1384+
3, 4,
1385+
5, 6};
1386+
1387+
printf("Don't you dare indent this line incorrectly!\n);
1388+
}
1389+
13621390
STARTTEST
13631391
:set cino&
13641392
2kdd=][

src/testdir/test3.ok

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,34 @@ void func(void)
12161216
printf("Foo!\n");
12171217
}
12181218

1219+
void func1(void)
1220+
{
1221+
char* tab[] = {"foo", "bar",
1222+
"baz", "quux",
1223+
"this line used", "to be indented incorrectly"};
1224+
foo();
1225+
}
1226+
1227+
void func2(void)
1228+
{
1229+
int tab[] =
1230+
{1, 2,
1231+
3, 4,
1232+
5, 6};
1233+
1234+
printf("This line used to be indented incorrectly.\n");
1235+
}
1236+
1237+
void func3(void)
1238+
{
1239+
int tab[] = {
1240+
1, 2,
1241+
3, 4,
1242+
5, 6};
1243+
1244+
printf("Don't you dare indent this line incorrectly!\n);
1245+
}
1246+
12191247

12201248
void func(void)
12211249
{

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ static char *(features[]) =
709709

710710
static int included_patches[] =
711711
{ /* Add new patch number below this line */
712+
/**/
713+
195,
712714
/**/
713715
194,
714716
/**/

0 commit comments

Comments
 (0)