Skip to content

Commit 6d862f5

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.2.1164: Vim9: :append parsing depends on whether command is skipped
Problem: Vim9: :append parsing depends on whether command is skipped (after 9.2.1159). Solution: Do not discard text up to "." when skipping in Vim9 script (zeertzjq). closes: #21415 Signed-off-by: zeertzjq <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent f5f6d12 commit 6d862f5

7 files changed

Lines changed: 43 additions & 33 deletions

File tree

‎src/ex_cmds.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3642,6 +3642,10 @@ ex_append(exarg_T *eap)
36423642
int vcol;
36433643
int empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
36443644

3645+
#ifdef FEAT_EVAL
3646+
if (not_in_vim9(eap, eap->skip) == FAIL)
3647+
return;
3648+
#endif
36453649
if (eap->skip)
36463650
{
36473651
// Not executing the command, only read the lines up to the ".".
@@ -3655,10 +3659,7 @@ ex_append(exarg_T *eap)
36553659
}
36563660
return;
36573661
}
3658-
#ifdef FEAT_EVAL
3659-
if (not_in_vim9(eap) == FAIL)
3660-
return;
3661-
#endif
3662+
36623663
// the ! flag toggles autoindent
36633664
if (eap->forceit)
36643665
curbuf->b_p_ai = !curbuf->b_p_ai;
@@ -3777,15 +3778,15 @@ ex_change(exarg_T *eap)
37773778
{
37783779
linenr_T lnum;
37793780

3781+
#ifdef FEAT_EVAL
3782+
if (not_in_vim9(eap, eap->skip) == FAIL)
3783+
return;
3784+
#endif
37803785
if (eap->skip)
37813786
{
37823787
ex_append(eap);
37833788
return;
37843789
}
3785-
#ifdef FEAT_EVAL
3786-
if (not_in_vim9(eap) == FAIL)
3787-
return;
3788-
#endif
37893790
if (eap->line2 >= eap->line1
37903791
&& u_save(eap->line1 - 1, eap->line2 + 1) == FAIL)
37913792
return;

‎src/ex_docmd.c‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4374,7 +4374,7 @@ ex_command_info(char_u *name, int vim9, dict_T *d)
43744374
if (p == NULL || ea.cmdidx == CMD_SIZE
43754375
|| (vim_isdigit(*name) && ea.cmdidx != CMD_match)
43764376
|| *skipwhite(p) != NUL
4377-
|| not_in_vim9(&ea) == FAIL)
4377+
|| not_in_vim9(&ea, true) == FAIL)
43784378
ret = FAIL;
43794379
--emsg_silent;
43804380

@@ -4446,17 +4446,8 @@ f_fullcommand(typval_T *argvars, typval_T *rettv)
44464446
if (p == NULL || ea.cmdidx == CMD_SIZE)
44474447
goto theend;
44484448

4449-
if (vim9script)
4450-
{
4451-
int res;
4452-
4453-
++emsg_silent;
4454-
res = not_in_vim9(&ea);
4455-
--emsg_silent;
4456-
4457-
if (res == FAIL)
4458-
goto theend;
4459-
}
4449+
if (vim9script && not_in_vim9(&ea, true) == FAIL)
4450+
goto theend;
44604451

