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)
|
void fixthisline(IndentGetter get_the_indent)
|
||||||
{
|
{
|
||||||
change_indent(INDENT_SET, get_the_indent(), FALSE, 0, TRUE);
|
int amount = get_the_indent();
|
||||||
if (linewhite(curwin->w_cursor.lnum))
|
|
||||||
did_ai = TRUE; /* delete the indent if the line stays empty */
|
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) {
|
void fix_indent(void) {
|
||||||
|
@ -17,7 +17,11 @@
|
|||||||
#include "nvim/search.h"
|
#include "nvim/search.h"
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
|
|
||||||
|
// Find result cache for cpp_baseclass
|
||||||
|
typedef struct {
|
||||||
|
int found;
|
||||||
|
lpos_T lpos;
|
||||||
|
} cpp_baseclass_cache_T;
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "indent_c.c.generated.h"
|
# include "indent_c.c.generated.h"
|
||||||
@ -25,6 +29,7 @@
|
|||||||
/*
|
/*
|
||||||
* Find the start of a comment, not knowing if we are in a comment right now.
|
* Find the start of a comment, not knowing if we are in a comment right now.
|
||||||
* Search starts at w_cursor.lnum and goes backwards.
|
* Search starts at w_cursor.lnum and goes backwards.
|
||||||
|
* Return NULL when not inside a comment.
|
||||||
*/
|
*/
|
||||||
static pos_T *ind_find_start_comment(void)
|
static pos_T *ind_find_start_comment(void)
|
||||||
{ /* XXX */
|
{ /* XXX */
|
||||||
@ -64,6 +69,62 @@ find_start_comment ( /* XXX */
|
|||||||
return pos;
|
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
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find the start of a raw string, not knowing if we are in one right now.
|
||||||
|
* Search starts at w_cursor.lnum and goes backwards.
|
||||||
|
* Return NULL when not inside a raw string.
|
||||||
|
*/
|
||||||
|
static pos_T *find_start_rawstring(int ind_maxcomment)
|
||||||
|
{ /* XXX */
|
||||||
|
pos_T *pos;
|
||||||
|
char_u *line;
|
||||||
|
char_u *p;
|
||||||
|
long cur_maxcomment = ind_maxcomment;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
pos = findmatchlimit(NULL, 'R', FM_BACKWARD, cur_maxcomment);
|
||||||
|
if (pos == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if the raw string start we found is inside a string.
|
||||||
|
* If it is then restrict the search to below this line and try again.
|
||||||
|
*/
|
||||||
|
line = ml_get(pos->lnum);
|
||||||
|
for (p = line; *p && (colnr_T)(p - line) < pos->col; ++p)
|
||||||
|
p = skip_string(p);
|
||||||
|
if ((colnr_T)(p - line) <= pos->col)
|
||||||
|
break;
|
||||||
|
cur_maxcomment = curwin->w_cursor.lnum - pos->lnum - 1;
|
||||||
|
if (cur_maxcomment <= 0)
|
||||||
|
{
|
||||||
|
pos = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Skip to the end of a "string" and a 'c' character.
|
* Skip to the end of a "string" and a 'c' character.
|
||||||
* If there is no string or character, return argument unmodified.
|
* If there is no string or character, return argument unmodified.
|
||||||
@ -97,7 +158,26 @@ static char_u *skip_string(char_u *p)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (p[0] == '"')
|
if (p[0] == '"')
|
||||||
continue;
|
continue; /* continue for another string */
|
||||||
|
} else if (p[0] == 'R' && p[1] == '"') {
|
||||||
|
/* Raw string: R"[delim](...)[delim]" */
|
||||||
|
char_u *delim = p + 2;
|
||||||
|
char_u *paren = vim_strchr(delim, '(');
|
||||||
|
|
||||||
|
if (paren != NULL)
|
||||||
|
{
|
||||||
|
long delim_len = paren - delim;
|
||||||
|
|
||||||
|
for (p += 3; *p; ++p)
|
||||||
|
if (p[0] == ')' && STRNCMP(p + 1, delim, delim_len) == 0
|
||||||
|
&& p[delim_len + 1] == '"')
|
||||||
|
{
|
||||||
|
p += delim_len + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (p[0] == '"')
|
||||||
|
continue; /* continue for another string */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break; /* no string found */
|
break; /* no string found */
|
||||||
}
|
}
|
||||||
@ -288,10 +368,11 @@ int cin_islabel(void)
|
|||||||
--curwin->w_cursor.lnum;
|
--curwin->w_cursor.lnum;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we're in a comment now, skip to the start of the comment.
|
* If we're in a comment or raw string now, skip to the start of
|
||||||
|
* it.
|
||||||
*/
|
*/
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
if ((trypos = ind_find_start_comment()) != NULL) /* XXX */
|
if ((trypos = ind_find_start_CORS()) != NULL) /* XXX */
|
||||||
curwin->w_cursor = *trypos;
|
curwin->w_cursor = *trypos;
|
||||||
|
|
||||||
line = get_cursor_line_ptr();
|
line = get_cursor_line_ptr();
|
||||||
@ -986,17 +1067,18 @@ static int cin_isbreak(char_u *p)
|
|||||||
*
|
*
|
||||||
* This is a lot of guessing. Watch out for "cond ? func() : foo".
|
* This is a lot of guessing. Watch out for "cond ? func() : foo".
|
||||||
*/
|
*/
|
||||||
static int
|
static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) {
|
||||||
cin_is_cpp_baseclass (
|
lpos_T *pos = &cached->lpos; // find position
|
||||||
colnr_T *col /* return: column to align with */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
char_u *s;
|
char_u *s;
|
||||||
int class_or_struct, lookfor_ctor_init, cpp_base_class;
|
int class_or_struct, lookfor_ctor_init, cpp_base_class;
|
||||||
linenr_T lnum = curwin->w_cursor.lnum;
|
linenr_T lnum = curwin->w_cursor.lnum;
|
||||||
char_u *line = get_cursor_line_ptr();
|
char_u *line = get_cursor_line_ptr();
|
||||||
|
|
||||||
*col = 0;
|
if (pos->lnum <= lnum) {
|
||||||
|
return cached->found; // Use the cached result
|
||||||
|
}
|
||||||
|
|
||||||
|
pos->col = 0;
|
||||||
|
|
||||||
s = skipwhite(line);
|
s = skipwhite(line);
|
||||||
if (*s == '#') /* skip #define FOO x ? (x) : x */
|
if (*s == '#') /* skip #define FOO x ? (x) : x */
|
||||||
@ -1038,6 +1120,7 @@ cin_is_cpp_baseclass (
|
|||||||
--lnum;
|
--lnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pos->lnum = lnum;
|
||||||
line = ml_get(lnum);
|
line = ml_get(lnum);
|
||||||
s = cin_skipcomment(line);
|
s = cin_skipcomment(line);
|
||||||
for (;; ) {
|
for (;; ) {
|
||||||
@ -1051,7 +1134,7 @@ cin_is_cpp_baseclass (
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s[0] == '"')
|
if (s[0] == '"' || (s[0] == 'R' && s[1] == '"'))
|
||||||
s = skip_string(s) + 1;
|
s = skip_string(s) + 1;
|
||||||
else if (s[0] == ':') {
|
else if (s[0] == ':') {
|
||||||
if (s[1] == ':') {
|
if (s[1] == ':') {
|
||||||
@ -1062,9 +1145,9 @@ cin_is_cpp_baseclass (
|
|||||||
} else if (lookfor_ctor_init || class_or_struct) {
|
} else if (lookfor_ctor_init || class_or_struct) {
|
||||||
/* we have something found, that looks like the start of
|
/* we have something found, that looks like the start of
|
||||||
* cpp-base-class-declaration or constructor-initialization */
|
* cpp-base-class-declaration or constructor-initialization */
|
||||||
cpp_base_class = TRUE;
|
cpp_base_class = true;
|
||||||
lookfor_ctor_init = class_or_struct = FALSE;
|
lookfor_ctor_init = class_or_struct = false;
|
||||||
*col = 0;
|
pos->col = 0;
|
||||||
s = cin_skipcomment(s + 1);
|
s = cin_skipcomment(s + 1);
|
||||||
} else
|
} else
|
||||||
s = cin_skipcomment(s + 1);
|
s = cin_skipcomment(s + 1);
|
||||||
@ -1090,25 +1173,31 @@ cin_is_cpp_baseclass (
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
} else if (!vim_isIDc(s[0])) {
|
} else if (!vim_isIDc(s[0])) {
|
||||||
/* if it is not an identifier, we are wrong */
|
/* if it is not an identifier, we are wrong */
|
||||||
class_or_struct = FALSE;
|
class_or_struct = false;
|
||||||
lookfor_ctor_init = FALSE;
|
lookfor_ctor_init = false;
|
||||||
} else if (*col == 0) {
|
} else if (pos->col == 0) {
|
||||||
/* it can't be a constructor-initialization any more */
|
/* it can't be a constructor-initialization any more */
|
||||||
lookfor_ctor_init = FALSE;
|
lookfor_ctor_init = FALSE;
|
||||||
|
|
||||||
/* the first statement starts here: lineup with this one... */
|
/* the first statement starts here: lineup with this one... */
|
||||||
if (cpp_base_class)
|
if (cpp_base_class) {
|
||||||
*col = (colnr_T)(s - line);
|
pos->col = (colnr_T)(s - line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* When the line ends in a comma don't align with it. */
|
/* When the line ends in a comma don't align with it. */
|
||||||
if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode(s + 1))
|
if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode(s + 1)) {
|
||||||
*col = 0;
|
pos->col = 0;
|
||||||
|
}
|
||||||
|
|
||||||
s = cin_skipcomment(s + 1);
|
s = cin_skipcomment(s + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cached->found = cpp_base_class;
|
||||||
|
if (cpp_base_class) {
|
||||||
|
pos->lnum = lnum;
|
||||||
|
}
|
||||||
return cpp_base_class;
|
return cpp_base_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1216,7 +1305,7 @@ static pos_T *find_start_brace(void)
|
|||||||
pos = NULL;
|
pos = NULL;
|
||||||
/* ignore the { if it's in a // or / * * / comment */
|
/* ignore the { if it's in a // or / * * / comment */
|
||||||
if ((colnr_T)cin_skip2pos(trypos) == trypos->col
|
if ((colnr_T)cin_skip2pos(trypos) == trypos->col
|
||||||
&& (pos = ind_find_start_comment()) == NULL) /* XXX */
|
&& (pos = ind_find_start_CORS()) == NULL) /* XXX */
|
||||||
break;
|
break;
|
||||||
if (pos != NULL)
|
if (pos != NULL)
|
||||||
curwin->w_cursor.lnum = pos->lnum;
|
curwin->w_cursor.lnum = pos->lnum;
|
||||||
@ -1237,20 +1326,38 @@ 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_CORS()) != 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;
|
||||||
return trypos;
|
return trypos;
|
||||||
}
|
}
|
||||||
@ -1532,6 +1639,10 @@ void parse_cino(buf_T *buf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the desired indent for C code.
|
||||||
|
* Return -1 if the indent should be left alone (inside a raw string).
|
||||||
|
*/
|
||||||
int get_c_indent(void)
|
int get_c_indent(void)
|
||||||
{
|
{
|
||||||
pos_T cur_curpos;
|
pos_T cur_curpos;
|
||||||
@ -1542,8 +1653,9 @@ int get_c_indent(void)
|
|||||||
char_u *theline;
|
char_u *theline;
|
||||||
char_u *linecopy;
|
char_u *linecopy;
|
||||||
pos_T *trypos;
|
pos_T *trypos;
|
||||||
|
pos_T *comment_pos;
|
||||||
pos_T *tryposBrace = NULL;
|
pos_T *tryposBrace = NULL;
|
||||||
pos_T tryposBraceCopy;
|
pos_T tryposCopy;
|
||||||
pos_T our_paren_pos;
|
pos_T our_paren_pos;
|
||||||
char_u *start;
|
char_u *start;
|
||||||
int start_brace;
|
int start_brace;
|
||||||
@ -1567,7 +1679,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;
|
||||||
@ -1578,6 +1690,7 @@ int get_c_indent(void)
|
|||||||
int cont_amount = 0; /* amount for continuation line */
|
int cont_amount = 0; /* amount for continuation line */
|
||||||
int original_line_islabel;
|
int original_line_islabel;
|
||||||
int added_to_amount = 0;
|
int added_to_amount = 0;
|
||||||
|
cpp_baseclass_cache_T cache_cpp_baseclass = { false, { MAXLNUM, 0 } };
|
||||||
|
|
||||||
/* make a copy, value is changed below */
|
/* make a copy, value is changed below */
|
||||||
int ind_continuation = curbuf->b_ind_continuation;
|
int ind_continuation = curbuf->b_ind_continuation;
|
||||||
@ -1585,7 +1698,7 @@ int get_c_indent(void)
|
|||||||
/* remember where the cursor was when we started */
|
/* remember where the cursor was when we started */
|
||||||
cur_curpos = curwin->w_cursor;
|
cur_curpos = curwin->w_cursor;
|
||||||
|
|
||||||
/* if we are at line 1 0 is fine, right? */
|
/* if we are at line 1 zero indent is fine, right? */
|
||||||
if (cur_curpos.lnum == 1)
|
if (cur_curpos.lnum == 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -1614,38 +1727,56 @@ int get_c_indent(void)
|
|||||||
|
|
||||||
original_line_islabel = cin_islabel(); /* XXX */
|
original_line_islabel = cin_islabel(); /* XXX */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we are inside a raw string don't change the indent.
|
||||||
|
* Ignore a raw string inside a comment.
|
||||||
|
*/
|
||||||
|
comment_pos = ind_find_start_comment();
|
||||||
|
if (comment_pos != NULL) {
|
||||||
|
/* findmatchlimit() static pos is overwritten, make a copy */
|
||||||
|
tryposCopy = *comment_pos;
|
||||||
|
comment_pos = &tryposCopy;
|
||||||
|
}
|
||||||
|
trypos = find_start_rawstring(curbuf->b_ind_maxcomment);
|
||||||
|
if (trypos != NULL && (comment_pos == NULL || lt(*trypos, *comment_pos))) {
|
||||||
|
amount = -1;
|
||||||
|
goto laterend;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* #defines and so on always go at the left when included in 'cinkeys'.
|
* #defines and so on always go at the left when included in 'cinkeys'.
|
||||||
*/
|
*/
|
||||||
if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', TRUE)))
|
if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', true))) {
|
||||||
amount = curbuf->b_ind_hash_comment;
|
amount = curbuf->b_ind_hash_comment;
|
||||||
|
goto theend;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Is it a non-case label? Then that goes at the left margin too unless:
|
* Is it a non-case label? Then that goes at the left margin too unless:
|
||||||
* - JS flag is set.
|
* - JS flag is set.
|
||||||
* - 'L' item has a positive value.
|
* - 'L' item has a positive value.
|
||||||
*/
|
*/
|
||||||
else if (original_line_islabel && !curbuf->b_ind_js
|
if (original_line_islabel && !curbuf->b_ind_js
|
||||||
&& curbuf->b_ind_jump_label < 0) {
|
&& curbuf->b_ind_jump_label < 0) {
|
||||||
amount = 0;
|
amount = 0;
|
||||||
|
goto theend;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* If we're inside a "//" comment and there is a "//" comment in a
|
* If we're inside a "//" comment and there is a "//" comment in a
|
||||||
* previous line, lineup with that one.
|
* previous line, lineup with that one.
|
||||||
*/
|
*/
|
||||||
else if (cin_islinecomment(theline)
|
if (cin_islinecomment(theline)
|
||||||
&& (trypos = find_line_comment()) != NULL) { /* XXX */
|
&& (trypos = find_line_comment()) != NULL) { /* XXX */
|
||||||
/* find how indented the line beginning the comment is */
|
/* find how indented the line beginning the comment is */
|
||||||
getvcol(curwin, trypos, &col, NULL, NULL);
|
getvcol(curwin, trypos, &col, NULL, NULL);
|
||||||
amount = col;
|
amount = col;
|
||||||
|
goto theend;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* If we're inside a comment and not looking at the start of the
|
* If we're inside a comment and not looking at the start of the
|
||||||
* comment, try using the 'comments' option.
|
* comment, try using the 'comments' option.
|
||||||
*/
|
*/
|
||||||
else if (!cin_iscomment(theline)
|
if (!cin_iscomment(theline) && comment_pos != NULL) { /* XXX */
|
||||||
&& (trypos = ind_find_start_comment()) != NULL) {
|
|
||||||
/* XXX */
|
|
||||||
int lead_start_len = 2;
|
int lead_start_len = 2;
|
||||||
int lead_middle_len = 1;
|
int lead_middle_len = 1;
|
||||||
char_u lead_start[COM_MAX_LEN]; /* start-comment string */
|
char_u lead_start[COM_MAX_LEN]; /* start-comment string */
|
||||||
@ -1657,7 +1788,7 @@ int get_c_indent(void)
|
|||||||
int done = FALSE;
|
int done = FALSE;
|
||||||
|
|
||||||
/* find how indented the line beginning the comment is */
|
/* find how indented the line beginning the comment is */
|
||||||
getvcol(curwin, trypos, &col, NULL, NULL);
|
getvcol(curwin, comment_pos, &col, NULL, NULL);
|
||||||
amount = col;
|
amount = col;
|
||||||
*lead_start = NUL;
|
*lead_start = NUL;
|
||||||
*lead_middle = NUL;
|
*lead_middle = NUL;
|
||||||
@ -1709,13 +1840,13 @@ int get_c_indent(void)
|
|||||||
lead_middle_len) == 0) {
|
lead_middle_len) == 0) {
|
||||||
amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
|
amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
|
||||||
break;
|
break;
|
||||||
}
|
} else if (STRNCMP(ml_get(comment_pos->lnum) + comment_pos->col,
|
||||||
|
lead_start, lead_start_len) != 0) {
|
||||||
/* If the start comment string doesn't match with the
|
/* If the start comment string doesn't match with the
|
||||||
* start of the comment, skip this entry. XXX */
|
* start of the comment, skip this entry. XXX */
|
||||||
else if (STRNCMP(ml_get(trypos->lnum) + trypos->col,
|
|
||||||
lead_start, lead_start_len) != 0)
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (start_off != 0)
|
if (start_off != 0)
|
||||||
amount += start_off;
|
amount += start_off;
|
||||||
else if (start_align == COM_RIGHT)
|
else if (start_align == COM_RIGHT)
|
||||||
@ -1758,7 +1889,7 @@ int get_c_indent(void)
|
|||||||
* otherwise, add the amount specified by "c" in 'cino'
|
* otherwise, add the amount specified by "c" in 'cino'
|
||||||
*/
|
*/
|
||||||
amount = -1;
|
amount = -1;
|
||||||
for (lnum = cur_curpos.lnum - 1; lnum > trypos->lnum; --lnum) {
|
for (lnum = cur_curpos.lnum - 1; lnum > comment_pos->lnum; --lnum) {
|
||||||
if (linewhite(lnum)) /* skip blank lines */
|
if (linewhite(lnum)) /* skip blank lines */
|
||||||
continue;
|
continue;
|
||||||
amount = get_indent_lnum(lnum); /* XXX */
|
amount = get_indent_lnum(lnum); /* XXX */
|
||||||
@ -1766,28 +1897,30 @@ int get_c_indent(void)
|
|||||||
}
|
}
|
||||||
if (amount == -1) { /* use the comment opener */
|
if (amount == -1) { /* use the comment opener */
|
||||||
if (!curbuf->b_ind_in_comment2) {
|
if (!curbuf->b_ind_in_comment2) {
|
||||||
start = ml_get(trypos->lnum);
|
start = ml_get(comment_pos->lnum);
|
||||||
look = start + trypos->col + 2; /* skip / and * */
|
look = start + comment_pos->col + 2; /* skip / and * */
|
||||||
if (*look != NUL) /* if something after it */
|
if (*look != NUL) /* if something after it */
|
||||||
trypos->col = (colnr_T)(skipwhite(look) - start);
|
comment_pos->col = (colnr_T)(skipwhite(look) - start);
|
||||||
}
|
}
|
||||||
getvcol(curwin, trypos, &col, NULL, NULL);
|
getvcol(curwin, comment_pos, &col, NULL, NULL);
|
||||||
amount = col;
|
amount = col;
|
||||||
if (curbuf->b_ind_in_comment2 || *look == NUL)
|
if (curbuf->b_ind_in_comment2 || *look == NUL)
|
||||||
amount += curbuf->b_ind_in_comment;
|
amount += curbuf->b_ind_in_comment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
goto theend;
|
||||||
}
|
}
|
||||||
// Are we looking at a ']' that has a match?
|
// Are we looking at a ']' that has a match?
|
||||||
else if (*skipwhite(theline) == ']'
|
if (*skipwhite(theline) == ']'
|
||||||
&& (trypos = find_match_char('[', curbuf->b_ind_maxparen)) != NULL) {
|
&& (trypos = find_match_char('[', curbuf->b_ind_maxparen)) != NULL) {
|
||||||
// align with the line containing the '['.
|
// align with the line containing the '['.
|
||||||
amount = get_indent_lnum(trypos->lnum);
|
amount = get_indent_lnum(trypos->lnum);
|
||||||
|
goto theend;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Are we inside parentheses or braces?
|
* Are we inside parentheses or braces?
|
||||||
*/ /* XXX */
|
*/ /* XXX */
|
||||||
else if (((trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL
|
if (((trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL
|
||||||
&& curbuf->b_ind_java == 0)
|
&& curbuf->b_ind_java == 0)
|
||||||
|| (tryposBrace = find_start_brace()) != NULL
|
|| (tryposBrace = find_start_brace()) != NULL
|
||||||
|| trypos != NULL) {
|
|| trypos != NULL) {
|
||||||
@ -1821,8 +1954,8 @@ int get_c_indent(void)
|
|||||||
continue; /* ignore #define, #if, etc. */
|
continue; /* ignore #define, #if, etc. */
|
||||||
curwin->w_cursor.lnum = lnum;
|
curwin->w_cursor.lnum = lnum;
|
||||||
|
|
||||||
/* Skip a comment. XXX */
|
/* Skip a comment or raw string. XXX */
|
||||||
if ((trypos = ind_find_start_comment()) != NULL) {
|
if ((trypos = ind_find_start_CORS()) != NULL) {
|
||||||
lnum = trypos->lnum + 1;
|
lnum = trypos->lnum + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -2023,8 +2156,8 @@ int get_c_indent(void)
|
|||||||
// stored in tryposBrace.
|
// stored in tryposBrace.
|
||||||
// Make a copy of tryposBrace, it may point to pos_copy inside
|
// Make a copy of tryposBrace, it may point to pos_copy inside
|
||||||
// find_start_brace(), which may be changed somewhere.
|
// find_start_brace(), which may be changed somewhere.
|
||||||
tryposBraceCopy = *tryposBrace;
|
tryposCopy = *tryposBrace;
|
||||||
tryposBrace = &tryposBraceCopy;
|
tryposBrace = &tryposCopy;
|
||||||
trypos = tryposBrace;
|
trypos = tryposBrace;
|
||||||
ourscope = trypos->lnum;
|
ourscope = trypos->lnum;
|
||||||
start = ml_get(ourscope);
|
start = ml_get(ourscope);
|
||||||
@ -2201,10 +2334,10 @@ int get_c_indent(void)
|
|||||||
l = get_cursor_line_ptr();
|
l = get_cursor_line_ptr();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we're in a comment now, skip to the start of the
|
* If we're in a comment or raw string now, skip to
|
||||||
* comment.
|
* the start of it.
|
||||||
*/
|
*/
|
||||||
trypos = ind_find_start_comment();
|
trypos = ind_find_start_CORS();
|
||||||
if (trypos != NULL) {
|
if (trypos != NULL) {
|
||||||
curwin->w_cursor.lnum = trypos->lnum + 1;
|
curwin->w_cursor.lnum = trypos->lnum + 1;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
@ -2286,7 +2419,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;
|
||||||
@ -2309,9 +2443,9 @@ int get_c_indent(void)
|
|||||||
|
|
||||||
l = get_cursor_line_ptr();
|
l = get_cursor_line_ptr();
|
||||||
|
|
||||||
/* If we're in a comment now, skip to the start of
|
/* If we're in a comment or raw string now, skip
|
||||||
* the comment. */
|
* to the start of it. */
|
||||||
trypos = ind_find_start_comment();
|
trypos = ind_find_start_CORS();
|
||||||
if (trypos != NULL) {
|
if (trypos != NULL) {
|
||||||
curwin->w_cursor.lnum = trypos->lnum + 1;
|
curwin->w_cursor.lnum = trypos->lnum + 1;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
@ -2337,9 +2471,10 @@ int get_c_indent(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we're in a comment now, skip to the start of the comment.
|
* If we're in a comment or raw string now, skip to the start
|
||||||
|
* of it.
|
||||||
*/ /* XXX */
|
*/ /* XXX */
|
||||||
if ((trypos = ind_find_start_comment()) != NULL) {
|
if ((trypos = ind_find_start_CORS()) != NULL) {
|
||||||
curwin->w_cursor.lnum = trypos->lnum + 1;
|
curwin->w_cursor.lnum = trypos->lnum + 1;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
continue;
|
continue;
|
||||||
@ -2492,7 +2627,7 @@ int get_c_indent(void)
|
|||||||
*/ /* XXX */
|
*/ /* XXX */
|
||||||
n = FALSE;
|
n = FALSE;
|
||||||
if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0) {
|
if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0) {
|
||||||
n = cin_is_cpp_baseclass(&col);
|
n = cin_is_cpp_baseclass(&cache_cpp_baseclass);
|
||||||
l = get_cursor_line_ptr();
|
l = get_cursor_line_ptr();
|
||||||
}
|
}
|
||||||
if (n) {
|
if (n) {
|
||||||
@ -2508,7 +2643,7 @@ int get_c_indent(void)
|
|||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
/* XXX */
|
/* XXX */
|
||||||
amount = get_baseclass_amount(col);
|
amount = get_baseclass_amount(cache_cpp_baseclass.lpos.col);
|
||||||
break;
|
break;
|
||||||
} else if (lookfor == LOOKFOR_CPP_BASECLASS) {
|
} else if (lookfor == LOOKFOR_CPP_BASECLASS) {
|
||||||
/* only look, whether there is a cpp base class
|
/* only look, whether there is a cpp base class
|
||||||
@ -2550,23 +2685,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 +2926,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 +2956,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 +2980,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3038,8 +3189,10 @@ term_again:
|
|||||||
/* subtract extra left-shift for jump labels */
|
/* subtract extra left-shift for jump labels */
|
||||||
if (curbuf->b_ind_jump_label > 0 && original_line_islabel)
|
if (curbuf->b_ind_jump_label > 0 && original_line_islabel)
|
||||||
amount -= curbuf->b_ind_jump_label;
|
amount -= curbuf->b_ind_jump_label;
|
||||||
|
|
||||||
|
goto theend;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// Ok -- we're not inside any sort of structure at all!
|
// Ok -- we're not inside any sort of structure at all!
|
||||||
//
|
//
|
||||||
// this means we're at the top level, and everything should
|
// this means we're at the top level, and everything should
|
||||||
@ -3050,8 +3203,10 @@ term_again:
|
|||||||
// if our line starts with an open brace, forget about any
|
// if our line starts with an open brace, forget about any
|
||||||
// prevailing indent and make sure it looks like the start
|
// prevailing indent and make sure it looks like the start
|
||||||
// of a function
|
// of a function
|
||||||
|
|
||||||
if (theline[0] == '{') {
|
if (theline[0] == '{') {
|
||||||
amount = curbuf->b_ind_first_open;
|
amount = curbuf->b_ind_first_open;
|
||||||
|
goto theend;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* If the NEXT line is a function declaration, the current
|
* If the NEXT line is a function declaration, the current
|
||||||
@ -3060,7 +3215,7 @@ term_again:
|
|||||||
* current line is terminated, ie. ends in ';', or if the current line
|
* current line is terminated, ie. ends in ';', or if the current line
|
||||||
* contains { or }: "void f() {\n if (1)"
|
* contains { or }: "void f() {\n if (1)"
|
||||||
*/
|
*/
|
||||||
else if (cur_curpos.lnum < curbuf->b_ml.ml_line_count
|
if (cur_curpos.lnum < curbuf->b_ml.ml_line_count
|
||||||
&& !cin_nocode(theline)
|
&& !cin_nocode(theline)
|
||||||
&& vim_strchr(theline, '{') == NULL
|
&& vim_strchr(theline, '{') == NULL
|
||||||
&& vim_strchr(theline, '}') == NULL
|
&& vim_strchr(theline, '}') == NULL
|
||||||
@ -3068,14 +3223,14 @@ term_again:
|
|||||||
&& !cin_ends_in(theline, (char_u *)",", NULL)
|
&& !cin_ends_in(theline, (char_u *)",", NULL)
|
||||||
&& cin_isfuncdecl(NULL, cur_curpos.lnum + 1,
|
&& cin_isfuncdecl(NULL, cur_curpos.lnum + 1,
|
||||||
cur_curpos.lnum + 1)
|
cur_curpos.lnum + 1)
|
||||||
&& !cin_isterminated(theline, FALSE, TRUE)) {
|
&& !cin_isterminated(theline, false, true)) {
|
||||||
amount = curbuf->b_ind_func_type;
|
amount = curbuf->b_ind_func_type;
|
||||||
} else {
|
goto theend;
|
||||||
amount = 0;
|
}
|
||||||
curwin->w_cursor = cur_curpos;
|
|
||||||
|
|
||||||
/* search backwards until we find something we recognize */
|
/* search backwards until we find something we recognize */
|
||||||
|
amount = 0;
|
||||||
|
curwin->w_cursor = cur_curpos;
|
||||||
while (curwin->w_cursor.lnum > 1) {
|
while (curwin->w_cursor.lnum > 1) {
|
||||||
curwin->w_cursor.lnum--;
|
curwin->w_cursor.lnum--;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
@ -3083,9 +3238,10 @@ term_again:
|
|||||||
l = get_cursor_line_ptr();
|
l = get_cursor_line_ptr();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we're in a comment now, skip to the start of the comment.
|
* If we're in a comment or raw string now, skip to the start
|
||||||
|
* of it.
|
||||||
*/ /* XXX */
|
*/ /* XXX */
|
||||||
if ((trypos = ind_find_start_comment()) != NULL) {
|
if ((trypos = ind_find_start_CORS()) != NULL) {
|
||||||
curwin->w_cursor.lnum = trypos->lnum + 1;
|
curwin->w_cursor.lnum = trypos->lnum + 1;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
continue;
|
continue;
|
||||||
@ -3095,14 +3251,14 @@ term_again:
|
|||||||
* Are we at the start of a cpp base class declaration or
|
* Are we at the start of a cpp base class declaration or
|
||||||
* constructor initialization?
|
* constructor initialization?
|
||||||
*/ /* XXX */
|
*/ /* XXX */
|
||||||
n = FALSE;
|
n = false;
|
||||||
if (curbuf->b_ind_cpp_baseclass != 0 && theline[0] != '{') {
|
if (curbuf->b_ind_cpp_baseclass != 0 && theline[0] != '{') {
|
||||||
n = cin_is_cpp_baseclass(&col);
|
n = cin_is_cpp_baseclass(&cache_cpp_baseclass);
|
||||||
l = get_cursor_line_ptr();
|
l = get_cursor_line_ptr();
|
||||||
}
|
}
|
||||||
if (n) {
|
if (n) {
|
||||||
/* XXX */
|
/* XXX */
|
||||||
amount = get_baseclass_amount(col);
|
amount = get_baseclass_amount(cache_cpp_baseclass.lpos.col);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3273,17 +3429,17 @@ term_again:
|
|||||||
amount += ind_continuation;
|
amount += ind_continuation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
theend:
|
theend:
|
||||||
|
if (amount < 0)
|
||||||
|
amount = 0;
|
||||||
|
|
||||||
|
laterend:
|
||||||
/* put the cursor back where it belongs */
|
/* put the cursor back where it belongs */
|
||||||
curwin->w_cursor = cur_curpos;
|
curwin->w_cursor = cur_curpos;
|
||||||
|
|
||||||
xfree(linecopy);
|
xfree(linecopy);
|
||||||
|
|
||||||
if (amount < 0)
|
|
||||||
return 0;
|
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,7 +554,7 @@ void op_reindent(oparg_T *oap, Indenter how)
|
|||||||
{
|
{
|
||||||
long i;
|
long i;
|
||||||
char_u *l;
|
char_u *l;
|
||||||
int count;
|
int amount;
|
||||||
linenr_T first_changed = 0;
|
linenr_T first_changed = 0;
|
||||||
linenr_T last_changed = 0;
|
linenr_T last_changed = 0;
|
||||||
linenr_T start_lnum = curwin->w_cursor.lnum;
|
linenr_T start_lnum = curwin->w_cursor.lnum;
|
||||||
@ -582,11 +582,11 @@ void op_reindent(oparg_T *oap, Indenter how)
|
|||||||
|| how != get_lisp_indent) {
|
|| how != get_lisp_indent) {
|
||||||
l = skipwhite(get_cursor_line_ptr());
|
l = skipwhite(get_cursor_line_ptr());
|
||||||
if (*l == NUL) /* empty or blank line */
|
if (*l == NUL) /* empty or blank line */
|
||||||
count = 0;
|
amount = 0;
|
||||||
else
|
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 */
|
/* did change the indent, call changed_lines() later */
|
||||||
if (first_changed == 0)
|
if (first_changed == 0)
|
||||||
first_changed = curwin->w_cursor.lnum;
|
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;
|
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
|
* findmatchlimit -- find the matching paren or brace, if it exists within
|
||||||
* maxtravel lines of here. A maxtravel of 0 means search until falling off
|
* maxtravel lines of the cursor. A maxtravel of 0 means search until falling
|
||||||
* the edge of the file.
|
* off the edge of the file.
|
||||||
*
|
*
|
||||||
* "initc" is the character to find a match for. NUL means to find the
|
* "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 '#')
|
* flags: FM_BACKWARD search backwards (when initc is '/', '*' or '#')
|
||||||
* FM_FORWARD search forwards (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_BLOCKSTOP stop at start/end of block ({ or } in column 0)
|
||||||
* FM_SKIPCOMM skip comments (not implemented yet!)
|
* 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
|
* NULL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -1465,8 +1510,9 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
|
|||||||
int findc = 0; /* matching brace */
|
int findc = 0; /* matching brace */
|
||||||
int c;
|
int c;
|
||||||
int count = 0; /* cumulative number of braces */
|
int count = 0; /* cumulative number of braces */
|
||||||
int backwards = FALSE; /* init for gcc */
|
int backwards = false; /* init for gcc */
|
||||||
int inquote = FALSE; /* TRUE when inside quotes */
|
int raw_string = false; /* search for raw string */
|
||||||
|
int inquote = false; /* true when inside quotes */
|
||||||
char_u *linep; /* pointer to current line */
|
char_u *linep; /* pointer to current line */
|
||||||
char_u *ptr;
|
char_u *ptr;
|
||||||
int do_quotes; /* check for quotes in current line */
|
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
|
* When '/' is used, we ignore running backwards into a star-slash, for
|
||||||
* "[*" command, we just want to find any comment.
|
* "[*" command, we just want to find any comment.
|
||||||
*/
|
*/
|
||||||
if (initc == '/' || initc == '*') {
|
if (initc == '/' || initc == '*' || initc == 'R') {
|
||||||
comment_dir = dir;
|
comment_dir = dir;
|
||||||
if (initc == '/')
|
if (initc == '/')
|
||||||
ignore_cend = TRUE;
|
ignore_cend = true;
|
||||||
backwards = (dir == FORWARD) ? FALSE : TRUE;
|
backwards = (dir == FORWARD) ? false : true;
|
||||||
|
raw_string = (initc == 'R');
|
||||||
initc = NUL;
|
initc = NUL;
|
||||||
} else if (initc != '#' && initc != NUL) {
|
} else if (initc != '#' && initc != NUL) {
|
||||||
find_mps_values(&initc, &findc, &backwards, TRUE);
|
find_mps_values(&initc, &findc, &backwards, TRUE);
|
||||||
if (findc == NUL)
|
if (findc == NUL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else {
|
||||||
/*
|
/*
|
||||||
* Either initc is '#', or no initc was given and we need to look under the
|
* Either initc is '#', or no initc was given and we need to look
|
||||||
* cursor.
|
* under the cursor.
|
||||||
*/
|
*/
|
||||||
else {
|
|
||||||
if (initc == '#') {
|
if (initc == '#') {
|
||||||
hash_dir = dir;
|
hash_dir = dir;
|
||||||
} else {
|
} else {
|
||||||
@ -1766,7 +1812,26 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
|
|||||||
*/
|
*/
|
||||||
if (pos.col == 0)
|
if (pos.col == 0)
|
||||||
continue;
|
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] == '*'
|
&& linep[pos.col] == '*'
|
||||||
&& (int)pos.col < comment_col) {
|
&& (int)pos.col < comment_col) {
|
||||||
count++;
|
count++;
|
||||||
|
@ -190,7 +190,7 @@ static int included_patches[] = {
|
|||||||
// 806,
|
// 806,
|
||||||
// 805,
|
// 805,
|
||||||
// 804,
|
// 804,
|
||||||
// 803,
|
803,
|
||||||
802,
|
802,
|
||||||
// 801,
|
// 801,
|
||||||
// 800,
|
// 800,
|
||||||
@ -270,7 +270,7 @@ static int included_patches[] = {
|
|||||||
// 726 NA
|
// 726 NA
|
||||||
// 725,
|
// 725,
|
||||||
// 724 NA
|
// 724 NA
|
||||||
// 723,
|
723,
|
||||||
// 722,
|
// 722,
|
||||||
// 721,
|
// 721,
|
||||||
// 720 NA
|
// 720 NA
|
||||||
@ -323,7 +323,7 @@ static int included_patches[] = {
|
|||||||
673,
|
673,
|
||||||
// 672,
|
// 672,
|
||||||
// 671,
|
// 671,
|
||||||
// 670,
|
670,
|
||||||
// 669 NA
|
// 669 NA
|
||||||
668,
|
668,
|
||||||
667,
|
667,
|
||||||
|
@ -901,6 +901,23 @@ describe('cindent', function()
|
|||||||
{
|
{
|
||||||
111111111111111111;
|
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 */
|
/* end of AUTO */
|
||||||
]=])
|
]=])
|
||||||
@ -1790,6 +1807,23 @@ describe('cindent', function()
|
|||||||
{
|
{
|
||||||
111111111111111111;
|
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 */
|
/* end of AUTO */
|
||||||
]=])
|
]=])
|
||||||
@ -4213,4 +4247,321 @@ describe('cindent', function()
|
|||||||
JSEND
|
JSEND
|
||||||
]=])
|
]=])
|
||||||
end)
|
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)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user