Hi Bram and list,
How to reproduce.
- Start pure Vim with 'set cindent'. (test.c is attached this mail)
$ vim -N -u NONE -c "set cin cino=" test.c
- Do indent.
gg=G
Expected result:
{
// (1)
int ary[4] = {
[0] = 0,
[1] = 1,
[2] = 2,
[3] = 3,
};
// (2)
a = b[2]
+ 3;
// (3)
if (1)
/* aaaaa
* bbbbb
*/
a = 1;
}
Actual result:
{
// (1)
int ary[4] = {
[0] = 0,
[1] = 1,
[2] = 2,
[3] = 3,
};
// (2)
a = b[2]
+ 3;
// (3)
if (1)
/* aaaaa
* bbbbb
*/
a = 1;
}
(1) Line of "[2] = 2," and "[3] = 3," indent wrong.
(2) "+ 3;" indent wrong.
(3) "a = 1;" indent wrong.
Investigation result:
- (1) and (2) is broken since the patch 7.4.670.
https://groups.google.com/d/msg/vim_dev/0nS1z0tGtnc/9h6zk-oc0LQJ
It's my patch. sorry.
- (3) is broken since the patch 7.4.803.
https://groups.google.com/d/msg/vim_dev/G6syQNGZjsQ/7TtbRF9JGgAJ
In ind_find_start_CORS() src/misc1.c.
Call find_start_comment() and receives the return value by comment_pos of
type of (pos_T *).
It's address of static pos_T pos in findmatchlimit().
But, next call find_start_rawstring() calls findmatchlimit().
This may the contents of comment_pos is changed unexpectedly.
I wrote a patch contains test.
Please check this.
--
Best regards,
Hirohito Higashi (a.k.a h_east)
--
--
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.
diff --git a/src/misc1.c b/src/misc1.c
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -5345,14 +5345,26 @@
static pos_T *
ind_find_start_CORS() /* XXX */
{
- pos_T *comment_pos = find_start_comment(curbuf->b_ind_maxcomment);
- pos_T *rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment);
-
+ static pos_T comment_pos_body;
+ static pos_T rs_pos_body;
+ pos_T *comment_pos;
+ pos_T *rs_pos;
+
+ comment_pos = find_start_comment(curbuf->b_ind_maxcomment);
+ if (comment_pos != NULL)
+ comment_pos_body = *comment_pos;
+ rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment);
+ if (rs_pos != NULL)
+ rs_pos_body = *rs_pos;
+
+ if (comment_pos == NULL && rs_pos == NULL)
+ return NULL;
/* 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;
+ if (comment_pos == NULL
+ || (rs_pos != NULL && lt(rs_pos_body, comment_pos_body)))
+ return &rs_pos_body;
+ return &comment_pos_body;
}
/*
@@ -8334,7 +8346,8 @@
if (terminated == 0 || (lookfor != LOOKFOR_UNTERM
&& terminated == ','))
{
- if (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '[')
+ if (lookfor != LOOKFOR_ENUM_OR_INIT &&
+ (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '['))
amount += ind_continuation;
/*
* if we're in the middle of a paren thing,
@@ -8576,7 +8589,10 @@
*/
l = ml_get_curline();
amount = cur_amount;
- if (*skipwhite(l) == ']' || l[STRLEN(l) - 1] == ']')
+
+ n = (int)STRLEN(l);
+ if (terminated == ',' && (*skipwhite(l) == ']'
+ || (n >=2 && l[n - 2] == ']')))
break;
/*
diff --git a/src/testdir/test3.in b/src/testdir/test3.in
--- a/src/testdir/test3.in
+++ b/src/testdir/test3.in
@@ -910,6 +910,28 @@
)foo";
}
+{
+int a[4] = {
+[0] = 0,
+[1] = 1,
+[2] = 2,
+[3] = 3,
+};
+}
+
+{
+a = b[2]
++ 3;
+}
+
+{
+if (1)
+/* aaaaa
+* bbbbb
+*/
+a = 1;
+}
+
/* end of AUTO */
STARTTEST
diff --git a/src/testdir/test3.ok b/src/testdir/test3.ok
--- a/src/testdir/test3.ok
+++ b/src/testdir/test3.ok
@@ -898,6 +898,28 @@
)foo";
}
+{
+ int a[4] = {
+ [0] = 0,
+ [1] = 1,
+ [2] = 2,
+ [3] = 3,
+ };
+}
+
+{
+ a = b[2]
+ + 3;
+}
+
+{
+ if (1)
+ /* aaaaa
+ * bbbbb
+ */
+ a = 1;
+}
+
/* end of AUTO */
{
// (1)
int ary[4] = {
[0] = 0,
[1] = 1,
[2] = 2,
[3] = 3,
};
// (2)
a = b[2]
+ 3;
// (3)
if (1)
/* aaaaa
* bbbbb
*/
a = 1;
}