Greetings all,
Using auto-format with 2nd line indent (fo+=a2) works well, but there
is a situation where it's a little awkward...
Lets say we want to make a new paragraph with auto-format and 2nd line
indent that will end up looking something like this:
xx aaaa aaaa aaaa
bbbb bbbb bbbb
cccc cccc cccc
To get started, lets also turn on smartindent:
vi:textwidth=25:formatoptions=a2:smartindent
xx aaaa aaaa aaaa
bbbb
Above, we see that as we enter the text, since there is not yet a 2nd
line, smartindent wraps the text to the same indent as the 1st line
(no problem).
The problem occurs if you attempt to adjust the 2nd line indent by
inserting a space at column 1 on the 2nd line (i.e. you stay in insert
mode and just hit <Home><Space>). The text becomes:
xx aaaa aaaa aaaa
bbbb
... Which is OK. What's not OK is that the cursor is positioned on
the 1st line on the 3rd char from the end. This is surprising and it
makes it awkward to insert more space chars at the beginning of the 2nd
line as the cursor jumps up to the 1st line with each new space char.
This problem does not happen if the text is in a comment. If we turn
on all of the cool comment handling features, like so:
:set formatoptions+=cjoqr
After repeating the above (but with a preceding comment char), we see
this result:
# xx aaaa aaaa aaaa
# bbbb
... But this time the cursor stays on the 2nd line and jumps from
column 1 to column 6 (the 1st 'b', which is OK). Subsequent inserted
space chars offer no surprise cursor jumps (the cursor stays on the
1st 'b' as one would expect).
Please find the attached diff that makes the non-comment behavior
match the comment behavior. The diff also includes a new test case.
The patch tries to mimic what was happening when comments are turned
on and it survives a 'make test' as of v.7.3.905.
Thank you for your time and consideration!
- Tor
--
--
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 Tue Apr 23 13:26:43 2013
--- ./src/ops.c Thu Apr 25 14:48:52 2013
*************** format_lines(line_count, avoid_fex)
*** 4960,4966 ****
/*
* When still in same paragraph, join the lines together. But
! * first delete the comment leader from the second line.
*/
if (!is_end_par)
{
--- 4960,4966 ----
/*
* 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)
*** 4970,4979 ****
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)
--- 4970,4991 ----
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 Thu Apr 25 14:33:39 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 Thu Apr 25 14:34:12 2013
*************** a b
*** 43,48 ****
--- 43,57 ----
{
+
+ x a
+ b_
+ c
+
+ }
+
+
+ {
# 1 a
# b
}