To: vim_dev@googlegroups.com Subject: Patch 8.2.1280 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1280 Problem: Ex command error cannot contain an argument. Solution: Add ex_errmsg() and translate earlier. Use e_trailing_arg where possible. Files: src/ex_docmd.c, src/proto/ex_docmd.pro, src/buffer.c, src/ex_eval.c, src/match.c, src/testdir/test_tabpage.vim *** ../vim-8.2.1279/src/ex_docmd.c 2020-07-20 22:37:40.554206364 +0200 --- src/ex_docmd.c 2020-07-23 16:34:46.849060035 +0200 *************** *** 2570,2576 **** ea.errmsg = NULL; (cmdnames[ea.cmdidx].cmd_func)(&ea); if (ea.errmsg != NULL) ! errormsg = _(ea.errmsg); } #ifdef FEAT_EVAL --- 2570,2576 ---- ea.errmsg = NULL; (cmdnames[ea.cmdidx].cmd_func)(&ea); if (ea.errmsg != NULL) ! errormsg = ea.errmsg; } #ifdef FEAT_EVAL *************** *** 2648,2653 **** --- 2648,2667 ---- #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,3995 **** ex_ni(exarg_T *eap) { if (!eap->skip) ! eap->errmsg = N_("E319: Sorry, the command is not available in this version"); } #ifdef HAVE_EX_SCRIPT_NI --- 4003,4010 ---- ex_ni(exarg_T *eap) { if (!eap->skip) ! eap->errmsg = ! _("E319: Sorry, the command is not available in this version"); } #ifdef HAVE_EX_SCRIPT_NI *************** *** 4747,4753 **** if (secure) { secure = 2; ! eap->errmsg = e_curdir; } else if (eap->cmdidx == CMD_autocmd) do_autocmd(eap->arg, eap->forceit); --- 4762,4768 ---- if (secure) { secure = 2; ! eap->errmsg = _(e_curdir); } else if (eap->cmdidx == CMD_autocmd) do_autocmd(eap->arg, eap->forceit); *************** *** 4798,4804 **** if (ERROR_IF_ANY_POPUP_WINDOW) return; if (*eap->arg) ! eap->errmsg = e_trailing; else { if (eap->addr_count == 0) // default is current buffer --- 4813,4819 ---- if (ERROR_IF_ANY_POPUP_WINDOW) return; if (*eap->arg) ! eap->errmsg = ex_errmsg(e_trailing_arg, eap->arg); else { if (eap->addr_count == 0) // default is current buffer *************** *** 5365,5371 **** || tab_number > LAST_TAB_NR) { // No numbers as argument. ! eap->errmsg = e_invarg; goto theend; } } --- 5380,5386 ---- || tab_number > LAST_TAB_NR) { // No numbers as argument. ! eap->errmsg = ex_errmsg(e_invarg2, eap->arg); goto theend; } } *************** *** 5377,5383 **** || tab_number == 0) { // No numbers as argument. ! eap->errmsg = e_invarg; goto theend; } tab_number = tab_number * relative + tabpage_index(curtab); --- 5392,5398 ---- || tab_number == 0) { // No numbers as argument. ! eap->errmsg = ex_errmsg(e_invarg2, eap->arg); goto theend; } tab_number = tab_number * relative + tabpage_index(curtab); *************** *** 5385,5397 **** --tab_number; } if (tab_number < unaccept_arg0 || tab_number > LAST_TAB_NR) ! eap->errmsg = e_invarg; } else if (eap->addr_count > 0) { if (unaccept_arg0 && eap->line2 == 0) { ! eap->errmsg = e_invrange; tab_number = 0; } else --- 5400,5412 ---- --tab_number; } if (tab_number < unaccept_arg0 || tab_number > LAST_TAB_NR) ! eap->errmsg = ex_errmsg(e_invarg2, eap->arg); } else if (eap->addr_count > 0) { if (unaccept_arg0 && eap->line2 == 0) { ! eap->errmsg = _(e_invrange); tab_number = 0; } else *************** *** 5401,5407 **** { --tab_number; if (tab_number < unaccept_arg0) ! eap->errmsg = e_invarg; } } } --- 5416,5422 ---- { --tab_number; if (tab_number < unaccept_arg0) ! eap->errmsg = _(e_invrange); } } } *************** *** 5914,5920 **** static void ex_wrongmodifier(exarg_T *eap) { ! eap->errmsg = e_invcmd; } /* --- 5929,5935 ---- static void ex_wrongmodifier(exarg_T *eap) { ! eap->errmsg = _(e_invcmd); } /* *************** *** 6097,6103 **** || tab_number == 0) { // No numbers as argument. ! eap->errmsg = e_invarg; return; } } --- 6112,6118 ---- || tab_number == 0) { // No numbers as argument. ! eap->errmsg = ex_errmsg(e_invarg2, eap->arg); return; } } *************** *** 6110,6116 **** tab_number = eap->line2; if (tab_number < 1) { ! eap->errmsg = e_invrange; return; } } --- 6125,6131 ---- tab_number = eap->line2; if (tab_number < 1) { ! eap->errmsg = _(e_invrange); return; } } *************** *** 6498,6504 **** static void ex_nogui(exarg_T *eap) { ! eap->errmsg = e_nogvim; } #endif --- 6513,6519 ---- static void ex_nogui(exarg_T *eap) { ! eap->errmsg = _(e_nogvim); } #endif *************** *** 8074,8080 **** // Check for trailing illegal characters if (!ends_excmd2(eap->arg, p)) ! eap->errmsg = e_trailing; else eap->nextcmd = check_nextcmd(p); } --- 8089,8095 ---- // Check for trailing illegal characters if (!ends_excmd2(eap->arg, p)) ! eap->errmsg = ex_errmsg(e_trailing_arg, p); else eap->nextcmd = check_nextcmd(p); } *** ../vim-8.2.1279/src/proto/ex_docmd.pro 2020-07-17 20:47:47.640033591 +0200 --- src/proto/ex_docmd.pro 2020-07-23 16:02:45.427063143 +0200 *************** *** 5,10 **** --- 5,11 ---- 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); *** ../vim-8.2.1279/src/buffer.c 2020-07-21 19:25:11.414568222 +0200 --- src/buffer.c 2020-07-23 16:06:26.345884594 +0200 *************** *** 1188,1194 **** if (addr_count == 2) { if (*arg) // both range and argument is not allowed ! return _(e_trailing); bnr = start_bnr; } else // addr_count == 1 --- 1188,1194 ---- if (addr_count == 2) { if (*arg) // both range and argument is not allowed ! return ex_errmsg(e_trailing_arg, arg); bnr = start_bnr; } else // addr_count == 1 *** ../vim-8.2.1279/src/ex_eval.c 2020-07-01 17:28:30.343443234 +0200 --- src/ex_eval.c 2020-07-23 16:19:03.754090508 +0200 *************** *** 917,923 **** cstack_T *cstack = eap->cstack; if (cstack->cs_idx == CSTACK_LEN - 1) ! eap->errmsg = N_("E579: :if nesting too deep"); else { ++cstack->cs_idx; --- 917,923 ---- cstack_T *cstack = eap->cstack; if (cstack->cs_idx == CSTACK_LEN - 1) ! eap->errmsg = _("E579: :if nesting too deep"); else { ++cstack->cs_idx; *************** *** 953,959 **** 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); else { /* --- 953,959 ---- if (eap->cstack->cs_idx < 0 || (eap->cstack->cs_flags[eap->cstack->cs_idx] & (CSF_WHILE | CSF_FOR | CSF_TRY))) ! eap->errmsg = _(e_endif_without_if); else { /* *************** *** 997,1016 **** { if (eap->cmdidx == CMD_else) { ! eap->errmsg = N_(e_else_without_if); return; } ! eap->errmsg = N_(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"); return; } ! eap->errmsg = N_("E584: :elseif after :else"); skip = TRUE; } --- 997,1016 ---- { if (eap->cmdidx == CMD_else) { ! eap->errmsg = _(e_else_without_if); return; } ! 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 = _("E583: multiple :else"); return; } ! eap->errmsg = _("E584: :elseif after :else"); skip = TRUE; } *************** *** 1076,1082 **** cstack_T *cstack = eap->cstack; if (cstack->cs_idx == CSTACK_LEN - 1) ! eap->errmsg = N_("E585: :while/:for nesting too deep"); else { /* --- 1076,1082 ---- cstack_T *cstack = eap->cstack; if (cstack->cs_idx == CSTACK_LEN - 1) ! eap->errmsg = _("E585: :while/:for nesting too deep"); else { /* *************** *** 1186,1192 **** cstack_T *cstack = eap->cstack; if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) ! eap->errmsg = N_(e_continue); else { // Try to find the matching ":while". This might stop at a try --- 1186,1192 ---- cstack_T *cstack = eap->cstack; if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) ! eap->errmsg = _(e_continue); else { // Try to find the matching ":while". This might stop at a try *************** *** 1224,1230 **** cstack_T *cstack = eap->cstack; if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) ! eap->errmsg = N_(e_break); else { // Inactivate conditionals until the matching ":while" or a try --- 1224,1230 ---- cstack_T *cstack = eap->cstack; if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) ! eap->errmsg = _(e_break); else { // Inactivate conditionals until the matching ":while" or a try *************** *** 1264,1270 **** } if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) ! eap->errmsg = err; else { fl = cstack->cs_flags[cstack->cs_idx]; --- 1264,1270 ---- } if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) ! eap->errmsg = _(err); else { fl = cstack->cs_flags[cstack->cs_idx]; *************** *** 1280,1288 **** if (!(fl & (CSF_WHILE | CSF_FOR))) { if (!(fl & CSF_TRY)) ! eap->errmsg = e_endif; else if (fl & CSF_FINALLY) ! eap->errmsg = e_endtry; // Try to find the matching ":while" and report what's missing. for (idx = cstack->cs_idx; idx > 0; --idx) { --- 1280,1288 ---- if (!(fl & (CSF_WHILE | CSF_FOR))) { if (!(fl & CSF_TRY)) ! eap->errmsg = _(e_endif); else if (fl & CSF_FINALLY) ! eap->errmsg = _(e_endtry); // Try to find the matching ":while" and report what's missing. for (idx = cstack->cs_idx; idx > 0; --idx) { *************** *** 1291,1297 **** { // Give up at a try conditional not in its finally clause. // Ignore the ":endwhile"/":endfor". ! eap->errmsg = err; return; } if (fl & csf) --- 1291,1297 ---- { // Give up at a try conditional not in its finally clause. // Ignore the ":endwhile"/":endfor". ! eap->errmsg = _(err); return; } if (fl & csf) *************** *** 1447,1453 **** cstack_T *cstack = eap->cstack; if (cstack->cs_idx == CSTACK_LEN - 1) ! eap->errmsg = N_("E601: :try nesting too deep"); else { ++cstack->cs_idx; --- 1447,1453 ---- cstack_T *cstack = eap->cstack; if (cstack->cs_idx == CSTACK_LEN - 1) ! eap->errmsg = _("E601: :try nesting too deep"); else { ++cstack->cs_idx; *************** *** 1526,1532 **** if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) { ! eap->errmsg = e_catch; give_up = TRUE; } else --- 1526,1532 ---- if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) { ! eap->errmsg = _(e_catch); give_up = TRUE; } else *************** *** 1545,1551 **** { // Give up for a ":catch" after ":finally" and ignore it. // Just parse. ! eap->errmsg = N_("E604: :catch after :finally"); give_up = TRUE; } else --- 1545,1551 ---- { // Give up for a ":catch" after ":finally" and ignore it. // Just parse. ! eap->errmsg = _("E604: :catch after :finally"); give_up = TRUE; } else *************** *** 1685,1691 **** cstack_T *cstack = eap->cstack; if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) ! eap->errmsg = e_finally; else { if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) --- 1685,1691 ---- cstack_T *cstack = eap->cstack; if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) ! eap->errmsg = _(e_finally); else { if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) *************** *** 1705,1711 **** if (cstack->cs_flags[idx] & CSF_FINALLY) { // Give up for a multiple ":finally" and ignore it. ! eap->errmsg = e_finally_dup; return; } rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, --- 1705,1711 ---- if (cstack->cs_flags[idx] & CSF_FINALLY) { // Give up for a multiple ":finally" and ignore it. ! eap->errmsg = _(e_finally_dup); return; } rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, *************** *** 1814,1820 **** cstack_T *cstack = eap->cstack; if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) ! eap->errmsg = e_no_endtry; else { /* --- 1814,1820 ---- cstack_T *cstack = eap->cstack; if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) ! eap->errmsg = _(e_no_endtry); else { /* *************** *** 2276,2285 **** get_end_emsg(cstack_T *cstack) { if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE) ! return e_endwhile; if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) ! return e_endfor; ! return e_endif; } --- 2276,2285 ---- get_end_emsg(cstack_T *cstack) { if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE) ! return _(e_endwhile); if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) ! return _(e_endfor); ! return _(e_endif); } *** ../vim-8.2.1279/src/match.c 2020-06-28 13:17:07.551811006 +0200 --- src/match.c 2020-07-23 16:19:26.477979706 +0200 *************** *** 1329,1335 **** if (*end != NUL && !ends_excmd2(end, skipwhite(end + 1))) { vim_free(g); ! eap->errmsg = e_trailing; return; } if (*end != *p) --- 1329,1335 ---- if (*end != NUL && !ends_excmd2(end, skipwhite(end + 1))) { vim_free(g); ! eap->errmsg = ex_errmsg(e_trailing_arg, end); return; } if (*end != *p) *** ../vim-8.2.1279/src/testdir/test_tabpage.vim 2020-06-26 20:41:35.628844696 +0200 --- src/testdir/test_tabpage.vim 2020-07-23 16:28:54.522927016 +0200 *************** *** 135,152 **** 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("%tabonly", 'E16:') 1tabonly! tabmove 1 call assert_equal(1, tabpagenr()) tabnew ! call assert_fails("-2tabmove", 'E474:') tabonly! endfunc --- 135,152 ---- call assert_fails("99tabmove", 'E16:') call assert_fails("+99tabmove", 'E16:') call assert_fails("-99tabmove", 'E16:') ! 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", 'E16:') tabonly! endfunc *************** *** 324,337 **** 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:') 1tabonly! endfunction --- 324,337 ---- 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', '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,362 **** let err_code = 'E16:' else let entire_cmd = cmd . ' ' . c ! let err_code = 'E474:' endif call assert_fails(entire_cmd, err_code) endfor --- 356,362 ---- let err_code = 'E16:' else let entire_cmd = cmd . ' ' . c ! let err_code = 'E475:' endif call assert_fails(entire_cmd, err_code) endfor *************** *** 455,461 **** let err_code = 'E16:' else let entire_cmd = 'tabclose ' . c ! let err_code = 'E474:' endif call assert_fails(entire_cmd, err_code) call assert_equal(6, tabpagenr('$')) --- 455,461 ---- let err_code = 'E16:' else let entire_cmd = 'tabclose ' . c ! let err_code = 'E475:' endif call assert_fails(entire_cmd, err_code) call assert_equal(6, tabpagenr('$')) *************** *** 464,471 **** call assert_fails('3tabclose', 'E37:') call assert_fails('tabclose 3', 'E37:') ! call assert_fails('tabclose -+', 'E474:') ! call assert_fails('tabclose +2-', 'E474:') call assert_equal(6, tabpagenr('$')) 1tabonly! --- 464,471 ---- call assert_fails('3tabclose', 'E37:') call assert_fails('tabclose 3', 'E37:') ! call assert_fails('tabclose -+', 'E475:') ! call assert_fails('tabclose +2-', 'E475:') call assert_equal(6, tabpagenr('$')) 1tabonly! *************** *** 510,516 **** let err_code = 'E16:' else let entire_cmd = 'tabonly ' . c ! let err_code = 'E474:' endif call assert_fails(entire_cmd, err_code) call assert_equal(6, tabpagenr('$')) --- 510,516 ---- let err_code = 'E16:' else let entire_cmd = 'tabonly ' . c ! let err_code = 'E475:' endif call assert_fails(entire_cmd, err_code) call assert_equal(6, tabpagenr('$')) *************** *** 521,533 **** for c in tc call s:reconstruct_tabpage_for_test(6) let entire_cmd = 'tabonly' . c[2] . ' ' . c[1] ! let err_code = 'E474:' 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_equal(6, tabpagenr('$')) 1tabonly! --- 521,533 ---- for c in tc call s:reconstruct_tabpage_for_test(6) let entire_cmd = 'tabonly' . c[2] . ' ' . c[1] ! let err_code = 'E475:' call assert_fails(entire_cmd, err_code) call assert_equal(6, tabpagenr('$')) endfor ! call assert_fails('tabonly -+', 'E475:') ! call assert_fails('tabonly +2-', 'E475:') call assert_equal(6, tabpagenr('$')) 1tabonly! *** ../vim-8.2.1279/src/version.c 2020-07-23 15:50:37.243649168 +0200 --- src/version.c 2020-07-23 16:32:46.241688992 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1280, /**/ -- hundred-and-one symptoms of being an internet addict: 70. ISDN lines are added to your house on a hourly basis /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///