Skip to content

Commit 419b108

Browse files
committed
updated for version 7.3.380
Problem: C-indenting wrong for a function header. Solution: Skip to the start paren. (Lech Lorens)
1 parent afc0ee8 commit 419b108

File tree

4 files changed

+81
-10
lines changed

4 files changed

+81
-10
lines changed

src/misc1.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4943,7 +4943,7 @@ static int cin_iscomment __ARGS((char_u *));
49434943
static int cin_islinecomment __ARGS((char_u *));
49444944
static int cin_isterminated __ARGS((char_u *, int, int));
49454945
static int cin_isinit __ARGS((void));
4946-
static int cin_isfuncdecl __ARGS((char_u **, linenr_T));
4946+
static int cin_isfuncdecl __ARGS((char_u **, linenr_T, linenr_T, int, int));
49474947
static int cin_isif __ARGS((char_u *));
49484948
static int cin_iselse __ARGS((char_u *));
49494949
static int cin_isdo __ARGS((char_u *));
@@ -5585,21 +5585,37 @@ cin_isterminated(s, incl_open, incl_comma)
55855585
* "sp" points to a string with the line. When looking at other lines it must
55865586
* be restored to the line. When it's NULL fetch lines here.
55875587
* "lnum" is where we start looking.
5588+
* "min_lnum" is the line before which we will not be looking.
55885589
*/
55895590
static int
5590-
cin_isfuncdecl(sp, first_lnum)
5591+
cin_isfuncdecl(sp, first_lnum, min_lnum, ind_maxparen, ind_maxcomment)
55915592
char_u **sp;
55925593
linenr_T first_lnum;
5594+
linenr_T min_lnum;
5595+
int ind_maxparen;
5596+
int ind_maxcomment;
55935597
{
55945598
char_u *s;
55955599
linenr_T lnum = first_lnum;
55965600
int retval = FALSE;
5601+
pos_T *trypos;
5602+
int just_started = TRUE;
55975603

55985604
if (sp == NULL)
55995605
s = ml_get(lnum);
56005606
else
56015607
s = *sp;
56025608

5609+
if (find_last_paren(s, '(', ')')
5610+
&& (trypos = find_match_paren(ind_maxparen, ind_maxcomment)) != NULL)
5611+
{
5612+
lnum = trypos->lnum;
5613+
if (lnum < min_lnum)
5614+
return FALSE;
5615+
5616+
s = ml_get(lnum);
5617+
}
5618+
56035619
/* Ignore line starting with #. */
56045620
if (cin_ispreproc(s))
56055621
return FALSE;
@@ -5650,13 +5666,17 @@ cin_isfuncdecl(sp, first_lnum)
56505666
/* Require a comma at end of the line or a comma or ')' at the
56515667
* start of next line. */
56525668
s = skipwhite(s);
5653-
if (!comma && *s != ',' && *s != ')')
5669+
if (!just_started && (!comma && *s != ',' && *s != ')'))
56545670
break;
5671+
just_started = FALSE;
56555672
}
56565673
else if (cin_iscomment(s)) /* ignore comments */
56575674
s = cin_skipcomment(s);
56585675
else
5676+
{
56595677
++s;
5678+
just_started = FALSE;
5679+
}
56605680
}
56615681

56625682
done:
@@ -7158,7 +7178,8 @@ get_c_indent()
71587178
* (it's a variable declaration).
71597179
*/
71607180
if (start_brace != BRACE_IN_COL0
7161-
|| !cin_isfuncdecl(&l, curwin->w_cursor.lnum))
7181+
|| !cin_isfuncdecl(&l, curwin->w_cursor.lnum,
7182+
0, ind_maxparen, ind_maxcomment))
71627183
{
71637184
/* if the line is terminated with another ','
71647185
* it is a continued variable initialization.
@@ -8019,7 +8040,9 @@ get_c_indent()
80198040
&& vim_strchr(theline, '}') == NULL
80208041
&& !cin_ends_in(theline, (char_u *)":", NULL)
80218042
&& !cin_ends_in(theline, (char_u *)",", NULL)
8022-
&& cin_isfuncdecl(NULL, cur_curpos.lnum + 1)
8043+
&& cin_isfuncdecl(NULL, cur_curpos.lnum + 1,
8044+
cur_curpos.lnum + 1,
8045+
ind_maxparen, ind_maxcomment)
80238046
&& !cin_isterminated(theline, FALSE, TRUE))
80248047
{
80258048
amount = ind_func_type;
@@ -8125,7 +8148,8 @@ get_c_indent()
81258148
* If the line looks like a function declaration, and we're
81268149
* not in a comment, put it the left margin.
81278150
*/
8128-
if (cin_isfuncdecl(NULL, cur_curpos.lnum)) /* XXX */
8151+
if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0,
8152+
ind_maxparen, ind_maxcomment)) /* XXX */
81298153
break;
81308154
l = ml_get_curline();
81318155

@@ -8173,7 +8197,8 @@ get_c_indent()
81738197
* line (and the ones that follow) needs to be indented as
81748198
* parameters.
81758199
*/
8176-
if (cin_isfuncdecl(&l, curwin->w_cursor.lnum))
8200+
if (cin_isfuncdecl(&l, curwin->w_cursor.lnum, 0,
8201+
ind_maxparen, ind_maxcomment))
81778202
{
81788203
amount = ind_param;
81798204
break;

src/testdir/test3.in

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ func(int a
14291429

14301430
STARTTEST
14311431
:set cino&
1432-
2kdd=4][
1432+
2kdd=7][
14331433
ENDTEST
14341434

14351435
void func(void)
@@ -1478,7 +1478,29 @@ void func3(void)
14781478
3, 4,
14791479
5, 6};
14801480

1481-
printf("Don't you dare indent this line incorrectly!\n);
1481+
printf("Don't you dare indent this line incorrectly!\n");
1482+
}
1483+
1484+
void
1485+
func4(a, b,
1486+
c)
1487+
int a;
1488+
int b;
1489+
int c;
1490+
{
1491+
}
1492+
1493+
void
1494+
func5(
1495+
int a,
1496+
int b)
1497+
{
1498+
}
1499+
1500+
void
1501+
func6(
1502+
int a)
1503+
{
14821504
}
14831505

14841506
STARTTEST

src/testdir/test3.ok

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,29 @@ void func3(void)
13311331
3, 4,
13321332
5, 6};
13331333

1334-
printf("Don't you dare indent this line incorrectly!\n);
1334+
printf("Don't you dare indent this line incorrectly!\n");
1335+
}
1336+
1337+
void
1338+
func4(a, b,
1339+
c)
1340+
int a;
1341+
int b;
1342+
int c;
1343+
{
1344+
}
1345+
1346+
void
1347+
func5(
1348+
int a,
1349+
int b)
1350+
{
1351+
}
1352+
1353+
void
1354+
func6(
1355+
int a)
1356+
{
13351357
}
13361358

13371359

src/version.c

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

715715
static int included_patches[] =
716716
{ /* Add new patch number below this line */
717+
/**/
718+
380,
717719
/**/
718720
379,
719721
/**/

0 commit comments

Comments
 (0)