vim-patch:7.4.267

Problem:    The '[ mark is in the wrong position after "gq". (Ingo Karkat)
Solution:   Add the setmark argument to do_join(). (Christian Brabandt)

https://code.google.com/p/vim/source/detail?r=75f222d67cea335efbe0274de6340dba174c1e7e
This commit is contained in:
oni-link
2014-05-22 14:37:27 +02:00
committed by Justin M. Keyes
parent 1b43e5c47e
commit 753401ab4c
10 changed files with 72 additions and 29 deletions

View File

@@ -7244,11 +7244,12 @@ static void ins_del(void)
return; return;
if (gchar_cursor() == NUL) { /* delete newline */ if (gchar_cursor() == NUL) { /* delete newline */
temp = curwin->w_cursor.col; temp = curwin->w_cursor.col;
if (!can_bs(BS_EOL) /* only if "eol" included */ if (!can_bs(BS_EOL) // only if "eol" included
|| do_join(2, FALSE, TRUE, FALSE) == FAIL) || do_join(2, FALSE, TRUE, FALSE, false) == FAIL) {
vim_beep(); vim_beep();
else } else {
curwin->w_cursor.col = temp; curwin->w_cursor.col = temp;
}
} else if (del_char(FALSE) == FAIL) /* delete char under cursor */ } else if (del_char(FALSE) == FAIL) /* delete char under cursor */
vim_beep(); vim_beep();
did_ai = FALSE; did_ai = FALSE;
@@ -7387,7 +7388,7 @@ static int ins_bs(int c, int mode, int *inserted_space_p)
ptr[len - 1] = NUL; ptr[len - 1] = NUL;
} }
(void)do_join(2, FALSE, FALSE, FALSE); do_join(2, FALSE, FALSE, FALSE, false);
if (temp == NUL && gchar_cursor() != NUL) if (temp == NUL && gchar_cursor() != NUL)
inc_cursor(); inc_cursor();
} else } else

View File

@@ -3588,7 +3588,7 @@ void do_sub(exarg_T *eap)
eap->flags = EXFLAG_PRINT; eap->flags = EXFLAG_PRINT;
} }
do_join(eap->line2 - eap->line1 + 1, FALSE, TRUE, FALSE); do_join(eap->line2 - eap->line1 + 1, FALSE, TRUE, FALSE, true);
sub_nlines = sub_nsubs = eap->line2 - eap->line1 + 1; sub_nlines = sub_nsubs = eap->line2 - eap->line1 + 1;
do_sub_msg(FALSE); do_sub_msg(FALSE);
ex_may_print(eap); ex_may_print(eap);

View File

@@ -6804,7 +6804,7 @@ static void ex_join(exarg_T *eap)
} }
++eap->line2; ++eap->line2;
} }
(void)do_join(eap->line2 - eap->line1 + 1, !eap->forceit, TRUE, TRUE); do_join(eap->line2 - eap->line1 + 1, !eap->forceit, TRUE, TRUE, true);
beginline(BL_WHITE | BL_FIX); beginline(BL_WHITE | BL_FIX);
ex_may_print(eap); ex_may_print(eap);
} }

View File

@@ -730,7 +730,7 @@ getcount:
} }
if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) { if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) {
/* This command is not allowed while editing a ccmdline: beep. */ // This command is not allowed while editing a cmdline: beep.
clearopbeep(oap); clearopbeep(oap);
text_locked_msg(); text_locked_msg();
goto normal_end; goto normal_end;
@@ -1622,7 +1622,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
curbuf->b_ml.ml_line_count) curbuf->b_ml.ml_line_count)
beep_flush(); beep_flush();
else { else {
(void)do_join(oap->line_count, oap->op_type == OP_JOIN, TRUE, TRUE); do_join(oap->line_count, oap->op_type == OP_JOIN, TRUE, TRUE, true);
auto_format(FALSE, TRUE); auto_format(FALSE, TRUE);
} }
break; break;
@@ -7326,7 +7326,7 @@ static void nv_join(cmdarg_T *cap)
else { else {
prep_redo(cap->oap->regname, cap->count0, prep_redo(cap->oap->regname, cap->count0,
NUL, cap->cmdchar, NUL, NUL, cap->nchar); NUL, cap->cmdchar, NUL, NUL, cap->nchar);
(void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE); do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, true);
} }
} }
} }

View File

