mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:7.4.670
Problem: Using 'cindent' for Javascript is less than perfect.
Solution: Improve indenting of continuation lines. (Hirohito Higashi)
dcefba9934
This commit is contained in:
parent
8a34d21b0d
commit
123361f187
@ -1237,18 +1237,36 @@ static pos_T * find_match_char(char_u c, int ind_maxparen)
|
|||||||
pos_T cursor_save;
|
pos_T cursor_save;
|
||||||
pos_T *trypos;
|
pos_T *trypos;
|
||||||
static pos_T pos_copy;
|
static pos_T pos_copy;
|
||||||
|
int ind_maxp_wk;
|
||||||
|
|
||||||
cursor_save = curwin->w_cursor;
|
cursor_save = curwin->w_cursor;
|
||||||
if ((trypos = findmatchlimit(NULL, c, 0, ind_maxparen)) != NULL) {
|
ind_maxp_wk = ind_maxparen;
|
||||||
/* check if the ( is in a // comment */
|
retry:
|
||||||
if ((colnr_T)cin_skip2pos(trypos) > trypos->col)
|
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;
|
trypos = NULL;
|
||||||
else {
|
} else {
|
||||||
|
pos_T *trypos_wk;
|
||||||
|
|
||||||
pos_copy = *trypos; /* copy trypos, findmatch will change it */
|
pos_copy = *trypos; /* copy trypos, findmatch will change it */
|
||||||
trypos = &pos_copy;
|
trypos = &pos_copy;
|
||||||
curwin->w_cursor = *trypos;
|
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;
|
trypos = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
curwin->w_cursor = cursor_save;
|
curwin->w_cursor = cursor_save;
|
||||||
@ -1567,7 +1585,7 @@ int get_c_indent(void)
|
|||||||
#define LOOKFOR_CPP_BASECLASS 9
|
#define LOOKFOR_CPP_BASECLASS 9
|
||||||
#define LOOKFOR_ENUM_OR_INIT 10
|
#define LOOKFOR_ENUM_OR_INIT 10
|
||||||
#define LOOKFOR_JS_KEY 11
|
#define LOOKFOR_JS_KEY 11
|
||||||
#define LOOKFOR_NO_COMMA 12
|
#define LOOKFOR_COMMA 12
|
||||||
|
|
||||||
int whilelevel;
|
int whilelevel;
|
||||||
linenr_T lnum;
|
linenr_T lnum;
|
||||||
@ -2286,7 +2304,8 @@ int get_c_indent(void)
|
|||||||
amount += ind_continuation;
|
amount += ind_continuation;
|
||||||
} else {
|
} else {
|
||||||
if (lookfor != LOOKFOR_TERM
|
if (lookfor != LOOKFOR_TERM
|
||||||
&& lookfor != LOOKFOR_CPP_BASECLASS) {
|
&& lookfor != LOOKFOR_CPP_BASECLASS
|
||||||
|
&& lookfor != LOOKFOR_COMMA) {
|
||||||
amount = scope_amount;
|
amount = scope_amount;
|
||||||
if (theline[0] == '{') {
|
if (theline[0] == '{') {
|
||||||
amount += curbuf->b_ind_open_extra;
|
amount += curbuf->b_ind_open_extra;
|
||||||
@ -2550,23 +2569,31 @@ int get_c_indent(void)
|
|||||||
amount = get_indent();
|
amount = get_indent();
|
||||||
break;
|
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
|
// Line below current line is the one that starts a
|
||||||
// (possibly broken) line ending in a comma.
|
// (possibly broken) line ending in a comma.
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
amount = get_indent();
|
amount = get_indent();
|
||||||
if (curwin->w_cursor.lnum - 1 == ourscope) {
|
if (curwin->w_cursor.lnum - 1 == ourscope) {
|
||||||
// line above is start of the scope, thus current line
|
// line above is start of the scope, thus current
|
||||||
// is the one that stars a (possibly broken) line
|
// line is the one that stars a (possibly broken)
|
||||||
// ending in a comma.
|
// line ending in a comma.
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (terminated == 0 || (lookfor != LOOKFOR_UNTERM
|
if (terminated == 0 || (lookfor != LOOKFOR_UNTERM
|
||||||
&& terminated == ',')) {
|
&& 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
|
// 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
|
// that starts it so we can get the right prevailing indent
|
||||||
// if ( foo &&
|
// if ( foo &&
|
||||||
@ -2783,7 +2810,11 @@ int get_c_indent(void)
|
|||||||
* 100 +
|
* 100 +
|
||||||
* -> here;
|
* -> here;
|
||||||
*/
|
*/
|
||||||
|
l = get_cursor_line_ptr();
|
||||||
amount = cur_amount;
|
amount = cur_amount;
|
||||||
|
if (*skipwhite(l) == ']' || l[STRLEN(l) - 1] == ']') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If previous line ends in ',', check whether we
|
* If previous line ends in ',', check whether we
|
||||||
@ -2809,8 +2840,10 @@ int get_c_indent(void)
|
|||||||
// 4 *
|
// 4 *
|
||||||
// 5,
|
// 5,
|
||||||
// 6,
|
// 6,
|
||||||
lookfor = LOOKFOR_NO_COMMA;
|
if (cin_iscomment(skipwhite(l))) {
|
||||||
amount = get_indent(); // XXX
|
break;
|
||||||
|
}
|
||||||
|
lookfor = LOOKFOR_COMMA;
|
||||||
trypos = find_match_char('[', curbuf->b_ind_maxparen);
|
trypos = find_match_char('[', curbuf->b_ind_maxparen);
|
||||||
if (trypos != NULL) {
|
if (trypos != NULL) {
|
||||||
if (trypos->lnum == curwin->w_cursor.lnum - 1) {
|
if (trypos->lnum == curwin->w_cursor.lnum - 1) {
|
||||||
@ -2831,7 +2864,9 @@ int get_c_indent(void)
|
|||||||
// XXX
|
// XXX
|
||||||
cont_amount = cin_get_equal_amount( curwin->w_cursor.lnum);
|
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;
|
lookfor = LOOKFOR_UNTERM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,7 +323,7 @@ static int included_patches[] = {
|
|||||||
673,
|
673,
|
||||||
// 672,
|
// 672,
|
||||||
// 671,
|
// 671,
|
||||||
// 670,
|
670,
|
||||||
// 669 NA
|
// 669 NA
|
||||||
668,
|
668,
|
||||||
667,
|
667,
|
||||||
|
@ -4213,4 +4213,321 @@ describe('cindent', function()
|
|||||||
JSEND
|
JSEND
|
||||||
]=])
|
]=])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('54 is working', function()
|
||||||
|
insert_([=[
|
||||||
|
|
||||||
|
JSSTART
|
||||||
|
// Results of JavaScript indent
|
||||||
|
// 1
|
||||||
|
(function(){
|
||||||
|
var a = [
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
'c',
|
||||||
|
'd',
|
||||||
|
'e',
|
||||||
|
'f',
|
||||||
|
'g',
|
||||||
|
'h',
|
||||||
|
'i'
|
||||||
|
];
|
||||||
|
}())
|
||||||
|
|
||||||
|
// 2
|
||||||
|
(function(){
|
||||||
|
var a = [
|
||||||
|
0 +
|
||||||
|
5 *
|
||||||
|
9 *
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
0 +
|
||||||
|
5 *
|
||||||
|
9 *
|
||||||
|
'c',
|
||||||
|
'd',
|
||||||
|
'e',
|
||||||
|
'f',
|
||||||
|
'g',
|
||||||
|
'h',
|
||||||
|
'i'
|
||||||
|
];
|
||||||
|
}())
|
||||||
|
|
||||||
|
// 3
|
||||||
|
(function(){
|
||||||
|
var a = [
|
||||||
|
0 +
|
||||||
|
// comment 1
|
||||||
|
5 *
|
||||||
|
/* comment 2 */
|
||||||
|
9 *
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
0 +
|
||||||
|
5 *
|
||||||
|
9 *
|
||||||
|
'c',
|
||||||
|
'd',
|
||||||
|
'e',
|
||||||
|
'f',
|
||||||
|
'g',
|
||||||
|
'h',
|
||||||
|
'i'
|
||||||
|
];
|
||||||
|
}())
|
||||||
|
|
||||||
|
// 4
|
||||||
|
{
|
||||||
|
var a = [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
];
|
||||||
|
var b;
|
||||||
|
var c;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5
|
||||||
|
{
|
||||||
|
var a = [
|
||||||
|
[
|
||||||
|
0
|
||||||
|
],
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6
|
||||||
|
{
|
||||||
|
var a = [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
],
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7
|
||||||
|
{
|
||||||
|
var a = [
|
||||||
|
// [
|
||||||
|
0,
|
||||||
|
// 1
|
||||||
|
// ],
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8
|
||||||
|
var x = [
|
||||||
|
(function(){
|
||||||
|
var a,
|
||||||
|
b,
|
||||||
|
c,
|
||||||
|
d,
|
||||||
|
e,
|
||||||
|
f,
|
||||||
|
g,
|
||||||
|
h,
|
||||||
|
i;
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
// 9
|
||||||
|
var a = [
|
||||||
|
0 +
|
||||||
|
5 *
|
||||||
|
9 *
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
0 +
|
||||||
|
5 *
|
||||||
|
9 *
|
||||||
|
'c',
|
||||||
|
'd',
|
||||||
|
'e',
|
||||||
|
'f',
|
||||||
|
'g',
|
||||||
|
'h',
|
||||||
|
'i'
|
||||||
|
];
|
||||||
|
|
||||||
|
// 10
|
||||||
|
var a,
|
||||||
|
b,
|
||||||
|
c,
|
||||||
|
d,
|
||||||
|
e,
|
||||||
|
f,
|
||||||
|
g,
|
||||||
|
h,
|
||||||
|
i;
|
||||||
|
JSEND
|
||||||
|
]=])
|
||||||
|
|
||||||
|
-- :set cino=j1,J1,+2
|
||||||
|
execute('set cino=j1,J1,+2')
|
||||||
|
execute('/^JSSTART')
|
||||||
|
feed('=/^JSEND<cr>')
|
||||||
|
|
||||||
|
expect([=[
|
||||||
|
|
||||||
|
JSSTART
|
||||||
|
// Results of JavaScript indent
|
||||||
|
// 1
|
||||||
|
(function(){
|
||||||
|
var a = [
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
'c',
|
||||||
|
'd',
|
||||||
|
'e',
|
||||||
|
'f',
|
||||||
|
'g',
|
||||||
|
'h',
|
||||||
|
'i'
|
||||||
|
];
|
||||||
|
}())
|
||||||
|
|
||||||
|
// 2
|
||||||
|
(function(){
|
||||||
|
var a = [
|
||||||
|
0 +
|
||||||
|
5 *
|
||||||
|
9 *
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
0 +
|
||||||
|
5 *
|
||||||
|
9 *
|
||||||
|
'c',
|
||||||
|
'd',
|
||||||
|
'e',
|
||||||
|
'f',
|
||||||
|
'g',
|
||||||
|
'h',
|
||||||
|
'i'
|
||||||
|
];
|
||||||
|
}())
|
||||||
|
|
||||||
|
// 3
|
||||||
|
(function(){
|
||||||
|
var a = [
|
||||||
|
0 +
|
||||||
|
// comment 1
|
||||||
|
5 *
|
||||||
|
/* comment 2 */
|
||||||
|
9 *
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
0 +
|
||||||
|
5 *
|
||||||
|
9 *
|
||||||
|
'c',
|
||||||
|
'd',
|
||||||
|
'e',
|
||||||
|
'f',
|
||||||
|
'g',
|
||||||
|
'h',
|
||||||
|
'i'
|
||||||
|
];
|
||||||
|
}())
|
||||||
|
|
||||||
|
// 4
|
||||||
|
{
|
||||||
|
var a = [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
];
|
||||||
|
var b;
|
||||||
|
var c;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5
|
||||||
|
{
|
||||||
|
var a = [
|
||||||
|
[
|
||||||
|
0
|
||||||
|
],
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6
|
||||||
|
{
|
||||||
|
var a = [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
],
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7
|
||||||
|
{
|
||||||
|
var a = [
|
||||||
|
// [
|
||||||
|
0,
|
||||||
|
// 1
|
||||||
|
// ],
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8
|
||||||
|
var x = [
|
||||||
|
(function(){
|
||||||
|
var a,
|
||||||
|
b,
|
||||||
|
c,
|
||||||
|
d,
|
||||||
|
e,
|
||||||
|
f,
|
||||||
|
g,
|
||||||
|
h,
|
||||||
|
i;
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
// 9
|
||||||
|
var a = [
|
||||||
|
0 +
|
||||||
|
5 *
|
||||||
|
9 *
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
0 +
|
||||||
|
5 *
|
||||||
|
9 *
|
||||||
|
'c',
|
||||||
|
'd',
|
||||||
|
'e',
|
||||||
|
'f',
|
||||||
|
'g',
|
||||||
|
'h',
|
||||||
|
'i'
|
||||||
|
];
|
||||||
|
|
||||||
|
// 10
|
||||||
|
var a,
|
||||||
|
b,
|
||||||
|
c,
|
||||||
|
d,
|
||||||
|
e,
|
||||||
|
f,
|
||||||
|
g,
|
||||||
|
h,
|
||||||
|
i;
|
||||||
|
JSEND
|
||||||
|
]=])
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user