mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 21:48:35 +00:00
vim-patch:8.0.0999: indenting raw C++ strings is wrong
Problem: Indenting raw C++ strings is wrong.
Solution: Add special handling of raw strings. (Christian Brabandt)
dde81312b0
This commit is contained in:
@@ -75,11 +75,12 @@ find_start_comment ( /* XXX */
|
||||
/// 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.
|
||||
/// If is_raw is given and returns start of raw_string, sets it to true.
|
||||
///
|
||||
/// @returns NULL when not inside a comment or raw string.
|
||||
///
|
||||
/// @note "CORS" -> Comment Or Raw String
|
||||
static pos_T *ind_find_start_CORS(void)
|
||||
static pos_T *ind_find_start_CORS(linenr_T *is_raw)
|
||||
{
|
||||
// XXX
|
||||
static pos_T comment_pos_copy;
|
||||
@@ -96,6 +97,9 @@ static pos_T *ind_find_start_CORS(void)
|
||||
// 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))) {
|
||||
if (is_raw != NULL && rs_pos != NULL) {
|
||||
*is_raw = rs_pos->lnum;
|
||||
}
|
||||
return rs_pos;
|
||||
}
|
||||
return comment_pos;
|
||||
@@ -384,8 +388,9 @@ int cin_islabel(void)
|
||||
* it.
|
||||
*/
|
||||
curwin->w_cursor.col = 0;
|
||||
if ((trypos = ind_find_start_CORS()) != NULL) /* XXX */
|
||||
if ((trypos = ind_find_start_CORS(NULL)) != NULL) { // XXX
|
||||
curwin->w_cursor = *trypos;
|
||||
}
|
||||
|
||||
line = get_cursor_line_ptr();
|
||||
if (cin_ispreproc(line)) /* ignore #defines, #if, etc. */
|
||||
@@ -1401,8 +1406,9 @@ static pos_T *find_start_brace(void)
|
||||
pos = NULL;
|
||||
/* ignore the { if it's in a // or / * * / comment */
|
||||
if ((colnr_T)cin_skip2pos(trypos) == trypos->col
|
||||
&& (pos = ind_find_start_CORS()) == NULL) /* XXX */
|
||||
&& (pos = ind_find_start_CORS(NULL)) == NULL) { // XXX
|
||||
break;
|
||||
}
|
||||
if (pos != NULL)
|
||||
curwin->w_cursor.lnum = pos->lnum;
|
||||
}
|
||||
@@ -1443,7 +1449,7 @@ retry:
|
||||
pos_copy = *trypos; /* copy trypos, findmatch will change it */
|
||||
trypos = &pos_copy;
|
||||
curwin->w_cursor = *trypos;
|
||||
if ((trypos_wk = ind_find_start_CORS()) != NULL) { /* XXX */
|
||||
if ((trypos_wk = ind_find_start_CORS(NULL)) != NULL) { // XXX
|
||||
ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum
|
||||
- trypos_wk->lnum);
|
||||
if (ind_maxp_wk > 0) {
|
||||
@@ -1793,6 +1799,7 @@ int get_c_indent(void)
|
||||
int cont_amount = 0; /* amount for continuation line */
|
||||
int original_line_islabel;
|
||||
int added_to_amount = 0;
|
||||
linenr_T raw_string_start = 0;
|
||||
cpp_baseclass_cache_T cache_cpp_baseclass = { false, { MAXLNUM, 0 } };
|
||||
|
||||
/* make a copy, value is changed below */
|
||||
@@ -2060,7 +2067,7 @@ int get_c_indent(void)
|
||||
curwin->w_cursor.lnum = lnum;
|
||||
|
||||
/* Skip a comment or raw string. XXX */
|
||||
if ((trypos = ind_find_start_CORS()) != NULL) {
|
||||
if ((trypos = ind_find_start_CORS(NULL)) != NULL) {
|
||||
lnum = trypos->lnum + 1;
|
||||
continue;
|
||||
}
|
||||
@@ -2443,7 +2450,7 @@ int get_c_indent(void)
|
||||
* If we're in a comment or raw string now, skip to
|
||||
* the start of it.
|
||||
*/
|
||||
trypos = ind_find_start_CORS();
|
||||
trypos = ind_find_start_CORS(NULL);
|
||||
if (trypos != NULL) {
|
||||
curwin->w_cursor.lnum = trypos->lnum + 1;
|
||||
curwin->w_cursor.col = 0;
|
||||
@@ -2552,7 +2559,7 @@ int get_c_indent(void)
|
||||
|
||||
/* If we're in a comment or raw string now, skip
|
||||
* to the start of it. */
|
||||
trypos = ind_find_start_CORS();
|
||||
trypos = ind_find_start_CORS(NULL);
|
||||
if (trypos != NULL) {
|
||||
curwin->w_cursor.lnum = trypos->lnum + 1;
|
||||
curwin->w_cursor.col = 0;
|
||||
@@ -2585,7 +2592,7 @@ int get_c_indent(void)
|
||||
* If we're in a comment or raw string now, skip to the start
|
||||
* of it.
|
||||
*/ /* XXX */
|
||||
if ((trypos = ind_find_start_CORS()) != NULL) {
|
||||
if ((trypos = ind_find_start_CORS(&raw_string_start)) != NULL) {
|
||||
curwin->w_cursor.lnum = trypos->lnum + 1;
|
||||
curwin->w_cursor.col = 0;
|
||||
continue;
|
||||
@@ -3096,7 +3103,8 @@ int get_c_indent(void)
|
||||
}
|
||||
if (lookfor != LOOKFOR_TERM
|
||||
&& lookfor != LOOKFOR_JS_KEY
|
||||
&& lookfor != LOOKFOR_COMMA) {
|
||||
&& lookfor != LOOKFOR_COMMA
|
||||
&& raw_string_start != curwin->w_cursor.lnum) {
|
||||
lookfor = LOOKFOR_UNTERM;
|
||||
}
|
||||
}
|
||||
@@ -3355,7 +3363,7 @@ term_again:
|
||||
* If we're in a comment or raw string now, skip to the start
|
||||
* of it.
|
||||
*/ /* XXX */
|
||||
if ((trypos = ind_find_start_CORS()) != NULL) {
|
||||
if ((trypos = ind_find_start_CORS(NULL)) != NULL) {
|
||||
curwin->w_cursor.lnum = trypos->lnum + 1;
|
||||
curwin->w_cursor.col = 0;
|
||||
continue;
|
||||
|
Reference in New Issue
Block a user