mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06: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:
parent
012cd35bfb
commit
fe57a8a4e4
@ -75,11 +75,12 @@ find_start_comment ( /* XXX */
|
|||||||
/// Find the start of a comment or raw string, not knowing if we are in a
|
/// Find the start of a comment or raw string, not knowing if we are in a
|
||||||
/// comment or raw string right now.
|
/// comment or raw string right now.
|
||||||
/// Search starts at w_cursor.lnum and goes backwards.
|
/// 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.
|
/// @returns NULL when not inside a comment or raw string.
|
||||||
///
|
///
|
||||||
/// @note "CORS" -> 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
|
// XXX
|
||||||
static pos_T comment_pos_copy;
|
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 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 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 (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 rs_pos;
|
||||||
}
|
}
|
||||||
return comment_pos;
|
return comment_pos;
|
||||||
@ -384,8 +388,9 @@ int cin_islabel(void)
|
|||||||
* it.
|
* it.
|
||||||
*/
|
*/
|
||||||
curwin->w_cursor.col = 0;
|
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;
|
curwin->w_cursor = *trypos;
|
||||||
|
}
|
||||||
|
|
||||||
line = get_cursor_line_ptr();
|
line = get_cursor_line_ptr();
|
||||||
if (cin_ispreproc(line)) /* ignore #defines, #if, etc. */
|
if (cin_ispreproc(line)) /* ignore #defines, #if, etc. */
|
||||||
@ -1401,8 +1406,9 @@ 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_CORS()) == NULL) /* XXX */
|
&& (pos = ind_find_start_CORS(NULL)) == NULL) { // XXX
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
if (pos != NULL)
|
if (pos != NULL)
|
||||||
curwin->w_cursor.lnum = pos->lnum;
|
curwin->w_cursor.lnum = pos->lnum;
|
||||||
}
|
}
|
||||||
@ -1443,7 +1449,7 @@ retry:
|
|||||||
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 ((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
|
ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum
|
||||||
- trypos_wk->lnum);
|
- trypos_wk->lnum);
|
||||||
if (ind_maxp_wk > 0) {
|
if (ind_maxp_wk > 0) {
|
||||||
@ -1793,6 +1799,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;
|
||||||
|
linenr_T raw_string_start = 0;
|
||||||
cpp_baseclass_cache_T cache_cpp_baseclass = { false, { MAXLNUM, 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 */
|
||||||
@ -2060,7 +2067,7 @@ int get_c_indent(void)
|
|||||||
curwin->w_cursor.lnum = lnum;
|
curwin->w_cursor.lnum = lnum;
|
||||||
|
|
||||||
/* Skip a comment or raw string. XXX */
|
/* 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;
|
lnum = trypos->lnum + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -2443,7 +2450,7 @@ int get_c_indent(void)
|
|||||||
* If we're in a comment or raw string now, skip to
|
* If we're in a comment or raw string now, skip to
|
||||||
* the start of it.
|
* the start of it.
|
||||||
*/
|
*/
|
||||||
trypos = ind_find_start_CORS();
|
trypos = ind_find_start_CORS(NULL);
|
||||||
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;
|
||||||
@ -2552,7 +2559,7 @@ int get_c_indent(void)
|
|||||||
|
|
||||||
/* If we're in a comment or raw string now, skip
|
/* If we're in a comment or raw string now, skip
|
||||||
* to the start of it. */
|
* to the start of it. */
|
||||||
trypos = ind_find_start_CORS();
|
trypos = ind_find_start_CORS(NULL);
|
||||||
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;
|
||||||
@ -2585,7 +2592,7 @@ int get_c_indent(void)
|
|||||||
* If we're in a comment or raw string now, skip to the start
|
* If we're in a comment or raw string now, skip to the start
|
||||||
* of it.
|
* of it.
|
||||||
*/ /* XXX */
|
*/ /* 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.lnum = trypos->lnum + 1;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
continue;
|
continue;
|
||||||
@ -3096,7 +3103,8 @@ int get_c_indent(void)
|
|||||||
}
|
}
|
||||||
if (lookfor != LOOKFOR_TERM
|
if (lookfor != LOOKFOR_TERM
|
||||||
&& lookfor != LOOKFOR_JS_KEY
|
&& lookfor != LOOKFOR_JS_KEY
|
||||||
&& lookfor != LOOKFOR_COMMA) {
|
&& lookfor != LOOKFOR_COMMA
|
||||||
|
&& raw_string_start != curwin->w_cursor.lnum) {
|
||||||
lookfor = LOOKFOR_UNTERM;
|
lookfor = LOOKFOR_UNTERM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3355,7 +3363,7 @@ term_again:
|
|||||||
* If we're in a comment or raw string now, skip to the start
|
* If we're in a comment or raw string now, skip to the start
|
||||||
* of it.
|
* of it.
|
||||||
*/ /* XXX */
|
*/ /* 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.lnum = trypos->lnum + 1;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
continue;
|
continue;
|
||||||
|
@ -68,9 +68,18 @@ func Test_cino_extern_c()
|
|||||||
call assert_equal(pair[2], getline(len(lines) + 1), 'Failed for "' . string(lines) . '"')
|
call assert_equal(pair[2], getline(len(lines) + 1), 'Failed for "' . string(lines) . '"')
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func! Test_cindent_rawstring()
|
||||||
|
new
|
||||||
|
setl cindent
|
||||||
|
call feedkeys("i" .
|
||||||
|
\ "int main() {\<CR>" .
|
||||||
|
\ "R\"(\<CR>" .
|
||||||
|
\ ")\";\<CR>" .
|
||||||
|
\ "statement;\<Esc>", "x")
|
||||||
|
call assert_equal("\tstatement;", getline(line('.')))
|
||||||
|
bw!
|
||||||
|
endfunction
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Loading…
Reference in New Issue
Block a user