mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #3623 'vim-patch:7.4.{670,723,803}'
This commit is contained in:
commit
77c0f9a62b
@ -6584,9 +6584,14 @@ static int cindent_on(void) {
|
||||
*/
|
||||
void fixthisline(IndentGetter get_the_indent)
|
||||
{
|
||||
change_indent(INDENT_SET, get_the_indent(), FALSE, 0, TRUE);
|
||||
if (linewhite(curwin->w_cursor.lnum))
|
||||
did_ai = TRUE; /* delete the indent if the line stays empty */
|
||||
int amount = get_the_indent();
|
||||
|
||||
if (amount >= 0) {
|
||||
change_indent(INDENT_SET, amount, false, 0, true);
|
||||
if (linewhite(curwin->w_cursor.lnum)) {
|
||||
did_ai = true; // delete the indent if the line stays empty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void fix_indent(void) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -554,7 +554,7 @@ void op_reindent(oparg_T *oap, Indenter how)
|
||||
{
|
||||
long i;
|
||||
char_u *l;
|
||||
int count;
|
||||
int amount;
|
||||
linenr_T first_changed = 0;
|
||||
linenr_T last_changed = 0;
|
||||
linenr_T start_lnum = curwin->w_cursor.lnum;
|
||||
@ -582,11 +582,11 @@ void op_reindent(oparg_T *oap, Indenter how)
|
||||
|| how != get_lisp_indent) {
|
||||
l = skipwhite(get_cursor_line_ptr());
|
||||
if (*l == NUL) /* empty or blank line */
|
||||
count = 0;
|
||||
amount = 0;
|
||||
else
|
||||
count = how(); /* get the indent for this line */
|
||||
amount = how(); /* get the indent for this line */
|
||||
|
||||
if (set_indent(count, SIN_UNDO)) {
|
||||
if (amount >= 0 && set_indent(amount, SIN_UNDO)) {
|
||||
/* did change the indent, call changed_lines() later */
|
||||
if (first_changed == 0)
|
||||
first_changed = curwin->w_cursor.lnum;
|
||||
|
@ -1442,20 +1442,65 @@ static int check_prevcol(char_u *linep, int col, int ch, int *prevcol)
|
||||
return (col >= 0 && linep[col] == ch) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Raw string start is found at linep[startpos.col - 1].
|
||||
* Return true if the matching end can be found between startpos and endpos.
|
||||
*/
|
||||
static int find_rawstring_end(char_u *linep, pos_T *startpos, pos_T *endpos)
|
||||
{
|
||||
char_u *p;
|
||||
char_u *delim_copy;
|
||||
size_t delim_len;
|
||||
linenr_T lnum;
|
||||
int found = false;
|
||||
|
||||
for (p = linep + startpos->col + 1; *p && *p != '('; ++p) {}
|
||||
|
||||
delim_len = (p - linep) - startpos->col - 1;
|
||||
delim_copy = vim_strnsave(linep + startpos->col + 1, delim_len);
|
||||
if (delim_copy == NULL)
|
||||
return false;
|
||||
for (lnum = startpos->lnum; lnum <= endpos->lnum; ++lnum)
|
||||
{
|
||||
char_u *line = ml_get(lnum);
|
||||
|
||||
for (p = line + (lnum == startpos->lnum
|
||||
? startpos->col + 1 : 0); *p; ++p)
|
||||
{
|
||||
if (lnum == endpos->lnum && (colnr_T)(p - line) >= endpos->col)
|
||||
break;
|
||||
if (*p == ')' && p[delim_len + 1] == '"'
|
||||
&& STRNCMP(delim_copy, p + 1, delim_len) == 0)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
xfree(delim_copy);
|
||||
return found;
|
||||
}
|
||||
|
||||
/*
|
||||
* findmatchlimit -- find the matching paren or brace, if it exists within
|
||||
* maxtravel lines of here. A maxtravel of 0 means search until falling off
|
||||
* the edge of the file.
|
||||
* maxtravel lines of the cursor. A maxtravel of 0 means search until falling
|
||||
* off the edge of the file.
|
||||
*
|
||||
* "initc" is the character to find a match for. NUL means to find the
|
||||
* character at or after the cursor.
|
||||
* character at or after the cursor. Special values:
|
||||
* '*' look for C-style comment / *
|
||||
* '/' look for C-style comment / *, ignoring comment-end
|
||||
* '#' look for preprocessor directives
|
||||
* 'R' look for raw string start: R"delim(text)delim" (only backwards)
|
||||
*
|
||||
* flags: FM_BACKWARD search backwards (when initc is '/', '*' or '#')
|
||||
* FM_FORWARD search forwards (when initc is '/', '*' or '#')
|
||||
* FM_BLOCKSTOP stop at start/end of block ({ or } in column 0)
|
||||
* FM_SKIPCOMM skip comments (not implemented yet!)
|
||||
*
|
||||
* "oap" is only used to set oap->motion_type for a linewise motion, it be
|
||||
* "oap" is only used to set oap->motion_type for a linewise motion, it can be
|
||||
* NULL
|
||||
*/
|
||||
|
||||
@ -1465,8 +1510,9 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
|
||||
int findc = 0; /* matching brace */
|
||||
int c;
|
||||
int count = 0; /* cumulative number of braces */
|
||||
int backwards = FALSE; /* init for gcc */
|
||||
int inquote = FALSE; /* TRUE when inside quotes */
|
||||
int backwards = false; /* init for gcc */
|
||||
int raw_string = false; /* search for raw string */
|
||||
int inquote = false; /* true when inside quotes */
|
||||
char_u *linep; /* pointer to current line */
|
||||
char_u *ptr;
|
||||
int do_quotes; /* check for quotes in current line */
|
||||
@ -1506,22 +1552,22 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
|
||||
* When '/' is used, we ignore running backwards into a star-slash, for
|
||||
* "[*" command, we just want to find any comment.
|
||||
*/
|
||||
if (initc == '/' || initc == '*') {
|
||||
if (initc == '/' || initc == '*' || initc == 'R') {
|
||||
comment_dir = dir;
|
||||
if (initc == '/')
|
||||
ignore_cend = TRUE;
|
||||
backwards = (dir == FORWARD) ? FALSE : TRUE;
|
||||
ignore_cend = true;
|
||||
backwards = (dir == FORWARD) ? false : true;
|
||||
raw_string = (initc == 'R');
|
||||
initc = NUL;
|
||||
} else if (initc != '#' && initc != NUL) {
|
||||
find_mps_values(&initc, &findc, &backwards, TRUE);
|
||||
if (findc == NUL)
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
* Either initc is '#', or no initc was given and we need to look under the
|
||||
* cursor.
|
||||
*/
|
||||
else {
|
||||
} else {
|
||||
/*
|
||||
* Either initc is '#', or no initc was given and we need to look
|
||||
* under the cursor.
|
||||
*/
|
||||
if (initc == '#') {
|
||||
hash_dir = dir;
|
||||
} else {
|
||||
@ -1766,7 +1812,26 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
|
||||
*/
|
||||
if (pos.col == 0)
|
||||
continue;
|
||||
else if ( linep[pos.col - 1] == '/'
|
||||
else if (raw_string)
|
||||
{
|
||||
if (linep[pos.col - 1] == 'R'
|
||||
&& linep[pos.col] == '"'
|
||||
&& vim_strchr(linep + pos.col + 1, '(') != NULL)
|
||||
{
|
||||
/* Possible start of raw string. Now that we have the
|
||||
* delimiter we can check if it ends before where we
|
||||
* started searching, or before the previously found
|
||||
* raw string start. */
|
||||
if (!find_rawstring_end(linep, &pos,
|
||||
count > 0 ? &match_pos : &curwin->w_cursor))
|
||||
{
|
||||
count++;
|
||||
match_pos = pos;
|
||||
match_pos.col--;
|
||||
}
|
||||
linep = ml_get(pos.lnum); /* may have been released */
|
||||
}
|
||||
} else if ( linep[pos.col - 1] == '/'
|
||||
&& linep[pos.col] == '*'
|
||||
&& (int)pos.col < comment_col) {
|
||||
count++;
|
||||
|
@ -190,7 +190,7 @@ static int included_patches[] = {
|
||||
// 806,
|
||||
// 805,
|
||||
// 804,
|
||||
// 803,
|
||||
803,
|
||||
802,
|
||||
// 801,
|
||||
// 800,
|
||||
@ -270,7 +270,7 @@ static int included_patches[] = {
|
||||
// 726 NA
|
||||
// 725,
|
||||
// 724 NA
|
||||
// 723,
|
||||
723,
|
||||
// 722,
|
||||
// 721,
|
||||
// 720 NA
|
||||
@ -323,7 +323,7 @@ static int included_patches[] = {
|
||||
673,
|
||||
// 672,
|
||||
// 671,
|
||||
// 670,
|
||||
670,
|
||||
// 669 NA
|
||||
668,
|
||||
667,
|
||||
|
@ -901,6 +901,23 @@ describe('cindent', function()
|
||||
{
|
||||
111111111111111111;
|
||||
}
|
||||
void getstring() {
|
||||
/* Raw strings */
|
||||
const char* s = R"(
|
||||
test {
|
||||
# comment
|
||||
field: 123
|
||||
}
|
||||
)";
|
||||
}
|
||||
void getstring() {
|
||||
const char* s = R"foo(
|
||||
test {
|
||||
# comment
|
||||
field: 123
|
||||
}
|
||||
)foo";
|
||||
}
|
||||
|
||||
/* end of AUTO */
|
||||
]=])
|
||||
@ -1790,6 +1807,23 @@ describe('cindent', function()
|
||||
{
|
||||
111111111111111111;
|
||||
}
|
||||
void getstring() {
|
||||
/* Raw strings */
|
||||
const char* s = R"(
|
||||
test {
|
||||
# comment
|
||||
field: 123
|
||||
}
|
||||
)";
|
||||
}
|
||||
void getstring() {
|
||||
const char* s = R"foo(
|
||||
test {
|
||||
# comment
|
||||
field: 123
|
||||
}
|
||||
)foo";
|
||||
}
|
||||
|
||||
/* end of AUTO */
|
||||
]=])
|
||||
@ -4213,4 +4247,321 @@ describe('cindent', function()
|
||||
JSEND
|
||||
]=])
|
||||
end)
|
||||
|
||||
it('javascript indent / vim-patch 7.4.670', 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)
|
||||
|
Loading…
Reference in New Issue
Block a user