mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
updated for version 7.4.052
Problem: With 'fo' set to "a2" inserting a space in the first column may cause the cursor to jump to the previous line. Solution: Handle the case when there is no comment leader properly. (Tor Perkins) Also fix that cursor is in the wrong place when spaces get replaced with a Tab.
This commit is contained in:
22
src/misc1.c
22
src/misc1.c
@@ -303,10 +303,18 @@ set_indent(size, flags)
|
|||||||
ml_replace(curwin->w_cursor.lnum, newline, FALSE);
|
ml_replace(curwin->w_cursor.lnum, newline, FALSE);
|
||||||
if (flags & SIN_CHANGED)
|
if (flags & SIN_CHANGED)
|
||||||
changed_bytes(curwin->w_cursor.lnum, 0);
|
changed_bytes(curwin->w_cursor.lnum, 0);
|
||||||
/* Correct saved cursor position if it's after the indent. */
|
/* Correct saved cursor position if it is in this line. */
|
||||||
if (saved_cursor.lnum == curwin->w_cursor.lnum
|
if (saved_cursor.lnum == curwin->w_cursor.lnum)
|
||||||
&& saved_cursor.col >= (colnr_T)(p - oldline))
|
{
|
||||||
saved_cursor.col += ind_len - (colnr_T)(p - oldline);
|
if (saved_cursor.col >= (colnr_T)(p - oldline))
|
||||||
|
/* cursor was after the indent, adjust for the number of
|
||||||
|
* bytes added/removed */
|
||||||
|
saved_cursor.col += ind_len - (colnr_T)(p - oldline);
|
||||||
|
else if (saved_cursor.col >= (colnr_T)(s - newline))
|
||||||
|
/* cursor was in the indent, and is now after it, put it back
|
||||||
|
* at the start of the indent (replacing spaces with TAB) */
|
||||||
|
saved_cursor.col = (colnr_T)(s - newline);
|
||||||
|
}
|
||||||
retval = TRUE;
|
retval = TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1581,9 +1589,9 @@ theend:
|
|||||||
|
|
||||||
#if defined(FEAT_COMMENTS) || defined(PROTO)
|
#if defined(FEAT_COMMENTS) || defined(PROTO)
|
||||||
/*
|
/*
|
||||||
* get_leader_len() returns the length of the prefix of the given string
|
* get_leader_len() returns the length in bytes of the prefix of the given
|
||||||
* which introduces a comment. If this string is not a comment then 0 is
|
* string which introduces a comment. If this string is not a comment then
|
||||||
* returned.
|
* 0 is returned.
|
||||||
* When "flags" is not NULL, it is set to point to the flags of the recognized
|
* When "flags" is not NULL, it is set to point to the flags of the recognized
|
||||||
* comment leader.
|
* comment leader.
|
||||||
* "backward" must be true for the "O" command.
|
* "backward" must be true for the "O" command.
|
||||||
|
18
src/ops.c
18
src/ops.c
@@ -4989,7 +4989,7 @@ format_lines(line_count, avoid_fex)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* When still in same paragraph, join the lines together. But
|
* When still in same paragraph, join the lines together. But
|
||||||
* first delete the comment leader from the second line.
|
* first delete the leader from the second line.
|
||||||
*/
|
*/
|
||||||
if (!is_end_par)
|
if (!is_end_par)
|
||||||
{
|
{
|
||||||
@@ -4999,11 +4999,25 @@ format_lines(line_count, avoid_fex)
|
|||||||
if (line_count < 0 && u_save_cursor() == FAIL)
|
if (line_count < 0 && u_save_cursor() == FAIL)
|
||||||
break;
|
break;
|
||||||
#ifdef FEAT_COMMENTS
|
#ifdef FEAT_COMMENTS
|
||||||
(void)del_bytes((long)next_leader_len, FALSE, FALSE);
|
|
||||||
if (next_leader_len > 0)
|
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,
|
mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
|
||||||
(long)-next_leader_len);
|
(long)-next_leader_len);
|
||||||
|
} else
|
||||||
#endif
|
#endif
|
||||||
|
if (second_indent > 0) /* the "leader" for FO_Q_SECOND */
|
||||||
|
{
|
||||||
|
char_u *p = ml_get_curline();
|
||||||
|
int indent = skipwhite(p) - p;
|
||||||
|
|
||||||
|
if (indent > 0)
|
||||||
|
{
|
||||||
|
(void)del_bytes(indent, FALSE, FALSE);
|
||||||
|
mark_col_adjust(curwin->w_cursor.lnum,
|
||||||
|
(colnr_T)0, 0L, (long)-indent);
|
||||||
|
}
|
||||||
|
}
|
||||||
curwin->w_cursor.lnum--;
|
curwin->w_cursor.lnum--;
|
||||||
if (do_join(2, TRUE, FALSE, FALSE) == FAIL)
|
if (do_join(2, TRUE, FALSE, FALSE) == FAIL)
|
||||||
{
|
{
|
||||||
|
@@ -61,6 +61,20 @@ ENDTEST
|
|||||||
# 1 a
|
# 1 a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STARTTEST
|
||||||
|
/^{/+3
|
||||||
|
:set tw=5 fo=t2a si
|
||||||
|
i A_
|
||||||
|
ENDTEST
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
x a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
STARTTEST
|
STARTTEST
|
||||||
/^{/+1
|
/^{/+1
|
||||||
:set tw=5 fo=qn comments=:#
|
:set tw=5 fo=qn comments=:#
|
||||||
|
@@ -42,6 +42,15 @@ a b
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
x a
|
||||||
|
b_
|
||||||
|
c
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
# 1 a
|
# 1 a
|
||||||
# b
|
# b
|
||||||
|
@@ -738,6 +738,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
52,
|
||||||
/**/
|
/**/
|
||||||
51,
|
51,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user