Given this text (two lines with four leading spaces on each):
xx 1111 1111 1111
2222
And, given these settings (auto format + second line indent):
:set textwidth=25
:set formatoptions=a2
Inserting a space on line 2 column 1 results in a cursor positioning bug, to
wit, the cursor is unexpectedly moved near the end of line 1.
This does not happen if comments are present and we 'set fo+=q'.
The problem is that ops.c:format_lines() has the requisite code needed
to handle this for the comment case only. In the non-comment case,
the second_indent variable can be used instead of the next_leader_len
variable to achieve the same result as seen in this excerpt from the
attached patch:
diff -p ./src/ops.c.org ./src/ops.c
*** ./src/ops.c.org Sun Sep 1 12:29:50 2013
--- ./src/ops.c Sun Sep 1 13:55:24 2013
*************** format_lines(line_count, avoid_fex)
*** 4981,4990 ****
if (line_count < 0 && u_save_cursor() == FAIL)
break;
#ifdef FEAT_COMMENTS
! (void)del_bytes((long)next_leader_len, FALSE, FALSE);
! if (next_leader_len > 0)
! mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
! (long)-next_leader_len);
#endif
curwin->w_cursor.lnum--;
if (do_join(2, TRUE, FALSE, FALSE) == FAIL)
--- 4981,5002 ----
if (line_count < 0 && u_save_cursor() == FAIL)
break;
#ifdef FEAT_COMMENTS
! if (next_leader_len > 0) {
! (void)del_bytes((long)next_leader_len, FALSE, FALSE);
! mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
! (long)-next_leader_len);
! } else {
! #endif
! if (second_indent > 0) { // the "leader" for FO_Q_SECOND
! int indent = get_indent_lnum(curwin->w_cursor.lnum);
!
! if (indent > 0) {
! (void)del_bytes(indent, FALSE, FALSE);
! mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
(long)-indent);
! }
! }
! #ifdef FEAT_COMMENTS
! }
#endif
curwin->w_cursor.lnum--;
if (do_join(2, TRUE, FALSE, FALSE) == FAIL)
--
--
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/groups/opt_out.
diff -p ./src/ops.c.org ./src/ops.c
*** ./src/ops.c.org Sun Sep 1 12:29:50 2013
--- ./src/ops.c Sun Sep 1 13:55:24 2013
*************** format_lines(line_count, avoid_fex)
*** 4971,4977 ****
/*
* When still in same paragraph, join the lines together. But
! * first delete the comment leader from the second line.
*/
if (!is_end_par)
{
--- 4971,4977 ----
/*
* When still in same paragraph, join the lines together. But
! * first delete the leader from the second line.
*/
if (!is_end_par)
{
*************** format_lines(line_count, avoid_fex)
*** 4981,4990 ****
if (line_count < 0 && u_save_cursor() == FAIL)
break;
#ifdef FEAT_COMMENTS
! (void)del_bytes((long)next_leader_len, FALSE, FALSE);
! if (next_leader_len > 0)
! mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
! (long)-next_leader_len);
#endif
curwin->w_cursor.lnum--;
if (do_join(2, TRUE, FALSE, FALSE) == FAIL)
--- 4981,5002 ----
if (line_count < 0 && u_save_cursor() == FAIL)
break;
#ifdef FEAT_COMMENTS
! if (next_leader_len > 0) {
! (void)del_bytes((long)next_leader_len, FALSE, FALSE);
! mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
! (long)-next_leader_len);
! } else {
! #endif
! if (second_indent > 0) { // the "leader" for FO_Q_SECOND
! int indent = get_indent_lnum(curwin->w_cursor.lnum);
!
! if (indent > 0) {
! (void)del_bytes(indent, FALSE, FALSE);
! mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, (long)-indent);
! }
! }
! #ifdef FEAT_COMMENTS
! }
#endif
curwin->w_cursor.lnum--;
if (do_join(2, TRUE, FALSE, FALSE) == FAIL)
diff -p ./src/testdir/test68.in.org ./src/testdir/test68.in
*** ./src/testdir/test68.in.org Tue Apr 23 13:26:43 2013
--- ./src/testdir/test68.in Sun Sep 1 13:58:14 2013
*************** ENDTEST
*** 62,67 ****
--- 62,81 ----
}
STARTTEST
+ /^{/+3
+ :set tw=5 fo=t2a si
+ i A_
+ ENDTEST
+
+ {
+
+ x a
+ b
+ c
+
+ }
+
+ STARTTEST
/^{/+1
:set tw=5 fo=qn comments=:#
gwap
diff -p ./src/testdir/test68.ok.org ./src/testdir/test68.ok
*** ./src/testdir/test68.ok.org Tue Apr 23 13:26:43 2013
--- ./src/testdir/test68.ok Sun Sep 1 13:58:14 2013
*************** a b
*** 43,48 ****
--- 43,57 ----
{
+
+ x a
+ b_
+ c
+
+ }
+
+
+ {
# 1 a
# b
}