Skip to content

Commit cfe4565

Browse files
zeertzjqbrammool
authored andcommitted
patch 8.2.5029: "textlock" is always zero
Problem: "textlock" is always zero. Solution: Remove "textlock" and rename "textwinlock" to "textlock". (closes #10489)
1 parent 02e8d4e commit cfe4565

22 files changed

+51
-76
lines changed

runtime/doc/insert.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ Note: The keys that are valid in CTRL-X mode are not mapped. This allows for
671671
ends CTRL-X mode (any key that is not a valid CTRL-X mode command) is mapped.
672672
Also, when doing completion with 'complete' mappings apply as usual.
673673

674-
*E578* *E565*
674+
*E565*
675675
Note: While completion is active Insert mode can't be used recursively and
676676
buffer text cannot be changed. Mappings that somehow invoke ":normal i.."
677677
will generate an E565 error.

runtime/doc/tags

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4749,7 +4749,6 @@ E574 starting.txt /*E574*
47494749
E575 starting.txt /*E575*
47504750
E576 starting.txt /*E576*
47514751
E577 starting.txt /*E577*
4752-
E578 insert.txt /*E578*
47534752
E579 eval.txt /*E579*
47544753
E580 eval.txt /*E580*
47554754
E581 eval.txt /*E581*

src/beval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ general_beval_cb(BalloonEval *beval, int state UNUSED)
284284
curbuf = save_curbuf;
285285
if (use_sandbox)
286286
++sandbox;
287-
++textwinlock;
287+
++textlock;
288288

289289
if (bexpr == p_bexpr)
290290
{
@@ -311,7 +311,7 @@ general_beval_cb(BalloonEval *beval, int state UNUSED)
311311

312312
if (use_sandbox)
313313
--sandbox;
314-
--textwinlock;
314+
--textlock;
315315
current_sctx = save_sctx;
316316

317317
set_vim_var_string(VV_BEVAL_TEXT, NULL, -1);

src/change.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ f_listener_remove(typval_T *argvars, typval_T *rettv)
324324
next = lnr->lr_next;
325325
if (lnr->lr_id == id)
326326
{
327-
if (textwinlock > 0)
327+
if (textlock > 0)
328328
{
329329
// in invoke_listeners(), clear ID and delete later
330330
lnr->lr_id = 0;
@@ -401,7 +401,7 @@ invoke_listeners(buf_T *buf)
401401

402402
argv[4].v_type = VAR_LIST;
403403
argv[4].vval.v_list = buf->b_recorded_changes;
404-
++textwinlock;
404+
++textlock;
405405

406406
for (lnr = buf->b_listener; lnr != NULL; lnr = lnr->lr_next)
407407
{
@@ -421,7 +421,7 @@ invoke_listeners(buf_T *buf)
421421
prev = lnr;
422422
}
423423

424-
--textwinlock;
424+
--textlock;
425425
list_unref(buf->b_recorded_changes);
426426
buf->b_recorded_changes = NULL;
427427

src/edit.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ edit(
168168
// Don't allow changes in the buffer while editing the cmdline. The
169169
// caller of getcmdline() may get confused.
170170
// Don't allow recursive insert mode when busy with completion.
171-
if (textwinlock != 0 || textlock != 0
172-
|| ins_compl_active() || compl_busy || pum_visible())
171+
if (textlock != 0 || ins_compl_active() || compl_busy || pum_visible())
173172
{
174173
emsg(_(e_not_allowed_to_change_text_or_change_window));
175174
return FALSE;
@@ -5342,7 +5341,7 @@ do_insert_char_pre(int c)
53425341
}
53435342

53445343
// Lock the text to avoid weird things from happening.
5345-
++textwinlock;
5344+
++textlock;
53465345
set_vim_var_string(VV_CHAR, buf, -1); // set v:char
53475346

53485347
res = NULL;
@@ -5356,7 +5355,7 @@ do_insert_char_pre(int c)
53565355
}
53575356

53585357
set_vim_var_string(VV_CHAR, NULL, -1); // clear v:char
5359-
--textwinlock;
5358+
--textlock;
53605359

53615360
// Restore the State, it may have been changed.
53625361
State = save_State;

src/errors.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,8 +1458,7 @@ EXTERN char e_nonr_missing_gt[]
14581458
EXTERN char e_illegal_register_name[]
14591459
INIT(= N_("Illegal register name"));
14601460
#endif
1461-
EXTERN char e_not_allowed_to_change_text_here[]
1462-
INIT(= N_("E578: Not allowed to change text here"));
1461+
// E578 unused
14631462
#ifdef FEAT_EVAL
14641463
EXTERN char e_if_nesting_too_deep[]
14651464
INIT(= N_("E579: :if nesting too deep"));

src/eval.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ eval_to_string(
543543

544544
/*
545545
* Call eval_to_string() without using current local variables and using
546-
* textwinlock. When "use_sandbox" is TRUE use the sandbox.
546+
* textlock. When "use_sandbox" is TRUE use the sandbox.
547547
* Use legacy Vim script syntax.
548548
*/
549549
char_u *
@@ -562,12 +562,12 @@ eval_to_string_safe(
562562
save_funccal(&funccal_entry);
563563
if (use_sandbox)
564564
++sandbox;
565-
++textwinlock;
565+
++textlock;
566566
may_garbage_collect = FALSE;
567567
retval = eval_to_string(arg, FALSE);
568568
if (use_sandbox)
569569
--sandbox;
570-
--textwinlock;
570+
--textlock;
571571
may_garbage_collect = save_garbage;
572572
restore_funccal();
573573
current_sctx.sc_version = save_sc_version;
@@ -807,7 +807,7 @@ eval_foldexpr(win_T *wp, int *cp)
807807
++emsg_off;
808808
if (use_sandbox)
809809
++sandbox;
810-
++textwinlock;
810+
++textlock;
811811
*cp = NUL;
812812
if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL)
813813
retval = 0;
@@ -832,7 +832,7 @@ eval_foldexpr(win_T *wp, int *cp)
832832
--emsg_off;
833833
if (use_sandbox)
834834
--sandbox;
835-
--textwinlock;
835+
--textlock;
836836
clear_evalarg(&EVALARG_EVALUATE, NULL);
837837
current_sctx = saved_sctx;
838838

src/ex_cmds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4414,14 +4414,14 @@ ex_substitute(exarg_T *eap)
44144414
subflags_save = subflags;
44154415

44164416
// Disallow changing text or switching window in an expression.
4417-
++textwinlock;
4417+
++textlock;
44184418
#endif
44194419
// get length of substitution part
44204420
sublen = vim_regsub_multi(&regmatch,
44214421
sub_firstlnum - regmatch.startpos[0].lnum,
44224422
sub, sub_firstline, FALSE, magic_isset(), TRUE);
44234423
#ifdef FEAT_EVAL
4424-
--textwinlock;
4424+
--textlock;
44254425

44264426
// If getting the substitute string caused an error, don't do
44274427
// the replacement.
@@ -4524,13 +4524,13 @@ ex_substitute(exarg_T *eap)
45244524
new_end += copy_len;
45254525

45264526
#ifdef FEAT_EVAL
4527-
++textwinlock;
4527+
++textlock;
45284528
#endif
45294529
(void)vim_regsub_multi(&regmatch,
45304530
sub_firstlnum - regmatch.startpos[0].lnum,
45314531
sub, new_end, TRUE, magic_isset(), TRUE);
45324532
#ifdef FEAT_EVAL
4533-
--textwinlock;
4533+
--textlock;
45344534
#endif
45354535
sub_nsubs++;
45364536
did_sub = TRUE;

src/ex_getln.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -850,12 +850,12 @@ cmdline_handle_backslash_key(int c, int *gotesc)
850850
c = get_expr_register();
851851
if (c == '=')
852852
{
853-
// Need to save and restore ccline. And set "textwinlock"
853+
// Need to save and restore ccline. And set "textlock"
854854
// to avoid nasty things like going to another buffer when
855855
// evaluating an expression.
856-
++textwinlock;
856+
++textlock;
857857
p = get_expr_line();
858-
--textwinlock;
858+
--textlock;
859859

860860
if (p != NULL)
861861
{
@@ -2710,13 +2710,13 @@ check_opt_wim(void)
27102710
* 'balloonexpr', etc.
27112711
*/
27122712
int
2713-
text_and_win_locked(void)
2713+
text_locked(void)
27142714
{
27152715
#ifdef FEAT_CMDWIN
27162716
if (cmdwin_type != 0)
27172717
return TRUE;
27182718
#endif
2719-
return textwinlock != 0;
2719+
return textlock != 0;
27202720
}
27212721

27222722
/*
@@ -2736,19 +2736,7 @@ get_text_locked_msg(void)
27362736
if (cmdwin_type != 0)
27372737
return e_invalid_in_cmdline_window;
27382738
#endif
2739-
if (textwinlock != 0)
2740-
return e_not_allowed_to_change_text_or_change_window;
2741-
return e_not_allowed_to_change_text_here;
2742-
}
2743-
2744-
/*
2745-
* Return TRUE when the text must not be changed and/or we cannot switch to
2746-
* another window. TRUE while evaluating 'completefunc'.
2747-
*/
2748-
int
2749-
text_locked(void)
2750-
{
2751-
return text_and_win_locked() || textlock != 0;
2739+
return e_not_allowed_to_change_text_or_change_window;
27522740
}
27532741

27542742
/*
@@ -3730,11 +3718,11 @@ cmdline_paste(
37303718
regname = may_get_selection(regname);
37313719
#endif
37323720

3733-
// Need to set "textwinlock" to avoid nasty things like going to another
3721+
// Need to set "textlock" to avoid nasty things like going to another
37343722
// buffer when evaluating an expression.
3735-
++textwinlock;
3723+
++textlock;
37363724
i = get_spec_reg(regname, &arg, &allocated, TRUE);
3737-
--textwinlock;
3725+
--textlock;
37383726

37393727
if (i)
37403728
{

src/globals.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -846,16 +846,11 @@ EXTERN int secure INIT(= FALSE);
846846
// allowed, e.g. when sourcing .exrc or .vimrc
847847
// in current directory
848848

849-
EXTERN int textwinlock INIT(= 0);
849+
EXTERN int textlock INIT(= 0);
850850
// non-zero when changing text and jumping to
851851
// another window or editing another buffer is
852852
// not allowed
853853

854-
EXTERN int textlock INIT(= 0);
855-
// non-zero when changing text is not allowed,
856-
// jumping to another window is allowed,
857-
// editing another buffer is not allowed.
858-
859854
EXTERN int curbuf_lock INIT(= 0);
860855
// non-zero when the current buffer can't be
861856
// changed. Used for FileChangedRO.

src/indent.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ get_expr_indent(void)
18721872
set_vim_var_nr(VV_LNUM, curwin->w_cursor.lnum);
18731873
if (use_sandbox)
18741874
++sandbox;
1875-
++textwinlock;
1875+
++textlock;
18761876
current_sctx = curbuf->b_p_script_ctx[BV_INDE];
18771877

18781878
// Need to make a copy, the 'indentexpr' option could be changed while
@@ -1886,7 +1886,7 @@ get_expr_indent(void)
18861886

18871887
if (use_sandbox)
18881888
--sandbox;
1889-
--textwinlock;
1889+
--textlock;
18901890
current_sctx = save_sctx;
18911891

18921892
// Restore the cursor position so that 'indentexpr' doesn't need to.

src/insexpand.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,9 +1144,9 @@ trigger_complete_changed_event(int cur)
11441144
dict_set_items_ro(v_event);
11451145

11461146
recursive = TRUE;
1147-
textwinlock++;
1147+
textlock++;
11481148
apply_autocmds(EVENT_COMPLETECHANGED, NULL, NULL, FALSE, curbuf);
1149-
textwinlock--;
1149+
textlock--;
11501150
recursive = FALSE;
11511151

11521152
restore_v_event(v_event, &save_v_event);
@@ -2643,7 +2643,7 @@ expand_by_function(int type, char_u *base)
26432643
// Lock the text to avoid weird things from happening. Also disallow
26442644
// switching to another window, it should not be needed and may end up in
26452645
// Insert mode in another buffer.
2646-
++textwinlock;
2646+
++textlock;
26472647

26482648
cb = get_insert_callback(type);
26492649
retval = call_callback(cb, 0, &rettv, 2, args);
@@ -2669,7 +2669,7 @@ expand_by_function(int type, char_u *base)
26692669
break;
26702670
}
26712671
}
2672-
--textwinlock;
2672+
--textlock;
26732673

26742674
curwin->w_cursor = pos; // restore the cursor position
26752675
validate_cursor();
@@ -2867,7 +2867,6 @@ set_completion(colnr_T startcol, list_T *list)
28672867
f_complete(typval_T *argvars, typval_T *rettv UNUSED)
28682868
{
28692869
int startcol;
2870-
int save_textlock = textlock;
28712870

28722871
if (in_vim9script()
28732872
&& (check_for_number_arg(argvars, 0) == FAIL
@@ -2880,10 +2879,6 @@ f_complete(typval_T *argvars, typval_T *rettv UNUSED)
28802879
return;
28812880
}
28822881

2883-
// "textlock" is set when evaluating 'completefunc' but we can change
2884-
// text here.
2885-
textlock = 0;
2886-
28872882
// Check for undo allowed here, because if something was already inserted
28882883
// the line was already saved for undo and this check isn't done.
28892884
if (!undo_allowed())
@@ -2897,7 +2892,6 @@ f_complete(typval_T *argvars, typval_T *rettv UNUSED)
28972892
if (startcol > 0)
28982893
set_completion(startcol - 1, argvars[1].vval.v_list);
28992894
}
2900-
textlock = save_textlock;
29012895
}
29022896

29032897
/*
@@ -4508,10 +4502,10 @@ get_userdefined_compl_info(colnr_T curs_col UNUSED)
45084502
args[1].vval.v_string = (char_u *)"";
45094503
args[2].v_type = VAR_UNKNOWN;
45104504
pos = curwin->w_cursor;
4511-
++textwinlock;
4505+
++textlock;
45124506
cb = get_insert_callback(ctrl_x_mode);
45134507
col = call_callback_retnr(cb, 2, args);
4514-
--textwinlock;
4508+
--textlock;
45154509

45164510
State = save_State;
45174511
curwin->w_cursor = pos; // restore the cursor position

src/map.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,7 @@ eval_map_expr(
16951695

16961696
// Forbid changing text or using ":normal" to avoid most of the bad side
16971697
// effects. Also restore the cursor position.
1698-
++textwinlock;
1698+
++textlock;
16991699
++ex_normal_lock;
17001700
set_vim_var_char(c); // set v:char to the typed character
17011701
save_cursor = curwin->w_cursor;
@@ -1710,7 +1710,7 @@ eval_map_expr(
17101710
// Note: the evaluation may make "mp" invalid.
17111711
p = eval_to_string(expr, FALSE);
17121712

1713-
--textwinlock;
1713+
--textlock;
17141714
--ex_normal_lock;
17151715
curwin->w_cursor = save_cursor;
17161716
msg_col = save_msg_col;

src/proto/ex_getln.pro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ void cmdline_init(void);
33
char_u *getcmdline(int firstc, long count, int indent, getline_opt_T do_concat);
44
char_u *getcmdline_prompt(int firstc, char_u *prompt, int attr, int xp_context, char_u *xp_arg);
55
int check_opt_wim(void);
6-
int text_and_win_locked(void);
76
void text_locked_msg(void);
87
char *get_text_locked_msg(void);
98
int text_locked(void);

src/register.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,9 @@ yank_do_autocmd(oparg_T *oap, yankreg_T *reg)
10551055
dict_set_items_ro(v_event);
10561056

10571057
recursive = TRUE;
1058-
textwinlock++;
1058+
textlock++;
10591059
apply_autocmds(EVENT_TEXTYANKPOST, NULL, NULL, FALSE, curbuf);
1060-
textwinlock--;
1060+
textlock--;
10611061
recursive = FALSE;
10621062

10631063
// Empty the dictionary, v:event is still valid

src/testdir/test_edit.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ func Test_edit_completefunc_delete()
10411041
set completefunc=CompleteFunc
10421042
call setline(1, ['', 'abcd', ''])
10431043
2d
1044-
call assert_fails("normal 2G$a\<C-X>\<C-U>", 'E578:')
1044+
call assert_fails("normal 2G$a\<C-X>\<C-U>", 'E565:')
10451045
bwipe!
10461046
endfunc
10471047

0 commit comments

Comments
 (0)