diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/indent_c.c | 34 | ||||
| -rw-r--r-- | src/nvim/testdir/test3.in | 4 | ||||
| -rw-r--r-- | src/nvim/testdir/test3.ok | 4 | ||||
| -rw-r--r-- | src/nvim/version.c | 2 | 
4 files changed, 38 insertions, 6 deletions
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 5c38a444ad..8ad0a997f1 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -1198,7 +1198,7 @@ static pos_T *find_start_brace(void)    return trypos;  } -/// Find the matching '(', failing if it is in a comment. +/// Find the matching '(', ignoring it if it is in a comment.  /// @returns NULL or the found match.  static pos_T *find_match_paren(int ind_maxparen)  { @@ -1223,6 +1223,29 @@ static pos_T *find_match_paren(int ind_maxparen)    return trypos;  } +/// Find the matching '(', ignoring it if it is in a comment or before an +/// unmatched {. +/// @returns NULL or the found match. +static pos_T *find_match_paren_after_brace(int ind_maxparen) +{ +  pos_T *trypos = find_match_paren(ind_maxparen); +  if (trypos == NULL) { +    return NULL; +  } + +  pos_T *tryposBrace = find_start_brace(); +  // If both an unmatched '(' and '{' is found.  Ignore the '(' +  // position if the '{' is further down. +  if (tryposBrace != NULL +      && (trypos->lnum != tryposBrace->lnum +          ? trypos->lnum < tryposBrace->lnum +          : trypos->col < tryposBrace->col)) { +    trypos = NULL; +  } +  return trypos; +} + +  /*   * Return ind_maxparen corrected for the difference in line number between the   * cursor position and "startpos".  This makes sure that searching for a @@ -1934,13 +1957,14 @@ int get_c_indent(void)            else {              curwin->w_cursor.lnum = our_paren_pos.lnum;              curwin->w_cursor.col = col; -            if (find_match_paren(curbuf->b_ind_maxparen) != NULL) +            if (find_match_paren_after_brace(curbuf->b_ind_maxparen)) {                amount += curbuf->b_ind_unclosed2; -            else { -              if (is_if_for_while) +            } else { +              if (is_if_for_while) {                  amount += curbuf->b_ind_if_for_while; -              else +              } else {                  amount += curbuf->b_ind_unclosed; +              }              }            }            /* diff --git a/src/nvim/testdir/test3.in b/src/nvim/testdir/test3.in index 46e5767062..287ed8e5b3 100644 --- a/src/nvim/testdir/test3.in +++ b/src/nvim/testdir/test3.in @@ -1950,6 +1950,10 @@ ENDTEST  JSSTART  (function($){ +if (cond && +cond) { +stmt; +}  var class_name='myclass';  function private_method() { diff --git a/src/nvim/testdir/test3.ok b/src/nvim/testdir/test3.ok index d73a5e1230..edd9e236a6 100644 --- a/src/nvim/testdir/test3.ok +++ b/src/nvim/testdir/test3.ok @@ -1728,6 +1728,10 @@ JSEND  JSSTART  (function($){ +	if (cond && +			cond) { +		stmt; +	}  	var class_name='myclass';  	function private_method() { diff --git a/src/nvim/version.c b/src/nvim/version.c index 43b759e9fb..0f885cde01 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -387,7 +387,7 @@ static int included_patches[] = {    353,    352,    351, -  //350, +  350,    349,    348,    347,  | 
