Patch 8.0.0148

27 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 7, 2017, 9:40:11 AM1/7/17
to vim...@googlegroups.com

Patch 8.0.0148
Problem: When a C preprocessor statement has two line continuations the
following line does not have the right indent. (Ken Takata)
Solution: Add the indent of the previous continuation line. (Hirohito
Higashi)
Files: src/misc1.c, src/testdir/test3.in, src/testdir/test3.ok


*** ../vim-8.0.0147/src/misc1.c 2016-11-17 21:30:17.144445729 +0100
--- src/misc1.c 2017-01-07 14:09:00.601851661 +0100
***************
*** 5422,5428 ****
static int cin_first_id_amount(void);
static int cin_get_equal_amount(linenr_T lnum);
static int cin_ispreproc(char_u *);
- static int cin_ispreproc_cont(char_u **pp, linenr_T *lnump);
static int cin_iscomment(char_u *);
static int cin_islinecomment(char_u *);
static int cin_isterminated(char_u *, int, int);
--- 5422,5427 ----
***************
*** 6002,6014 ****
* Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a
* continuation line of a preprocessor statement. Decrease "*lnump" to the
* start and return the line in "*pp".
*/
static int
! cin_ispreproc_cont(char_u **pp, linenr_T *lnump)
{
char_u *line = *pp;
linenr_T lnum = *lnump;
int retval = FALSE;

for (;;)
{
--- 6001,6018 ----
* Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a
* continuation line of a preprocessor statement. Decrease "*lnump" to the
* start and return the line in "*pp".
+ * Put the amount of indent in "*amount".
*/
static int
! cin_ispreproc_cont(char_u **pp, linenr_T *lnump, int *amount)
{
char_u *line = *pp;
linenr_T lnum = *lnump;
int retval = FALSE;
+ int candidate_amount = *amount;
+
+ if (*line != NUL && line[STRLEN(line) - 1] == '\\')
+ candidate_amount = get_indent_lnum(lnum);

for (;;)
{
***************
*** 6027,6032 ****
--- 6031,6038 ----

if (lnum != *lnump)
*pp = ml_get(*lnump);
+ if (retval)
+ *amount = candidate_amount;
return retval;
}

***************
*** 7390,7396 ****
l = skipwhite(ml_get(lnum));
if (cin_nocode(l)) /* skip comment lines */
continue;
! if (cin_ispreproc_cont(&l, &lnum))
continue; /* ignore #define, #if, etc. */
curwin->w_cursor.lnum = lnum;

--- 7396,7402 ----
l = skipwhite(ml_get(lnum));
if (cin_nocode(l)) /* skip comment lines */
continue;
! if (cin_ispreproc_cont(&l, &lnum, &amount))
continue; /* ignore #define, #if, etc. */
curwin->w_cursor.lnum = lnum;

***************
*** 7803,7812 ****
*/
if (curwin->w_cursor.lnum <= ourscope)
{
! /* we reached end of scope:
! * if looking for a enum or structure initialization
* go further back:
! * if it is an initializer (enum xxx or xxx =), then
* don't add ind_continuation, otherwise it is a variable
* declaration:
* int x,
--- 7809,7818 ----
*/
if (curwin->w_cursor.lnum <= ourscope)
{
! /* We reached end of scope:
! * If looking for a enum or structure initialization
* go further back:
! * If it is an initializer (enum xxx or xxx =), then
* don't add ind_continuation, otherwise it is a variable
* declaration:
* int x,
***************
*** 7845,7851 ****
/*
* Skip preprocessor directives and blank lines.
*/
! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum))
continue;

if (cin_nocode(l))
--- 7851,7858 ----
/*
* Skip preprocessor directives and blank lines.
*/
! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum,
! &amount))
continue;

if (cin_nocode(l))
***************
*** 7962,7968 ****
}

/* Skip preprocessor directives and blank lines. */
! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum))
continue;

/* Finally the actual check for "namespace". */
--- 7969,7976 ----
}

/* Skip preprocessor directives and blank lines. */
! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum,
! &amount))
continue;

/* Finally the actual check for "namespace". */
***************
*** 8138,8144 ****
* unlocked it)
*/
l = ml_get_curline();
! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)
|| cin_nocode(l))
continue;

--- 8146,8152 ----
* unlocked it)
*/
l = ml_get_curline();
! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)
|| cin_nocode(l))
continue;

***************
*** 8859,8865 ****
/*
* Skip preprocessor directives and blank lines.
*/
! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum))
continue;

if (cin_nocode(l))
--- 8867,8873 ----
/*
* Skip preprocessor directives and blank lines.
*/
! if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount))
continue;

