# HG changeset patch # User Bram Moolenaar # Date 1595515503 -7200 # Node ID a422bd80b434ba8b08809fcf22a1bf57e3d88ddf # Parent 5b12080761da437da32dc04e5e58d0d0bb514be2 patch 8.2.1280: Ex command error cannot contain an argument Commit: https://github.com/vim/vim/commit/8930caaa1a283092aca81fdbc3fcf15c7eadb197 Author: Bram Moolenaar Date: Thu Jul 23 16:37:03 2020 +0200 patch 8.2.1280: Ex command error cannot contain an argument Problem: Ex command error cannot contain an argument. Solution: Add ex_errmsg() and translate earlier. Use e_trailing_arg where possible. diff --git a/src/buffer.c b/src/buffer.c --- a/src/buffer.c +++ b/src/buffer.c @@ -1188,7 +1188,7 @@ do_bufdel( if (addr_count == 2) { if (*arg) // both range and argument is not allowed - return _(e_trailing); + return ex_errmsg(e_trailing_arg, arg); bnr = start_bnr; } else // addr_count == 1 diff --git a/src/ex_docmd.c b/src/ex_docmd.c --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -2570,7 +2570,7 @@ do_one_cmd( ea.errmsg = NULL; (cmdnames[ea.cmdidx].cmd_func)(&ea); if (ea.errmsg != NULL) - errormsg = _(ea.errmsg); + errormsg = ea.errmsg; } #ifdef FEAT_EVAL @@ -2648,6 +2648,20 @@ doend: #pragma optimize( "", on ) #endif +static char ex_error_buf[MSG_BUF_LEN]; + +/* + * Return an error message with argument included. + * Uses a static buffer, only the last error will be kept. + * "msg" will be translated, caller should use N_(). + */ + char * +ex_errmsg(char *msg, char_u *arg) +{ + vim_snprintf(ex_error_buf, MSG_BUF_LEN, _(msg), arg); + return ex_error_buf; +} + /* * Parse and skip over command modifiers: * - update eap->cmd @@ -3989,7 +4003,8 @@ get_flags(exarg_T *eap) ex_ni(exarg_T *eap) { if (!eap->skip) - eap->errmsg = N_("E319: Sorry, the command is not available in this version"); + eap->errmsg = + _("E319: Sorry, the command is not available in this version"); } #ifdef HAVE_EX_SCRIPT_NI @@ -4747,7 +4762,7 @@ ex_autocmd(exarg_T *eap) if (secure) { secure = 2; - eap->errmsg = e_curdir; + eap->errmsg = _(e_curdir); } else if (eap->cmdidx == CMD_autocmd) do_autocmd(eap->arg, eap->forceit); @@ -4798,7 +4813,7 @@ ex_buffer(exarg_T *eap) if (ERROR_IF_ANY_POPUP_WINDOW) return; if (*eap->arg) - eap->errmsg = e_trailing; + eap->errmsg = ex_errmsg(e_trailing_arg, eap->arg); else { if (eap->addr_count == 0) // default is current buffer @@ -5365,7 +5380,7 @@ get_tabpage_arg(exarg_T *eap) || tab_number > LAST_TAB_NR) { // No numbers as argument. - eap->errmsg = e_invarg; + eap->errmsg = ex_errmsg(e_invarg2, eap->arg); goto theend; } } @@ -5377,7 +5392,7 @@ get_tabpage_arg(exarg_T *eap) || tab_number == 0) { // No numbers as argument. - eap->errmsg = e_invarg; + eap->errmsg = ex_errmsg(e_invarg2, eap->arg); goto theend; } tab_number = tab_number * relative + tabpage_index(curtab); @@ -5385,13 +5400,13 @@ get_tabpage_arg(exarg_T *eap) --tab_number; } if (tab_number < unaccept_arg0 || tab_number > LAST_TAB_NR) - eap->errmsg = e_invarg; + eap->errmsg = ex_errmsg(e_invarg2, eap->arg); } else if (eap->addr_count > 0) { if (unaccept_arg0 && eap->line2 == 0) { - eap->errmsg = e_invrange; + eap->errmsg = _(e_invrange); tab_number = 0; } else @@ -5401,7 +5416,7 @@ get_tabpage_arg(exarg_T *eap) { --tab_number; if (tab_number < unaccept_arg0) - eap->errmsg = e_invarg; + eap->errmsg = _(e_invrange); } } } @@ -5914,7 +5929,7 @@ ex_recover(exarg_T *eap) static void ex_wrongmodifier(exarg_T *eap) { - eap->errmsg = e_invcmd; + eap->errmsg = _(e_invcmd); } /* @@ -6097,7 +6112,7 @@ ex_tabnext(exarg_T *eap) || tab_number == 0) { // No numbers as argument. - eap->errmsg = e_invarg; + eap->errmsg = ex_errmsg(e_invarg2, eap->arg); return; } } @@ -6110,7 +6125,7 @@ ex_tabnext(exarg_T *eap) tab_number = eap->line2; if (tab_number < 1) { - eap->errmsg = e_invrange; + eap->errmsg = _(e_invrange); return; } } @@ -6498,7 +6513,7 @@ do_exedit( static void ex_nogui(exarg_T *eap) { - eap->errmsg = e_nogvim; + eap->errmsg = _(e_nogvim); } #endif @@ -8074,7 +8089,7 @@ ex_findpat(exarg_T *eap) // Check for trailing illegal characters if (!ends_excmd2(eap->arg, p)) - eap->errmsg = e_trailing; + eap->errmsg = ex_errmsg(e_trailing_arg, p); else eap->nextcmd = check_nextcmd(p); } diff --git a/src/ex_eval.c b/src/ex_eval.c --- a/src/ex_eval.c +++ b/src/ex_eval.c @@ -917,7 +917,7 @@ ex_if(exarg_T *eap) cstack_T *cstack = eap->cstack; if (cstack->cs_idx == CSTACK_LEN - 1) - eap->errmsg = N_("E579: :if nesting too deep"); + eap->errmsg = _("E579: :if nesting too deep"); else { ++cstack->cs_idx; @@ -953,7 +953,7 @@ ex_endif(exarg_T *eap) if (eap->cstack->cs_idx < 0 || (eap->cstack->cs_flags[eap->cstack->cs_idx] & (CSF_WHILE | CSF_FOR | CSF_TRY))) - eap->errmsg = N_(e_endif_without_if); + eap->errmsg = _(e_endif_without_if); else { /* @@ -997,20 +997,20 @@ ex_else(exarg_T *eap) { if (eap->cmdidx == CMD_else) { - eap->errmsg = N_(e_else_without_if); + eap->errmsg = _(e_else_without_if); return; } - eap->errmsg = N_(e_elseif_without_if); + eap->errmsg = _(e_elseif_without_if); skip = TRUE; } else if (cstack->cs_flags[cstack->cs_idx] & CSF_ELSE) { if (eap->cmdidx == CMD_else) { - eap->errmsg = N_("E583: multiple :else"); + eap->errmsg = _("E583: multiple :else"); return; } - eap->errmsg = N_("E584: :elseif after :else"); + eap->errmsg = _("E584: :elseif after :else"); skip = TRUE; } @@ -1076,7 +1076,7 @@ ex_while(exarg_T *eap) cstack_T *cstack = eap->cstack; if (cstack->cs_idx == CSTACK_LEN - 1) - eap->errmsg = N_("E585: :while/:for nesting too deep"); + eap->errmsg = _("E585: :while/:for nesting too deep"); else { /* @@ -1186,7 +1186,7 @@ ex_continue(exarg_T *eap) cstack_T *cstack = eap->cstack; if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) - eap->errmsg = N_(e_continue); + eap->errmsg = _(e_continue); else { // Try to find the matching ":while". This might stop at a try @@ -1224,7 +1224,7 @@ ex_break(exarg_T *eap) cstack_T *cstack = eap->cstack; if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) - eap->errmsg = N_(e_break); + eap->errmsg = _(e_break); else { // Inactivate conditionals until the matching ":while" or a try @@ -1264,7 +1264,7 @@ ex_endwhile(exarg_T *eap) } if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) - eap->errmsg = err; + eap->errmsg = _(err); else { fl = cstack->cs_flags[cstack->cs_idx]; @@ -1280,9 +1280,9 @@ ex_endwhile(exarg_T *eap) if (!(fl & (CSF_WHILE | CSF_FOR))) { if (!(fl & CSF_TRY)) - eap->errmsg = e_endif; + eap->errmsg = _(e_endif); else if (fl & CSF_FINALLY) - eap->errmsg = e_endtry; + eap->errmsg = _(e_endtry); // Try to find the matching ":while" and report what's missing. for (idx = cstack->cs_idx; idx > 0; --idx) { @@ -1291,7 +1291,7 @@ ex_endwhile(exarg_T *eap) { // Give up at a try conditional not in its finally clause. // Ignore the ":endwhile"/":endfor". - eap->errmsg = err; + eap->errmsg = _(err); return; } if (fl & csf) @@ -1447,7 +1447,7 @@ ex_try(exarg_T *eap) cstack_T *cstack = eap->cstack; if (cstack->cs_idx == CSTACK_LEN - 1) - eap->errmsg = N_("E601: :try nesting too deep"); + eap->errmsg = _("E601: :try nesting too deep"); else { ++cstack->cs_idx; @@ -1526,7 +1526,7 @@ ex_catch(exarg_T *eap) if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) { - eap->errmsg = e_catch; + eap->errmsg = _(e_catch); give_up = TRUE; } else @@ -1545,7 +1545,7 @@ ex_catch(exarg_T *eap) { // Give up for a ":catch" after ":finally" and ignore it. // Just parse. - eap->errmsg = N_("E604: :catch after :finally"); + eap->errmsg = _("E604: :catch after :finally"); give_up = TRUE; } else @@ -1685,7 +1685,7 @@ ex_finally(exarg_T *eap) cstack_T *cstack = eap->cstack; if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) - eap->errmsg = e_finally; + eap->errmsg = _(e_finally); else { if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) @@ -1705,7 +1705,7 @@ ex_finally(exarg_T *eap) if (cstack->cs_flags[idx] & CSF_FINALLY) { // Give up for a multiple ":finally" and ignore it. - eap->errmsg = e_finally_dup; + eap->errmsg = _(e_finally_dup); return; } rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, @@ -1814,7 +1814,7 @@ ex_endtry(exarg_T *eap) cstack_T *cstack = eap->cstack; if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) - eap->errmsg = e_no_endtry; + eap->errmsg = _(e_no_endtry); else { /* @@ -2276,10 +2276,10 @@ cleanup_conditionals( get_end_emsg(cstack_T *cstack) { if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE) - return e_endwhile; + return _(e_endwhile); if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) - return e_endfor; - return e_endif; + return _(e_endfor); + return _(e_endif); } diff --git a/src/match.c b/src/match.c --- a/src/match.c +++ b/src/match.c @@ -1329,7 +1329,7 @@ ex_match(exarg_T *eap) if (*end != NUL && !ends_excmd2(end, skipwhite(end + 1))) { vim_free(g); - eap->errmsg = e_trailing; + eap->errmsg = ex_errmsg(e_trailing_arg, end); return; } if (*end != *p) diff --git a/src/proto/ex_docmd.pro b/src/proto/ex_docmd.pro --- a/src/proto/ex_docmd.pro +++ b/src/proto/ex_docmd.pro @@ -5,6 +5,7 @@ int do_cmdline(char_u *cmdline, char_u * int getline_equal(char_u *(*fgetline)(int, void *, int, int), void *cookie, char_u *(*func)(int, void *, int, int)); void *getline_cookie(char_u *(*fgetline)(int, void *, int, int), void *cookie); char_u *getline_peek(char_u *(*fgetline)(int, void *, int, int), void *cookie); +char *ex_errmsg(char *msg, char_u *arg); int parse_command_modifiers(exarg_T *eap, char **errormsg, int skip_only); void undo_cmdmod(exarg_T *eap, int save_msg_scroll); int parse_cmd_address(exarg_T *eap, char **errormsg, int silent); diff --git a/src/testdir/test_tabpage.vim b/src/testdir/test_tabpage.vim --- a/src/testdir/test_tabpage.vim +++ b/src/testdir/test_tabpage.vim @@ -135,18 +135,18 @@ function Test_tabpage() call assert_fails("99tabmove", 'E16:') call assert_fails("+99tabmove", 'E16:') call assert_fails("-99tabmove", 'E16:') - call assert_fails("tabmove foo", 'E474:') - call assert_fails("tabmove 99", 'E474:') - call assert_fails("tabmove +99", 'E474:') - call assert_fails("tabmove -99", 'E474:') - call assert_fails("tabmove -3+", 'E474:') - call assert_fails("tabmove $3", 'E474:') + call assert_fails("tabmove foo", 'E475:') + call assert_fails("tabmove 99", 'E475:') + call assert_fails("tabmove +99", 'E475:') + call assert_fails("tabmove -99", 'E475:') + call assert_fails("tabmove -3+", 'E475:') + call assert_fails("tabmove $3", 'E475:') call assert_fails("%tabonly", 'E16:') 1tabonly! tabmove 1 call assert_equal(1, tabpagenr()) tabnew - call assert_fails("-2tabmove", 'E474:') + call assert_fails("-2tabmove", 'E16:') tabonly! endfunc @@ -324,14 +324,14 @@ function Test_tabpage_with_tabnext() call Check_tab_count(4, 'tabnext -', 3) call Check_tab_count(4, 'tabnext -2', 2) call Check_tab_count(3, 'tabnext $', 5) - call assert_fails('tabnext 0', 'E474:') - call assert_fails('tabnext .', 'E474:') - call assert_fails('tabnext -+', 'E474:') - call assert_fails('tabnext +2-', 'E474:') - call assert_fails('tabnext $3', 'E474:') - call assert_fails('tabnext 99', 'E474:') - call assert_fails('tabnext +99', 'E474:') - call assert_fails('tabnext -99', 'E474:') + call assert_fails('tabnext 0', 'E475:') + call assert_fails('tabnext .', 'E475:') + call assert_fails('tabnext -+', 'E475:') + call assert_fails('tabnext +2-', 'E475:') + call assert_fails('tabnext $3', 'E475:') + call assert_fails('tabnext 99', 'E475:') + call assert_fails('tabnext +99', 'E475:') + call assert_fails('tabnext -99', 'E475:') 1tabonly! endfunction @@ -356,7 +356,7 @@ function Test_tabpage_with_tabprevious() let err_code = 'E16:' else let entire_cmd = cmd . ' ' . c - let err_code = 'E474:' + let err_code = 'E475:' endif call assert_fails(entire_cmd, err_code) endfor @@ -455,7 +455,7 @@ function Test_tabpage_with_tabclose() let err_code = 'E16:' else let entire_cmd = 'tabclose ' . c - let err_code = 'E474:' + let err_code = 'E475:' endif call assert_fails(entire_cmd, err_code) call assert_equal(6, tabpagenr('$')) @@ -464,8 +464,8 @@ function Test_tabpage_with_tabclose() call assert_fails('3tabclose', 'E37:') call assert_fails('tabclose 3', 'E37:') - call assert_fails('tabclose -+', 'E474:') - call assert_fails('tabclose +2-', 'E474:') + call assert_fails('tabclose -+', 'E475:') + call assert_fails('tabclose +2-', 'E475:') call assert_equal(6, tabpagenr('$')) 1tabonly! @@ -510,7 +510,7 @@ function Test_tabpage_with_tabonly() let err_code = 'E16:' else let entire_cmd = 'tabonly ' . c - let err_code = 'E474:' + let err_code = 'E475:' endif call assert_fails(entire_cmd, err_code) call assert_equal(6, tabpagenr('$')) @@ -521,13 +521,13 @@ function Test_tabpage_with_tabonly() for c in tc call s:reconstruct_tabpage_for_test(6) let entire_cmd = 'tabonly' . c[2] . ' ' . c[1] - let err_code = 'E474:' + let err_code = 'E475:' call assert_fails(entire_cmd, err_code) call assert_equal(6, tabpagenr('$')) endfor - call assert_fails('tabonly -+', 'E474:') - call assert_fails('tabonly +2-', 'E474:') + call assert_fails('tabonly -+', 'E475:') + call assert_fails('tabonly +2-', 'E475:') call assert_equal(6, tabpagenr('$')) 1tabonly! diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1280, +/**/ 1279, /**/ 1278,