@@ -749,8 +749,11 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
749749 foldMoveRange (& win -> w_folds , line1 , line2 , dest );
750750 }
751751#endif
752- curbuf -> b_op_start .lnum = dest - num_lines + 1 ;
753- curbuf -> b_op_end .lnum = dest ;
752+ if (!cmdmod .lockmarks )
753+ {
754+ curbuf -> b_op_start .lnum = dest - num_lines + 1 ;
755+ curbuf -> b_op_end .lnum = dest ;
756+ }
754757 }
755758 else
756759 {
@@ -761,10 +764,14 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
761764 foldMoveRange (& win -> w_folds , dest + 1 , line1 - 1 , line2 );
762765 }
763766#endif
764- curbuf -> b_op_start .lnum = dest + 1 ;
765- curbuf -> b_op_end .lnum = dest + num_lines ;
767+ if (!cmdmod .lockmarks )
768+ {
769+ curbuf -> b_op_start .lnum = dest + 1 ;
770+ curbuf -> b_op_end .lnum = dest + num_lines ;
771+ }
766772 }
767- curbuf -> b_op_start .col = curbuf -> b_op_end .col = 0 ;
773+ if (!cmdmod .lockmarks )
774+ curbuf -> b_op_start .col = curbuf -> b_op_end .col = 0 ;
768775 mark_adjust_nofold (last_line - num_lines + 1 , last_line ,
769776 - (last_line - dest - extra ), 0L );
770777
@@ -813,9 +820,12 @@ ex_copy(linenr_T line1, linenr_T line2, linenr_T n)
813820 char_u * p ;
814821
815822 count = line2 - line1 + 1 ;
816- curbuf -> b_op_start .lnum = n + 1 ;
817- curbuf -> b_op_end .lnum = n + count ;
818- curbuf -> b_op_start .col = curbuf -> b_op_end .col = 0 ;
823+ if (!cmdmod .lockmarks )
824+ {
825+ curbuf -> b_op_start .lnum = n + 1 ;
826+ curbuf -> b_op_end .lnum = n + count ;
827+ curbuf -> b_op_start .col = curbuf -> b_op_end .col = 0 ;
828+ }
819829
820830 /*
821831 * there are three situations:
@@ -1055,10 +1065,17 @@ do_filter(
10551065 char_u * cmd_buf ;
10561066 buf_T * old_curbuf = curbuf ;
10571067 int shell_flags = 0 ;
1068+ pos_T orig_start = curbuf -> b_op_start ;
1069+ pos_T orig_end = curbuf -> b_op_end ;
1070+ int save_lockmarks = cmdmod .lockmarks ;
10581071
10591072 if (* cmd == NUL ) /* no filter command */
10601073 return ;
10611074
1075+ // Temporarily disable lockmarks since that's needed to propagate changed
1076+ // regions of the buffer for foldUpdate(), linecount, etc.
1077+ cmdmod .lockmarks = 0 ;
1078+
10621079 cursor_save = curwin -> w_cursor ;
10631080 linecount = line2 - line1 + 1 ;
10641081 curwin -> w_cursor .lnum = line1 ;
@@ -1287,11 +1304,18 @@ do_filter(
12871304
12881305filterend :
12891306
1307+ cmdmod .lockmarks = save_lockmarks ;
12901308 if (curbuf != old_curbuf )
12911309 {
12921310 -- no_wait_return ;
12931311 emsg (_ ("E135: *Filter* Autocommands must not change current buffer" ));
12941312 }
1313+ else if (cmdmod .lockmarks )
1314+ {
1315+ curbuf -> b_op_start = orig_start ;
1316+ curbuf -> b_op_end = orig_end ;
1317+ }
1318+
12951319 if (itmp != NULL )
12961320 mch_remove (itmp );
12971321 if (otmp != NULL )
@@ -3276,13 +3300,16 @@ ex_append(exarg_T *eap)
32763300 * eap->line2 pointed to the end of the buffer and nothing was appended)
32773301 * "end" is set to lnum when something has been appended, otherwise
32783302 * it is the same than "start" -- Acevedo */
3279- curbuf -> b_op_start .lnum = (eap -> line2 < curbuf -> b_ml .ml_line_count ) ?
3280- eap -> line2 + 1 : curbuf -> b_ml .ml_line_count ;
3281- if (eap -> cmdidx != CMD_append )
3282- -- curbuf -> b_op_start .lnum ;
3283- curbuf -> b_op_end .lnum = (eap -> line2 < lnum )
3284- ? lnum : curbuf -> b_op_start .lnum ;
3285- curbuf -> b_op_start .col = curbuf -> b_op_end .col = 0 ;
3303+ if (!cmdmod .lockmarks )
3304+ {
3305+ curbuf -> b_op_start .lnum = (eap -> line2 < curbuf -> b_ml .ml_line_count ) ?
3306+ eap -> line2 + 1 : curbuf -> b_ml .ml_line_count ;
3307+ if (eap -> cmdidx != CMD_append )
3308+ -- curbuf -> b_op_start .lnum ;
3309+ curbuf -> b_op_end .lnum = (eap -> line2 < lnum )
3310+ ? lnum : curbuf -> b_op_start .lnum ;
3311+ curbuf -> b_op_start .col = curbuf -> b_op_end .col = 0 ;
3312+ }
32863313 curwin -> w_cursor .lnum = lnum ;
32873314 check_cursor_lnum ();
32883315 beginline (BL_SOL | BL_FIX );
@@ -4592,10 +4619,13 @@ do_sub(exarg_T *eap)
45924619
45934620 if (sub_nsubs > start_nsubs )
45944621 {
4595- /* Set the '[ and '] marks. */
4596- curbuf -> b_op_start .lnum = eap -> line1 ;
4597- curbuf -> b_op_end .lnum = line2 ;
4598- curbuf -> b_op_start .col = curbuf -> b_op_end .col = 0 ;
4622+ if (!cmdmod .lockmarks )
4623+ {
4624+ // Set the '[ and '] marks.
4625+ curbuf -> b_op_start .lnum = eap -> line1 ;
4626+ curbuf -> b_op_end .lnum = line2 ;
4627+ curbuf -> b_op_start .col = curbuf -> b_op_end .col = 0 ;
4628+ }
45994629
46004630 if (!global_busy )
46014631 {
0 commit comments