Skip to content

Commit 917c46a

Browse files
committed
patch 8.2.3324: Vim9: Cannot use :silent with :endwhile
Problem: Vim9: Cannot use :silent with :endwhile. Solution: Allow for using the :silent modifier. (closes #8737)
1 parent b6f55bb commit 917c46a

File tree

6 files changed

+34
-16
lines changed

6 files changed

+34
-16
lines changed

src/ex_docmd.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,9 +3061,11 @@ parse_command_modifiers(
30613061
* Return TRUE if "cmod" has anything set.
30623062
*/
30633063
int
3064-
has_cmdmod(cmdmod_T *cmod)
3064+
has_cmdmod(cmdmod_T *cmod, int ignore_silent)
30653065
{
3066-
return cmod->cmod_flags != 0
3066+
return (cmod->cmod_flags != 0 && (!ignore_silent
3067+
|| (cmod->cmod_flags
3068+
& ~(CMOD_SILENT | CMOD_ERRSILENT | CMOD_UNSILENT)) != 0))
30673069
|| cmod->cmod_split != 0
30683070
|| cmod->cmod_verbose != 0
30693071
|| cmod->cmod_tab != 0
@@ -3074,9 +3076,9 @@ has_cmdmod(cmdmod_T *cmod)
30743076
* If Vim9 script and "cmdmod" has anything set give an error and return TRUE.
30753077
*/
30763078
int
3077-
cmdmod_error(void)
3079+
cmdmod_error(int ignore_silent)
30783080
{
3079-
if (in_vim9script() && has_cmdmod(&cmdmod))
3081+
if (in_vim9script() && has_cmdmod(&cmdmod, ignore_silent))
30803082
{
30813083
emsg(_(e_misplaced_command_modifier));
30823084
return TRUE;

src/ex_eval.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ ex_endif(exarg_T *eap)
10261026
{
10271027
cstack_T *cstack = eap->cstack;
10281028

1029-
if (cmdmod_error())
1029+
if (cmdmod_error(FALSE))
10301030
return;
10311031
did_endif = TRUE;
10321032
if (cstack->cs_idx < 0
@@ -1355,7 +1355,7 @@ ex_endwhile(exarg_T *eap)
13551355
int csf;
13561356
int fl;
13571357

1358-
if (cmdmod_error())
1358+
if (cmdmod_error(TRUE))
13591359
return;
13601360

13611361
if (eap->cmdidx == CMD_endwhile)
@@ -1593,7 +1593,7 @@ ex_try(exarg_T *eap)
15931593
int skip;
15941594
cstack_T *cstack = eap->cstack;
15951595

1596-
if (cmdmod_error())
1596+
if (cmdmod_error(FALSE))
15971597
return;
15981598

15991599
if (cstack->cs_idx == CSTACK_LEN - 1)
@@ -1674,7 +1674,7 @@ ex_catch(exarg_T *eap)
16741674
cstack_T *cstack = eap->cstack;
16751675
char_u *pat;
16761676

1677-
if (cmdmod_error())
1677+
if (cmdmod_error(FALSE))
16781678
return;
16791679

16801680
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0)
@@ -1839,7 +1839,7 @@ ex_finally(exarg_T *eap)
18391839
int pending = CSTP_NONE;
18401840
cstack_T *cstack = eap->cstack;
18411841

1842-
if (cmdmod_error())
1842+
if (cmdmod_error(FALSE))
18431843
return;
18441844

18451845
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0)
@@ -1971,7 +1971,7 @@ ex_endtry(exarg_T *eap)
19711971
void *rettv = NULL;
19721972
cstack_T *cstack = eap->cstack;
19731973

1974-
if (cmdmod_error())
1974+
if (cmdmod_error(FALSE))
19751975
return;
19761976

19771977
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0)

src/proto/ex_docmd.pro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ char *ex_errmsg(char *msg, char_u *arg);
1010
int checkforcmd(char_u **pp, char *cmd, int len);
1111
int checkforcmd_noparen(char_u **pp, char *cmd, int len);
1212
int parse_command_modifiers(exarg_T *eap, char **errormsg, cmdmod_T *cmod, int skip_only);
13-
int has_cmdmod(cmdmod_T *cmod);
14-
int cmdmod_error(void);
13+
int has_cmdmod(cmdmod_T *cmod, int ignore_silent);
14+
int cmdmod_error(int ignore_silent);
1515
void apply_cmdmod(cmdmod_T *cmod);
1616
void undo_cmdmod(cmdmod_T *cmod);
1717
int parse_cmd_address(exarg_T *eap, char **errormsg, int silent);
@@ -32,7 +32,7 @@ int ends_excmd(int c);
3232
int ends_excmd2(char_u *cmd_start, char_u *cmd);
3333
char_u *find_nextcmd(char_u *p);
3434
char_u *check_nextcmd(char_u *p);
35-
void set_nextcmd(exarg_T *eap, char_u *p);
35+
void set_nextcmd(exarg_T *eap, char_u *arg);
3636
char_u *get_command_name(expand_T *xp, int idx);
3737
void not_exiting(void);
3838
int before_quit_autocmds(win_T *wp, int quit_all, int forceit);

src/testdir/test_vim9_cmd.vim

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,17 @@ def Test_modifier_silent_unsilent()
807807
echomsg "caught"
808808
endtry
809809
assert_equal("\ncaught", execute(':1messages'))
810+
811+
var lines =<< trim END
812+
vim9script
813+
set history=11
814+
silent! while 0
815+
set history=22
816+
silent! endwhile
817+
assert_equal(11, &history)
818+
set history&
819+
END
820+
CheckScriptSuccess(lines)
810821
enddef
811822

812823
def Test_range_after_command_modifier()
@@ -836,13 +847,16 @@ def Test_useless_command_modifier()
836847
for i in [0]
837848
silent endfor
838849
END
839-
CheckDefAndScriptFailure(lines, 'E1176:', 2)
850+
CheckDefFailure(lines, 'E1176:', 2)
851+
CheckScriptSuccess(['vim9script'] + lines)
840852

841853
lines =<< trim END
842854
while g:maybe
843855
silent endwhile
844856
END
845-
CheckDefAndScriptFailure(lines, 'E1176:', 2)
857+
CheckDefFailure(lines, 'E1176:', 2)
858+
g:maybe = false
859+
CheckScriptSuccess(['vim9script'] + lines)
846860

847861
lines =<< trim END
848862
silent try

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3324,
758760
/**/
759761
3323,
760762
/**/

src/vim9compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,7 @@ generate_cmdmods(cctx_T *cctx, cmdmod_T *cmod)
23442344
{
23452345
isn_T *isn;
23462346

2347-
if (has_cmdmod(cmod))
2347+
if (has_cmdmod(cmod, FALSE))
23482348
{
23492349
cctx->ctx_has_cmdmod = TRUE;
23502350

0 commit comments

Comments
 (0)