diff options
author | Bram Moolenaar <Bram@vim.org> | 2015-03-20 19:06:06 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2015-03-20 19:06:06 +0100 |
commit | dcefba993456263100785f18d21d780cf531f2dc (patch) | |
tree | e49c2f941f0b18b30195d0be08bf6ade5c7683a5 /src/misc1.c | |
parent | 3b7b83649cd9c486afd6fbdb33e4450616c4bd46 (diff) | |
download | vim-git-dcefba993456263100785f18d21d780cf531f2dc.tar.gz |
updated for version 7.4.670v7.4.670
Problem: Using 'cindent' for Javascript is less than perfect.
Solution: Improve indenting of continuation lines. (Hirohito Higashi)
Diffstat (limited to 'src/misc1.c')
-rw-r--r-- | src/misc1.c | 67 |
1 files changed, 52 insertions, 15 deletions
diff --git a/src/misc1.c b/src/misc1.c index ac87ef8fc..940a3e917 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -6670,20 +6670,43 @@ find_match_char(c, ind_maxparen) /* XXX */ 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) + 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 { + 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) /* XXX */ + 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; @@ -7024,7 +7047,7 @@ get_c_indent() #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; @@ -7842,7 +7865,8 @@ get_c_indent() else { if (lookfor != LOOKFOR_TERM - && lookfor != LOOKFOR_CPP_BASECLASS) + && lookfor != LOOKFOR_CPP_BASECLASS + && lookfor != LOOKFOR_COMMA) { amount = scope_amount; if (theline[0] == '{') @@ -8134,23 +8158,31 @@ get_c_indent() amount = get_indent(); break; } - if (lookfor == LOOKFOR_NO_COMMA) + if (lookfor == LOOKFOR_COMMA) { - if (terminated != ',') + if (tryposBrace != NULL && tryposBrace->lnum + >= curwin->w_cursor.lnum) + break; + if (terminated == ',') /* line below current line is the one that starts a * (possibly broken) line ending in a comma. */ 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. */ - 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 @@ -8389,7 +8421,10 @@ get_c_indent() * 100 + * -> here; */ + l = ml_get_curline(); amount = cur_amount; + if (*skipwhite(l) == ']' || l[STRLEN(l) - 1] == ']') + break; /* * If previous line ends in ',', check whether we @@ -8418,8 +8453,9 @@ get_c_indent() * 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) @@ -8449,7 +8485,8 @@ get_c_indent() cont_amount = cin_get_equal_amount( curwin->w_cursor.lnum); if (lookfor != LOOKFOR_TERM - && lookfor != LOOKFOR_JS_KEY) + && lookfor != LOOKFOR_JS_KEY + && lookfor != LOOKFOR_COMMA) lookfor = LOOKFOR_UNTERM; } } |