aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohan Klokkhammer Helsing <johanhelsing@gmail.com>2015-11-16 20:59:26 +0100
committerJohan Klokkhammer Helsing <johanhelsing@gmail.com>2015-12-13 11:55:37 +0100
commit123361f187778785aac112a7f34ed7a95e7239b9 (patch)
treeb55af1f6c9d6a17e8516e389796fd63fb769c23e /src
parent8a34d21b0d8e06edfbe02d47e4f045e0e97c996e (diff)
downloadrneovim-123361f187778785aac112a7f34ed7a95e7239b9.tar.gz
rneovim-123361f187778785aac112a7f34ed7a95e7239b9.tar.bz2
rneovim-123361f187778785aac112a7f34ed7a95e7239b9.zip
vim-patch:7.4.670
Problem: Using 'cindent' for Javascript is less than perfect. Solution: Improve indenting of continuation lines. (Hirohito Higashi) https://github.com/vim/vim/commit/dcefba993456263100785f18d21d780cf531f2dc
Diffstat (limited to 'src')
-rw-r--r--src/nvim/indent_c.c73
-rw-r--r--src/nvim/version.c2
2 files changed, 55 insertions, 20 deletions
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index d62e7aad03..da068478be 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -1237,18 +1237,36 @@ static pos_T * find_match_char(char_u c, int ind_maxparen)
pos_T cursor_save;
pos_T *trypos;
static pos_T pos_copy;
+ int ind_maxp_wk;
cursor_save = curwin->w_cursor;
- if ((trypos = findmatchlimit(NULL, c, 0, ind_maxparen)) != NULL) {
- /* check if the ( is in a // comment */
- if ((colnr_T)cin_skip2pos(trypos) > trypos->col)
+ ind_maxp_wk = ind_maxparen;
+retry:
+ if ((trypos = findmatchlimit(NULL, c, 0, ind_maxp_wk)) != NULL) {
+ // check if the ( is in a // comment
+ if ((colnr_T)cin_skip2pos(trypos) > trypos->col) {
+ ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum - trypos->lnum);
+ if (ind_maxp_wk > 0) {
+ curwin->w_cursor = *trypos;
+ curwin->w_cursor.col = 0; // XXX
+ goto retry;
+ }
trypos = NULL;
- else {
+ } else {
+ pos_T *trypos_wk;
+
pos_copy = *trypos; /* copy trypos, findmatch will change it */
trypos = &pos_copy;
curwin->w_cursor = *trypos;
- if (ind_find_start_comment() != NULL)
+ if ((trypos_wk = ind_find_start_comment()) != NULL) { /* XXX */
+ ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum
+ - trypos_wk->lnum);
+ if (ind_maxp_wk > 0) {
+ curwin->w_cursor = *trypos_wk;
+ goto retry;
+ }
trypos = NULL;
+ }
}
}
curwin->w_cursor = cursor_save;
@@ -1567,7 +1585,7 @@ int get_c_indent(void)
#define LOOKFOR_CPP_BASECLASS 9
#define LOOKFOR_ENUM_OR_INIT 10
#define LOOKFOR_JS_KEY 11
-#define LOOKFOR_NO_COMMA 12
+#define LOOKFOR_COMMA 12
int whilelevel;
linenr_T lnum;
@@ -2286,7 +2304,8 @@ int get_c_indent(void)
amount += ind_continuation;
} else {
if (lookfor != LOOKFOR_TERM
- && lookfor != LOOKFOR_CPP_BASECLASS) {
+ && lookfor != LOOKFOR_CPP_BASECLASS
+ && lookfor != LOOKFOR_COMMA) {
amount = scope_amount;
if (theline[0] == '{') {
amount += curbuf->b_ind_open_extra;
@@ -2550,23 +2569,31 @@ int get_c_indent(void)
amount = get_indent();
break;
}
- if (lookfor == LOOKFOR_NO_COMMA) {
- if (terminated != ',') {
- // Line below current line is the one that starts a
- // (possibly broken) line ending in a comma.
+ if (lookfor == LOOKFOR_COMMA) {
+ if (tryposBrace != NULL && tryposBrace->lnum
+ >= curwin->w_cursor.lnum) {
break;
}
- amount = get_indent();
- if (curwin->w_cursor.lnum - 1 == ourscope) {
- // line above is start of the scope, thus current line
- // is the one that stars a (possibly broken) line
- // ending in a comma.
+ if (terminated == ',') {
+ // Line below current line is the one that starts a
+ // (possibly broken) line ending in a comma.
break;
+ } else {
+ amount = get_indent();
+ if (curwin->w_cursor.lnum - 1 == ourscope) {
+ // line above is start of the scope, thus current
+ // line is the one that stars a (possibly broken)
+ // line ending in a comma.
+ break;
+ }
}
}
if (terminated == 0 || (lookfor != LOOKFOR_UNTERM
&& terminated == ',')) {
+ if (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '[') {
+ amount += ind_continuation;
+ }
// If we're in the middle of a paren thing, Go back to the line
// that starts it so we can get the right prevailing indent
// if ( foo &&
@@ -2783,7 +2810,11 @@ int get_c_indent(void)
* 100 +
* -> here;
*/
+ l = get_cursor_line_ptr();
amount = cur_amount;
+ if (*skipwhite(l) == ']' || l[STRLEN(l) - 1] == ']') {
+ break;
+ }
/*
* If previous line ends in ',', check whether we
@@ -2809,8 +2840,10 @@ int get_c_indent(void)
// 4 *
// 5,
// 6,
- lookfor = LOOKFOR_NO_COMMA;
- amount = get_indent(); // XXX
+ if (cin_iscomment(skipwhite(l))) {
+ break;
+ }
+ lookfor = LOOKFOR_COMMA;
trypos = find_match_char('[', curbuf->b_ind_maxparen);
if (trypos != NULL) {
if (trypos->lnum == curwin->w_cursor.lnum - 1) {
@@ -2831,7 +2864,9 @@ int get_c_indent(void)
// XXX
cont_amount = cin_get_equal_amount( curwin->w_cursor.lnum);
}
- if (lookfor != LOOKFOR_TERM && lookfor != LOOKFOR_JS_KEY) {
+ if (lookfor != LOOKFOR_TERM
+ && lookfor != LOOKFOR_JS_KEY
+ && lookfor != LOOKFOR_COMMA) {
lookfor = LOOKFOR_UNTERM;
}
}
diff --git a/src/nvim/version.c b/src/nvim/version.c
index c340211b02..2d66b06f48 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -323,7 +323,7 @@ static int included_patches[] = {
673,
// 672,
// 671,
- // 670,
+ 670,
// 669 NA
668,
667,