@@ -1623,8 +1623,9 @@ int op_delete(oparg_T *oap)
); );
curwin->w_cursor = curpos; /* restore curwin->w_cursor */ curwin->w_cursor = curpos; /* restore curwin->w_cursor */
} }
if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) {
(void)do_join(2, FALSE, FALSE, FALSE); do_join(2, FALSE, FALSE, FALSE, false);
}
} }
} }
@@ -3381,15 +3382,19 @@ static char_u *skip_comment(char_u *line, int process, int include_space, int *i
return line; return line;
} }
/* // Join 'count' lines (minimal 2) at cursor position.
* Join 'count' lines (minimal 2) at cursor position. // When "save_undo" is TRUE save lines for undo first.
* When "save_undo" is TRUE save lines for undo first. // Set "use_formatoptions" to FALSE when e.g. processing backspace and comment
* Set "use_formatoptions" to FALSE when e.g. processing // leaders should not be removed.
* backspace and comment leaders should not be removed. // When setmark is true, sets the '[ and '] mark, else, the caller is expected
* // to set those marks.
* return FAIL for failure, OK otherwise //
*/ // return FAIL for failure, OK otherwise
int do_join(long count, int insert_space, int save_undo, int use_formatoptions) int do_join(long count,
int insert_space,
int save_undo,
int use_formatoptions,
bool setmark)
{ {
char_u *curr = NULL; char_u *curr = NULL;
char_u *curr_start = NULL; char_u *curr_start = NULL;
@@ -3427,7 +3432,7 @@ int do_join(long count, int insert_space, int save_undo, int use_formatoptions)
*/ */
for (t = 0; t < count; ++t) { for (t = 0; t < count; ++t) {
curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t));
if (t == 0) { if (t == 0 && setmark) {
// Set the '[ mark. // Set the '[ mark.
curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum;
curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr);
@@ -3527,9 +3532,11 @@ int do_join(long count, int insert_space, int save_undo, int use_formatoptions)
} }
ml_replace(curwin->w_cursor.lnum, newp, FALSE); ml_replace(curwin->w_cursor.lnum, newp, FALSE);
if (setmark) {
// Set the '] mark. // Set the '] mark.
curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum;
curwin->w_buffer->b_op_end.col = (colnr_T)STRLEN(newp); curwin->w_buffer->b_op_end.col = (colnr_T)STRLEN(newp);
}
/* Only report the change in the first line here, del_lines() will report /* Only report the change in the first line here, del_lines() will report
* the deleted line. */ * the deleted line. */
@@ -3953,7 +3960,7 @@ format_lines (
} }
} }
curwin->w_cursor.lnum--; curwin->w_cursor.lnum--;
if (do_join(2, TRUE, FALSE, FALSE) == FAIL) { if (do_join(2, TRUE, FALSE, FALSE, false) == FAIL) {
beep_flush(); beep_flush();
break; break;
} }

View File

@@ -40,8 +40,11 @@ void adjust_cursor_eol(void);
int preprocs_left(void); int preprocs_left(void);
int get_register_name(int num); int get_register_name(int num);
void ex_display(exarg_T *eap); void ex_display(exarg_T *eap);
int do_join(long count, int insert_space, int save_undo, int do_join(long count,
int use_formatoptions); int insert_space,
int save_undo,
int use_formatoptions,
bool setmark);
void op_format(oparg_T *oap, int keep_cursor); void op_format(oparg_T *oap, int keep_cursor);
void op_formatexpr(oparg_T *oap); void op_formatexpr(oparg_T *oap);
int fex_format(linenr_T lnum, long count, int c); int fex_format(linenr_T lnum, long count, int c);

View File

@@ -6,7 +6,8 @@ export SHELL := sh
VIMPROG := ../../../build/bin/nvim VIMPROG := ../../../build/bin/nvim
SCRIPTS := test_eval.out \ SCRIPTS := test_autoformat_join.out \
test_eval.out \
test1.out test2.out test3.out test4.out test5.out \ test1.out test2.out test3.out test4.out test5.out \
test6.out test7.out test8.out test9.out test10.out \ test6.out test7.out test8.out test9.out test10.out \
test11.out test12.out test13.out test14.out test15.out \ test11.out test12.out test13.out test14.out test15.out \

View File

@@ -0,0 +1,23 @@
Tests for setting the '[,'] marks when joining lines.
STARTTEST
:so small.vim
:/^\t\t/
0gqj
:let a=string(getpos("'[")).'/'.string(getpos("']"))
:/^This line/;'}-join
:let b=string(getpos("'[")).'/'.string(getpos("']"))
:$put ='First test: Start/End '.string(a)
:$put ='Second test: Start/End '.string(b)
:/^\t\t/,$wq! test.out
ENDTEST
O sodales, ludite, vos qui
attamen consulite per voster honur. Tua pulchra facies me fay planszer milies
This line.
Should be joined with the next line
and with this line
Results:

View File

@@ -0,0 +1,8 @@
O sodales, ludite, vos qui attamen consulite per voster honur.
Tua pulchra facies me fay planszer milies
This line. Should be joined with the next line and with this line
Results:
First test: Start/End '[0, 16, 1, 0]/[0, 17, 1, 0]'
Second test: Start/End '[0, 19, 11, 0]/[0, 19, 67, 0]'

View File

@@ -219,7 +219,7 @@ static int included_patches[] = {
//270, //270,
269, 269,
268, 268,
//267, 267,
266, 266,
265, 265,
264, 264,