44614452
rettv->vval.v_string = vim_strsave(IS_USER_CMDIDX(ea.cmdidx)
44624453
? get_user_command_name(ea.useridx, ea.cmdidx)
@@ -6997,7 +6988,7 @@ ex_stop(exarg_T *eap)
69976988
ex_exit(exarg_T *eap)
69986989
{
69996990
#ifdef FEAT_EVAL
7000-
if (not_in_vim9(eap) == FAIL)
6991+
if (not_in_vim9(eap, false) == FAIL)
70016992
return;
70026993
#endif
70036994
if (cmdwin_type != 0)
@@ -7842,7 +7833,7 @@ ex_open(exarg_T *eap)
78427833
char_u *p;
78437834

78447835
#ifdef FEAT_EVAL
7845-
if (not_in_vim9(eap) == FAIL)
7836+
if (not_in_vim9(eap, false) == FAIL)
78467837
return;
78477838
#endif
78487839
curwin->w_cursor.lnum = eap->line2;
@@ -8866,7 +8857,7 @@ ex_copymove(exarg_T *eap)
88668857
long n;
88678858

88688859
#ifdef FEAT_EVAL
8869-
if (not_in_vim9(eap) == FAIL)
8860+
if (not_in_vim9(eap, false) == FAIL)
88708861
return;
88718862
#endif
88728863
n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, FALSE, 1);
@@ -9406,7 +9397,7 @@ ex_mark(exarg_T *eap)
94069397
pos_T pos;
94079398

94089399
#ifdef FEAT_EVAL
9409-
if (not_in_vim9(eap) == FAIL)
9400+
if (not_in_vim9(eap, false) == FAIL)
94109401
return;
94119402
#endif
94129403
if (*eap->arg == NUL) // No argument?

‎src/proto/vim9script.pro‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ int in_old_script(int max_version);
33
int current_script_is_vim9(void);
44
void clear_vim9_scriptlocal_vars(int sid);
55
void ex_vim9script(exarg_T *eap);
6-
int not_in_vim9(exarg_T *eap);
6+
int not_in_vim9(exarg_T *eap, bool silent);
77
int vim9_bad_comment(char_u *p);
88
int vim9_comment_start(char_u *p);
99
void ex_incdec(exarg_T *eap);

‎src/testdir/test_excmd.vim‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,11 @@ func Test_append_cmd_skipped()
205205
call assert_equal('append insert change while', g:skipped)
206206
call assert_equal(['text'], getline(1, '$'))
207207

208-
" In Vim9 script :append is not allowed, but it is not executed here.
208+
" In Vim9 script :append isn't allowed and doesn't consume followling lines.
209209
let lines =<< trim END
210210
vim9script
211211
if false
212212
append
213-
enddef
214-
.
215213
endif
216214
g:skipped = 'vim9'
217215
END
@@ -220,6 +218,22 @@ func Test_append_cmd_skipped()
220218
call assert_equal('vim9', g:skipped)
221219
call assert_equal(['text'], getline(1, '$'))
222220

221+
" Compiling a :def function with a skipped :append should still give E1100.
222+
let lines =<< trim END
223+
vim9script
224+
def Foo()
225+
if false
226+
append
227+
endif
228+
enddef
229+
g:skipped = ''
230+
defcompile
231+
g:skipped = 'defcompile' # not reached
232+
END
233+
call writefile(lines, 'Xappend_skipped_def', 'D')
234+
call assert_fails('source Xappend_skipped_def', 'E1100:')
235+
call assert_equal('', g:skipped)
236+
223237
unlet g:skipped
224238
bwipe!
225239
endfunc

‎src/version.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ static char *(features[]) =
743743

744744
static int included_patches[] =
745745
{ /* Add new patch number below this line */
746+
/**/
747+
1164,
746748
/**/
747749
1163,
748750
/**/

‎src/vim9compile.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4808,7 +4808,7 @@ compile_def_function_body(
48084808
case CMD_open:
48094809
case CMD_t:
48104810
case CMD_xit:
4811-
not_in_vim9(&ea);
4811+
not_in_vim9(&ea, false);
48124812
goto linefail;
48134813

48144814
case CMD_SIZE:

‎src/vim9script.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,19 @@ ex_vim9script(exarg_T *eap UNUSED)
133133

134134
#if defined(FEAT_EVAL)
135135
/*
136-
* When in Vim9 script give an error and return FAIL.
136+
* When in Vim9 script give an error (unless "silent" is true) and return FAIL.
137137
*/
138138
int
139-
not_in_vim9(exarg_T *eap)
139+
not_in_vim9(exarg_T *eap, bool silent)
140140
{
141141
if (in_vim9script())
142142
switch (eap->cmdidx)
143143
{
144144
case CMD_k:
145145
if (eap->addr_count > 0)
146146
{
147-
emsg(_(e_no_range_allowed));
147+
if (!silent)
148+
emsg(_(e_no_range_allowed));
148149
return FAIL;
149150
}
150151
// FALLTHROUGH
@@ -154,7 +155,8 @@ not_in_vim9(exarg_T *eap)
154155
case CMD_open:
155156
case CMD_t:
156157
case CMD_xit:
157-
semsg(_(e_command_not_supported_in_vim9_script_missing_var_str), eap->cmd);
158+
if (!silent)
159+
semsg(_(e_command_not_supported_in_vim9_script_missing_var_str), eap->cmd);
158160
return FAIL;
159161
default: break;
160162
}

0 commit comments

Comments
 (0)