From 2d5cba630c13d45e8a0125fe87a7c85b878c0b6f Mon Sep 17 00:00:00 2001 From: watiko Date: Mon, 15 Feb 2016 18:28:39 +0900 Subject: vim-patch:7.4.891 Problem: Indentation of array initializer is wrong. Solution: Avoid that calling find_start_rawstring() changes the position returned by find_start_comment(), add a test. (Hirohito Higashi) https://github.com/vim/vim/commit/089af18d1fd0961ff504ee72db0156bbfe509cdf --- src/nvim/indent_c.c | 88 ++++++++++++++++++++++++++++++----------------------- src/nvim/version.c | 2 +- 2 files changed, 51 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 340287499e..7cd8dd62de 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -69,23 +69,33 @@ find_start_comment ( /* XXX */ return pos; } -/* - * Find the start of a comment or raw string, not knowing if we are in a - * comment or raw string right now. - * Search starts at w_cursor.lnum and goes backwards. - * Return NULL when not inside a comment or raw string. - * "CORS" -> Comment Or Raw String - */ +/// Find the start of a comment or raw string, not knowing if we are in a +/// comment or raw string right now. +/// Search starts at w_cursor.lnum and goes backwards. +/// +/// @returns NULL when not inside a comment or raw string. +/// +/// @note "CORS" -> Comment Or Raw String static pos_T *ind_find_start_CORS(void) -{ /* XXX */ - pos_T *comment_pos = find_start_comment(curbuf->b_ind_maxcomment); - pos_T *rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment); - - /* If comment_pos is before rs_pos the raw string is inside the comment. - * If rs_pos is before comment_pos the comment is inside the raw string. */ - if (comment_pos == NULL || (rs_pos != NULL && lt(*rs_pos, *comment_pos))) - return rs_pos; - return comment_pos; +{ + // XXX + static pos_T comment_pos_copy; + + pos_T *comment_pos = find_start_comment(curbuf->b_ind_maxcomment); + if (comment_pos != NULL) { + // Need to make a copy of the static pos in findmatchlimit(), + // calling find_start_rawstring() may change it. + comment_pos_copy = *comment_pos; + comment_pos = &comment_pos_copy; + } + pos_T *rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment); + + // If comment_pos is before rs_pos the raw string is inside the comment. + // If rs_pos is before comment_pos the comment is inside the raw string. + if (comment_pos == NULL || (rs_pos != NULL && lt(*rs_pos, *comment_pos))) { + return rs_pos; + } + return comment_pos; } /* @@ -2707,7 +2717,8 @@ int get_c_indent(void) if (terminated == 0 || (lookfor != LOOKFOR_UNTERM && terminated == ',')) { - if (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '[') { + if (lookfor != LOOKFOR_ENUM_OR_INIT + && (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '[')) { amount += ind_continuation; } // If we're in the middle of a paren thing, Go back to the line @@ -2915,34 +2926,35 @@ int get_c_indent(void) continue; } - /* Ignore unterminated lines in between, but - * reduce indent. */ - if (amount > cur_amount) + // Ignore unterminated lines in between, but + // reduce indent. + if (amount > cur_amount) { amount = cur_amount; + } } else { - /* - * Found first unterminated line on a row, may - * line up with this line, remember its indent - * 100 + - * -> here; - */ + // Found first unterminated line on a row, may + // line up with this line, remember its indent + // 100 + // NOLINT(whitespace/tab) + // -> here; // NOLINT(whitespace/tab) l = get_cursor_line_ptr(); amount = cur_amount; - if (*skipwhite(l) == ']' || l[STRLEN(l) - 1] == ']') { + + n = (int)STRLEN(l); + if (terminated == ',' + && (*skipwhite(l) == ']' + || (n >=2 && l[n - 2] == ']'))) { break; } - /* - * If previous line ends in ',', check whether we - * are in an initialization or enum - * struct xxx = - * { - * sizeof a, - * 124 }; - * or a normal possible continuation line. - * but only, of no other statement has been found - * yet. - */ + // If previous line ends in ',', check whether we + // are in an initialization or enum + // struct xxx = + // { + // sizeof a, + // 124 }; + // or a normal possible continuation line. + // but only, of no other statement has been found + // yet. if (lookfor == LOOKFOR_INITIAL && terminated == ',') { if (curbuf->b_ind_js) { // Search for a line ending in a comma diff --git a/src/nvim/version.c b/src/nvim/version.c index 4de63ebb10..c5781412e7 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -397,7 +397,7 @@ static int included_patches[] = { // 894 NA // 893, // 892, - // 891, + 891, // 890 NA // 889, // 888, -- cgit From 72d5a88af5f417a8312408d85dbb6949f64146b2 Mon Sep 17 00:00:00 2001 From: watiko Date: Mon, 15 Feb 2016 19:12:47 +0900 Subject: vim-patch:7.4.893 Problem: C indenting is wrong below a "case (foo):" because it is recognized as a C++ base class construct. Issue #38. Solution: Check for the case keyword. https://github.com/vim/vim/commit/d1b15dec4d00d7ed5e92ff4e0fb7fc2e0818e479 --- src/nvim/indent_c.c | 14 +++++++++++--- src/nvim/version.c | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 7cd8dd62de..3def0defe3 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -1132,13 +1132,21 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) { pos->lnum = lnum; line = ml_get(lnum); - s = cin_skipcomment(line); + s = line; for (;; ) { if (*s == NUL) { - if (lnum == curwin->w_cursor.lnum) + if (lnum == curwin->w_cursor.lnum) { break; - /* Continue in the cursor line. */ + } + // Continue in the cursor line. line = ml_get(++lnum); + s = line; + } + if (s == line) { + // don't recognize "case (foo):" as a baseclass */ + if (cin_iscase(s, false)) { + break; + } s = cin_skipcomment(line); if (*s == NUL) continue; diff --git a/src/nvim/version.c b/src/nvim/version.c index c5781412e7..5a46049e27 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -395,7 +395,7 @@ static int included_patches[] = { // 896, // 895, // 894 NA - // 893, + 893, // 892, 891, // 890 NA -- cgit From ade2298735a17f8d71ae97fc17fc9059b12b99a1 Mon Sep 17 00:00:00 2001 From: watiko Date: Mon, 15 Feb 2016 20:57:10 +0900 Subject: vim-patch:7.4.912 Problem: Wrong indenting for C++ constructor. Solution: Recognize ::. (Anhong) https://github.com/vim/vim/commit/e01f4f86cef7bed3cb99b26f9f57d86f6eb5fe1a --- src/nvim/indent_c.c | 24 +++++++++++++++++++----- src/nvim/version.c | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 3def0defe3..17fadc4bfd 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -857,13 +857,27 @@ static int cin_isfuncdecl(char_u **sp, linenr_T first_lnum, linenr_T min_lnum) return FALSE; while (*s && *s != '(' && *s != ';' && *s != '\'' && *s != '"') { - if (cin_iscomment(s)) /* ignore comments */ + // ignore comments + if (cin_iscomment(s)) { s = cin_skipcomment(s); - else - ++s; + } else if (*s == ':') { + if (*(s + 1) == ':') { + s += 2; + } else { + // To avoid a mistake in the following situation: + // A::A(int a, int b) + // : a(0) // <--not a function decl + // , b(0) + // {... + return false; + } + } else { + s++; + } + } + if (*s != '(') { + return false; // ';', ' or " before any () or no '(' } - if (*s != '(') - return FALSE; /* ';', ' or " before any () or no '(' */ while (*s && *s != ';' && *s != '\'' && *s != '"') { if (*s == ')' && cin_nocode(s + 1)) { diff --git a/src/nvim/version.c b/src/nvim/version.c index 5a46049e27..c6bb094cf6 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -376,7 +376,7 @@ static int included_patches[] = { 915, // 914, // 913 NA - // 912, + 912, // 911 NA // 910 NA // 909, -- cgit