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.c203
1 files changed, 102 insertions, 101 deletions
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index 82f9194fa7..6648a9f7c6 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -233,9 +233,7 @@ static int cin_islabel_skip(char_u **s)
*/
int cin_islabel(void)
{ /* XXX */
- char_u *s;
-
- s = cin_skipcomment(get_cursor_line_ptr());
+ char_u *s = cin_skipcomment(get_cursor_line_ptr());
/*
* Exclude "default" from labels, since it should be indented
@@ -246,44 +244,45 @@ int cin_islabel(void)
if (cin_isscopedecl(s))
return FALSE;
- if (cin_islabel_skip(&s)) {
- /*
- * Only accept a label if the previous line is terminated or is a case
- * label.
- */
- pos_T cursor_save;
- pos_T *trypos;
- char_u *line;
+ if (!cin_islabel_skip(&s)) {
+ return FALSE;
+ }
- cursor_save = curwin->w_cursor;
- while (curwin->w_cursor.lnum > 1) {
- --curwin->w_cursor.lnum;
+ /*
+ * Only accept a label if the previous line is terminated or is a case
+ * label.
+ */
+ pos_T cursor_save;
+ pos_T *trypos;
+ char_u *line;
- /*
- * If we're in a comment now, skip to the start of the comment.
- */
- curwin->w_cursor.col = 0;
- if ((trypos = ind_find_start_comment()) != NULL) /* XXX */
- curwin->w_cursor = *trypos;
+ cursor_save = curwin->w_cursor;
+ while (curwin->w_cursor.lnum > 1) {
+ --curwin->w_cursor.lnum;
- line = get_cursor_line_ptr();
- if (cin_ispreproc(line)) /* ignore #defines, #if, etc. */
- continue;
- if (*(line = cin_skipcomment(line)) == NUL)
- continue;
+ /*
+ * If we're in a comment now, skip to the start of the comment.
+ */
+ curwin->w_cursor.col = 0;
+ if ((trypos = ind_find_start_comment()) != NULL) /* XXX */
+ curwin->w_cursor = *trypos;
+
+ line = get_cursor_line_ptr();
+ if (cin_ispreproc(line)) /* ignore #defines, #if, etc. */
+ continue;
+ if (*(line = cin_skipcomment(line)) == NUL)
+ continue;
- curwin->w_cursor = cursor_save;
- if (cin_isterminated(line, TRUE, FALSE)
- || cin_isscopedecl(line)
- || cin_iscase(line, TRUE)
- || (cin_islabel_skip(&line) && cin_nocode(line)))
- return TRUE;
- return FALSE;
- }
curwin->w_cursor = cursor_save;
- return TRUE; /* label at start of file??? */
+ if (cin_isterminated(line, TRUE, FALSE)
+ || cin_isscopedecl(line)
+ || cin_iscase(line, TRUE)
+ || (cin_islabel_skip(&line) && cin_nocode(line)))
+ return TRUE;
+ return FALSE;
}
- return FALSE;
+ curwin->w_cursor = cursor_save;
+ return TRUE; /* label at start of file??? */
}
/*
@@ -3200,80 +3199,82 @@ static int find_match(int lookfor, linenr_T ourscope)
curwin->w_cursor.col = 0;
look = cin_skipcomment(get_cursor_line_ptr());
- if (cin_iselse(look)
- || cin_isif(look)
- || cin_isdo(look) /* XXX */
- || cin_iswhileofdo(look, curwin->w_cursor.lnum)) {
- /*
- * if we've gone outside the braces entirely,
- * we must be out of scope...
- */
- theirscope = find_start_brace(); /* XXX */
- if (theirscope == NULL)
- break;
-
- /*
- * and if the brace enclosing this is further
- * back than the one enclosing the else, we're
- * out of luck too.
- */
- if (theirscope->lnum < ourscope)
- break;
+ if (!cin_iselse(look)
+ && !cin_isif(look)
+ && !cin_isdo(look) /* XXX */
+ && !cin_iswhileofdo(look, curwin->w_cursor.lnum)) {
+ continue;
+ }
- /*
- * and if they're enclosed in a *deeper* brace,
- * then we can ignore it because it's in a
- * different scope...
- */
- if (theirscope->lnum > ourscope)
- continue;
+ /*
+ * if we've gone outside the braces entirely,
+ * we must be out of scope...
+ */
+ theirscope = find_start_brace(); /* XXX */
+ if (theirscope == NULL)
+ break;
- /*
- * if it was an "else" (that's not an "else if")
- * then we need to go back to another if, so
- * increment elselevel
- */
- look = cin_skipcomment(get_cursor_line_ptr());
- if (cin_iselse(look)) {
- mightbeif = cin_skipcomment(look + 4);
- if (!cin_isif(mightbeif))
- ++elselevel;
- continue;
- }
+ /*
+ * and if the brace enclosing this is further
+ * back than the one enclosing the else, we're
+ * out of luck too.
+ */
+ if (theirscope->lnum < ourscope)
+ break;
- /*
- * if it was a "while" then we need to go back to
- * another "do", so increment whilelevel. XXX
- */
- if (cin_iswhileofdo(look, curwin->w_cursor.lnum)) {
- ++whilelevel;
- continue;
- }
+ /*
+ * and if they're enclosed in a *deeper* brace,
+ * then we can ignore it because it's in a
+ * different scope...
+ */
+ if (theirscope->lnum > ourscope)
+ continue;
- /* If it's an "if" decrement elselevel */
- look = cin_skipcomment(get_cursor_line_ptr());
- if (cin_isif(look)) {
- elselevel--;
- /*
- * When looking for an "if" ignore "while"s that
- * get in the way.
- */
- if (elselevel == 0 && lookfor == LOOKFOR_IF)
- whilelevel = 0;
- }
+ /*
+ * if it was an "else" (that's not an "else if")
+ * then we need to go back to another if, so
+ * increment elselevel
+ */
+ look = cin_skipcomment(get_cursor_line_ptr());
+ if (cin_iselse(look)) {
+ mightbeif = cin_skipcomment(look + 4);
+ if (!cin_isif(mightbeif))
+ ++elselevel;
+ continue;
+ }
- /* If it's a "do" decrement whilelevel */
- if (cin_isdo(look))
- whilelevel--;
+ /*
+ * if it was a "while" then we need to go back to
+ * another "do", so increment whilelevel. XXX
+ */
+ if (cin_iswhileofdo(look, curwin->w_cursor.lnum)) {
+ ++whilelevel;
+ continue;
+ }
+ /* If it's an "if" decrement elselevel */
+ look = cin_skipcomment(get_cursor_line_ptr());
+ if (cin_isif(look)) {
+ elselevel--;
/*
- * if we've used up all the elses, then
- * this must be the if that we want!
- * match the indent level of that if.
+ * When looking for an "if" ignore "while"s that
+ * get in the way.
*/
- if (elselevel <= 0 && whilelevel <= 0) {
- return OK;
- }
+ if (elselevel == 0 && lookfor == LOOKFOR_IF)
+ whilelevel = 0;
+ }
+
+ /* If it's a "do" decrement whilelevel */
+ if (cin_isdo(look))
+ whilelevel--;
+
+ /*
+ * if we've used up all the elses, then
+ * this must be the if that we want!
+ * match the indent level of that if.
+ */
+ if (elselevel <= 0 && whilelevel <= 0) {
+ return OK;
}
}
return FAIL;