1
0
forked from aniani/vim

patch 8.1.2302: :lockmarks does not work for '[ and ']

Problem:    :lockmarks does not work for '[ and '].
Solution:   save and restore '[ and '] marks. (James McCoy, closes #5222)
This commit is contained in:
Bram Moolenaar
2019-11-16 13:50:25 +01:00
parent ab85ca4e6a
commit f4a1d1c054
10 changed files with 208 additions and 69 deletions

View File

@@ -206,14 +206,15 @@ op_shift(oparg_T *oap, int curs_top, int amount)
msg((char *)IObuff);
}
/*
* Set "'[" and "']" marks.
*/
curbuf->b_op_start = oap->start;
curbuf->b_op_end.lnum = oap->end.lnum;
curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
if (curbuf->b_op_end.col > 0)
--curbuf->b_op_end.col;
if (!cmdmod.lockmarks)
{
// Set "'[" and "']" marks.
curbuf->b_op_start = oap->start;
curbuf->b_op_end.lnum = oap->end.lnum;
curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
if (curbuf->b_op_end.col > 0)
--curbuf->b_op_end.col;
}
}
/*
@@ -981,14 +982,17 @@ op_delete(oparg_T *oap)
msgmore(curbuf->b_ml.ml_line_count - old_lcount);
setmarks:
if (oap->block_mode)
if (!cmdmod.lockmarks)
{
curbuf->b_op_end.lnum = oap->end.lnum;
curbuf->b_op_end.col = oap->start.col;
if (oap->block_mode)
{
curbuf->b_op_end.lnum = oap->end.lnum;
curbuf->b_op_end.col = oap->start.col;
}
else
curbuf->b_op_end = oap->start;
curbuf->b_op_start = oap->start;
}
else
curbuf->b_op_end = oap->start;
curbuf->b_op_start = oap->start;
return OK;
}
@@ -1252,9 +1256,12 @@ op_replace(oparg_T *oap, int c)
check_cursor();
changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L);
/* Set "'[" and "']" marks. */
curbuf->b_op_start = oap->start;
curbuf->b_op_end = oap->end;
if (!cmdmod.lockmarks)
{
/* Set "'[" and "']" marks. */
curbuf->b_op_start = oap->start;
curbuf->b_op_end = oap->end;
}
return OK;
}
@@ -1362,11 +1369,12 @@ op_tilde(oparg_T *oap)
/* No change: need to remove the Visual selection */
redraw_curbuf_later(INVERTED);
/*
* Set '[ and '] marks.
*/
curbuf->b_op_start = oap->start;
curbuf->b_op_end = oap->end;
if (!cmdmod.lockmarks)
{
// Set '[ and '] marks.
curbuf->b_op_start = oap->start;
curbuf->b_op_end = oap->end;
}
if (oap->line_count > p_report)
smsg(NGETTEXT("%ld line changed", "%ld lines changed",
@@ -1973,7 +1981,7 @@ do_join(
for (t = 0; t < count; ++t)
{
curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t));
if (t == 0 && setmark)
if (t == 0 && setmark && !cmdmod.lockmarks)
{
/* Set the '[ mark. */
curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum;
@@ -2129,7 +2137,7 @@ do_join(
#endif
ml_replace(curwin->w_cursor.lnum, newp, FALSE);
if (setmark)
if (setmark && !cmdmod.lockmarks)
{
/* Set the '] mark. */
curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum;
@@ -2268,8 +2276,9 @@ op_format(
/* When there is no change: need to remove the Visual selection */
redraw_curbuf_later(INVERTED);
/* Set '[ mark at the start of the formatted area */
curbuf->b_op_start = oap->start;
if (!cmdmod.lockmarks)
/* Set '[ mark at the start of the formatted area */
curbuf->b_op_start = oap->start;
/* For "gw" remember the cursor position and put it back below (adjusted
* for joined and split lines). */
@@ -2289,8 +2298,9 @@ op_format(
old_line_count = curbuf->b_ml.ml_line_count - old_line_count;
msgmore(old_line_count);
/* put '] mark on the end of the formatted area */
curbuf->b_op_end = curwin->w_cursor;
if (!cmdmod.lockmarks)
/* put '] mark on the end of the formatted area */
curbuf->b_op_end = curwin->w_cursor;
if (keep_cursor)
{
@@ -2984,7 +2994,7 @@ op_addsub(
/* Set '[ mark if something changed. Keep the last end
* position from do_addsub(). */
if (change_cnt > 0)
if (change_cnt > 0 && !cmdmod.lockmarks)
curbuf->b_op_start = startpos;
if (change_cnt > p_report)
@@ -3384,7 +3394,7 @@ do_addsub(
--curwin->w_cursor.col;
}
if (did_change)
if (did_change && !cmdmod.lockmarks)
{
/* set the '[ and '] marks */
curbuf->b_op_start = startpos;
@@ -3905,6 +3915,8 @@ op_function(oparg_T *oap UNUSED)
#ifdef FEAT_EVAL
typval_T argv[2];
int save_virtual_op = virtual_op;
pos_T orig_start = curbuf->b_op_start;
pos_T orig_end = curbuf->b_op_end;
if (*p_opfunc == NUL)
emsg(_("E774: 'operatorfunc' is empty"));
@@ -3933,6 +3945,11 @@ op_function(oparg_T *oap UNUSED)
(void)call_func_retnr(p_opfunc, 1, argv);
virtual_op = save_virtual_op;
if (cmdmod.lockmarks)
{
curbuf->b_op_start = orig_start;
curbuf->b_op_end = orig_end;
}
}
#else
emsg(_("E775: Eval feature not available"));