aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/indent_c.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/indent_c.c')
-rw-r--r--src/nvim/indent_c.c82
1 files changed, 48 insertions, 34 deletions
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index 4a6393ac36..279d45bb0a 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -734,16 +734,20 @@ static int cin_ispreproc(char_u *s)
return FALSE;
}
-/*
- * 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)
+/// 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 retval = false;
+ int candidate_amount = *amount;
+
+ if (*line != NUL && line[STRLEN(line) - 1] == '\\') {
+ candidate_amount = get_indent_lnum(lnum);
+ }
for (;; ) {
if (cin_ispreproc(line)) {
@@ -758,8 +762,12 @@ static int cin_ispreproc_cont(char_u **pp, linenr_T *lnump)
break;
}
- if (lnum != *lnump)
+ if (lnum != *lnump) {
*pp = ml_get(*lnump);
+ }
+ if (retval) {
+ *amount = candidate_amount;
+ }
return retval;
}
@@ -1994,10 +2002,12 @@ int get_c_indent(void)
amount = -1;
for (lnum = cur_curpos.lnum - 1; lnum > our_paren_pos.lnum; --lnum) {
l = skipwhite(ml_get(lnum));
- if (cin_nocode(l)) /* skip comment lines */
+ if (cin_nocode(l)) { // skip comment lines
continue;
- if (cin_ispreproc_cont(&l, &lnum))
- continue; /* ignore #define, #if, etc. */
+ }
+ if (cin_ispreproc_cont(&l, &lnum, &amount)) {
+ continue; // ignore #define, #if, etc.
+ }
curwin->w_cursor.lnum = lnum;
/* Skip a comment or raw string. XXX */
@@ -2353,15 +2363,14 @@ int get_c_indent(void)
* up with it.
*/
if (curwin->w_cursor.lnum <= ourscope) {
- /* we reached end of scope:
- * if looking for an 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,
- * here; <-- add ind_continuation
- */
+ // 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,
+ // here; <-- add ind_continuation
if (lookfor == LOOKFOR_ENUM_OR_INIT) {
if (curwin->w_cursor.lnum == 0
|| curwin->w_cursor.lnum
@@ -2389,11 +2398,12 @@ int get_c_indent(void)
continue;
}
- /*
- * Skip preprocessor directives and blank lines.
- */
- if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum))
+ //
+ // Skip preprocessor directives and blank lines.
+ //
+ if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)) {
continue;
+ }
if (cin_nocode(l))
continue;
@@ -2497,9 +2507,10 @@ int get_c_indent(void)
continue;
}
- /* Skip preprocessor directives and blank lines. */
- if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum))
+ // Skip preprocessor directives and blank lines.
+ if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)) {
continue;
+ }
/* Finally the actual check for "namespace". */
if (cin_is_cpp_namespace(l)) {
@@ -2662,9 +2673,10 @@ int get_c_indent(void)
* unlocked it)
*/
l = get_cursor_line_ptr();
- if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)
- || cin_nocode(l))
+ if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)
+ || cin_nocode(l)) {
continue;
+ }
/*
* Are we at the start of a cpp base class declaration or
@@ -3309,11 +3321,12 @@ term_again:
break;
}
- /*
- * Skip preprocessor directives and blank lines.
- */
- if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum))
+ //
+ // Skip preprocessor directives and blank lines.
+ //
+ if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)) {
continue;
+ }
if (cin_nocode(l))
continue;
@@ -3405,9 +3418,10 @@ term_again:
while (curwin->w_cursor.lnum > 1) {
look = ml_get(--curwin->w_cursor.lnum);
- if (!(cin_nocode(look) || cin_ispreproc_cont(
- &look, &curwin->w_cursor.lnum)))
+ if (!(cin_nocode(look)
+ || cin_ispreproc_cont(&look, &curwin->w_cursor.lnum, &amount))) {
break;
+ }
}
if (curwin->w_cursor.lnum > 0
&& cin_ends_in(look, (char_u *)"}", NULL))