if (cin_nocode(l))
***************
*** 8960,8966 ****
{
look = ml_get(--curwin->w_cursor.lnum);
if (!(cin_nocode(look) || cin_ispreproc_cont(
! &look, &curwin->w_cursor.lnum)))
break;
}
if (curwin->w_cursor.lnum > 0
--- 8968,8974 ----
{
look = ml_get(--curwin->w_cursor.lnum);
if (!(cin_nocode(look) || cin_ispreproc_cont(
! &look, &curwin->w_cursor.lnum, &amount)))
break;
}
if (curwin->w_cursor.lnum > 0
*** ../vim-8.0.0147/src/testdir/test3.in 2016-11-17 21:30:17.144445729 +0100
--- src/testdir/test3.in 2017-01-07 14:03:05.980471398 +0100
***************
*** 2318,2323 ****
--- 2318,2342 ----
JSEND

STARTTEST
+ :set cin cino&
+ /start of define
+ =/end of define
+ ENDTEST
+
+ /* start of define */
+ {
+ }
+ #define AAA \
+ BBB\
+ CCC
+
+ #define CNT \
+ 1 + \
+ 2 + \
+ 4
+ /* end of define */
+
+ STARTTEST
:g/^STARTTEST/.,/^ENDTEST/d
:1;/start of AUTO/,$wq! test.out
ENDTEST
*** ../vim-8.0.0147/src/testdir/test3.ok 2016-11-17 21:30:17.144445729 +0100
--- src/testdir/test3.ok 2017-01-07 14:03:05.980471398 +0100
***************
*** 2080,2082 ****
--- 2080,2096 ----
i;
JSEND

+
+ /* start of define */
+ {
+ }
+ #define AAA \
+ BBB\
+ CCC
+
+ #define CNT \
+ 1 + \
+ 2 + \
+ 4
+ /* end of define */
+
*** ../vim-8.0.0147/src/version.c 2017-01-06 20:03:45.430748917 +0100
--- src/version.c 2017-01-07 14:02:42.520644763 +0100
***************
*** 766,767 ****
--- 766,769 ----
{ /* Add new patch number below this line */
+ /**/
+ 148,
/**/

--
Spam seems to be something useful to novices. Later you realize that
it's a bunch of indigestable junk that only clogs your system.
Applies to both the food and the e-mail!

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

h_east

unread,
Jan 7, 2017, 9:48:38 AM1/7/17
to vim_dev
Hi Bram,

2017-1-7(Sat) 23:40:11 UTC+9 Bram Moolenaar:


> Patch 8.0.0148
> Problem: When a C preprocessor statement has two line continuations the
> following line does not have the right indent. (Ken Takata)
> Solution: Add the indent of the previous continuation line. (Hirohito
> Higashi)
> Files: src/misc1.c, src/testdir/test3.in, src/testdir/test3.ok
>
>
> *** ../vim-8.0.0147/src/misc1.c 2016-11-17 21:30:17.144445729 +0100
> --- src/misc1.c 2017-01-07 14:09:00.601851661 +0100
> ***************
> *** 5422,5428 ****
> static int cin_first_id_amount(void);
> static int cin_get_equal_amount(linenr_T lnum);
> static int cin_ispreproc(char_u *);
> - static int cin_ispreproc_cont(char_u **pp, linenr_T *lnump);
> static int cin_iscomment(char_u *);
> static int cin_islinecomment(char_u *);
> static int cin_isterminated(char_u *, int, int);
> --- 5422,5427 ----

Thanks including my patch.
Perhaps, it seems that some of my patch is not reflected.

Please check the following text.

diff --git a/src/misc1.c b/src/misc1.c
index 3630d7b..1f16958 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -5422,7 +5422,7 @@ static int skip_label(linenr_T, char_u **pp);


static int cin_first_id_amount(void);
static int cin_get_equal_amount(linenr_T lnum);
static int cin_ispreproc(char_u *);

-static int cin_ispreproc_cont(char_u **pp, linenr_T *lnump);
+static int cin_ispreproc_cont(char_u **pp, linenr_T *lnump, int *amount);


static int cin_iscomment(char_u *);
static int cin_islinecomment(char_u *);
static int cin_isterminated(char_u *, int, int);

--
Best regards,
Hirohito Higashi (a.k.a. h_east)

h_east

unread,
Jan 7, 2017, 10:06:25 AM1/7/17
to vim_dev
Hi Bram,

Ah, There is no problem because the function body is in front of the use point, right?

Bram Moolenaar

unread,
Jan 7, 2017, 10:36:06 AM1/7/17
to vim...@googlegroups.com, h_east

Hirohito Higashi wrote:

> Ah, There is no problem because the function body is in front of the
> use point, right?

Correct. We changed K&R function headers to ANSI style, but we haven't
removed superfluous declarations. Will do that once in a while.

--
hundred-and-one symptoms of being an internet addict:
203. You're an active member of more than 20 newsgroups.
Reply all
Reply to author
Forward
0 new messages