On Do, 24 Aug 2017, Bart wrote:
> Here is a test:
>
> ```
> func Test_raw_string()
> new
> setlocal cindent
> norm i
>
> call feedkeys("i" .
> \ "int main() {\<CR>" .
> \ "R\"(\<CR>" .
> \ ")\";\<CR>" .
> \ "statement;\<Esc>", "x")
> assert_equal(getline(line('.')), "\tstatement;")
> endfunc
> ```
Thanks. It modified slightly and added it to the patch. Result is
attached to this mail. Bram, please include.
Best,
Christian
--
Was ist der Unterschied zwischen einem Fuchs und einem Wessi? Der
Fuchs ist schlau und stellt sich dumm - der Wessi macht es andersrum.
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
From 845afc4b59f12642fcae37bd9cc8e0f2c1814e6a Mon Sep 17 00:00:00 2001
From: Christian Brabandt <[email protected]>
Date: Thu, 24 Aug 2017 10:17:49 +0200
Subject: [PATCH] cindent: better support for raw-strings
fixes #2019
includes a test
---
src/misc1.c | 29 ++++++++++++++++++-----------
src/testdir/test_cindent.vim | 13 +++++++++++--
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/src/misc1.c b/src/misc1.c
index d20deaee0..c2aebf156 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -5219,7 +5219,7 @@ FullName_save(
static char_u *skip_string(char_u *p);
static pos_T *ind_find_start_comment(void);
-static pos_T *ind_find_start_CORS(void);
+static pos_T *ind_find_start_CORS(linenr_T *is_raw);
static pos_T *find_start_rawstring(int ind_maxcomment);
/*
@@ -5270,11 +5270,12 @@ find_start_comment(int ind_maxcomment) /* 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.
* Return NULL when not inside a comment or raw string.
* "CORS" -> Comment Or Raw String
*/
static pos_T *
-ind_find_start_CORS(void) /* XXX */
+ind_find_start_CORS(linenr_T *is_raw) /* XXX */
{
static pos_T comment_pos_copy;
pos_T *comment_pos;
@@ -5294,7 +5295,11 @@ ind_find_start_CORS(void) /* XXX */
* If rs_pos is before comment_pos the comment is inside the raw string. */
if (comment_pos == NULL || (rs_pos != NULL
&& LT_POS(*rs_pos, *comment_pos)))
+ {
+ if (is_raw != NULL && rs_pos != NULL)
+ *is_raw = rs_pos->lnum;
return rs_pos;
+ }
return comment_pos;
}
@@ -5639,7 +5644,7 @@ cin_islabel(void) /* XXX */
* 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 = ml_get_curline();
@@ -6766,7 +6771,7 @@ find_start_brace(void) /* XXX */
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;
@@ -6817,7 +6822,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);
@@ -7187,6 +7192,7 @@ get_c_indent(void)
int original_line_islabel;
int added_to_amount = 0;
int js_cur_has_key = 0;
+ linenr_T raw_string_start = 0;
cpp_baseclass_cache_T cache_cpp_baseclass = { FALSE, { MAXLNUM, 0 } };
/* make a copy, value is changed below */
@@ -7489,7 +7495,7 @@ 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;
@@ -7930,7 +7936,7 @@ 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;
@@ -8050,7 +8056,7 @@ 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;
@@ -8088,7 +8094,7 @@ 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;
@@ -8655,7 +8661,8 @@ get_c_indent(void)
curwin->w_cursor.lnum);
if (lookfor != LOOKFOR_TERM
&& lookfor != LOOKFOR_JS_KEY
- && lookfor != LOOKFOR_COMMA)
+ && lookfor != LOOKFOR_COMMA
+ && raw_string_start != curwin->w_cursor.lnum)
lookfor = LOOKFOR_UNTERM;
}
}
@@ -8936,7 +8943,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;
diff --git a/src/testdir/test_cindent.vim b/src/testdir/test_cindent.vim
index 5f9d9fd5b..b39f933f7 100644
--- a/src/testdir/test_cindent.vim
+++ b/src/testdir/test_cindent.vim
@@ -68,8 +68,6 @@ func Test_cino_extern_c()
call assert_equal(pair[2], getline(len(lines) + 1), 'Failed for "' . string(lines) . '"')
endfor
-
-
bwipe!
endfunc
@@ -92,4 +90,15 @@ func! Test_cindent_expr()
bw!
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
--
2.11.0