diff options
Diffstat (limited to 'src/nvim/ex_docmd.c')
-rw-r--r-- | src/nvim/ex_docmd.c | 84 |
1 files changed, 29 insertions, 55 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 671e83def6..48e6dad720 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -82,8 +82,13 @@ #include "nvim/vim.h" #include "nvim/window.h" -static char *e_no_such_user_defined_command_str = N_("E184: No such user-defined command: %s"); -static char *e_no_such_user_defined_command_in_current_buffer_str +static char e_no_such_user_defined_command_str[] + = N_("E184: No such user-defined command: %s"); +static char e_ambiguous_use_of_user_defined_command[] + = N_("E464: Ambiguous use of user-defined command"); +static char e_not_an_editor_command[] + = N_("E492: Not an editor command"); +static char e_no_such_user_defined_command_in_current_buffer_str[] = N_("E1237: No such user-defined command in current buffer: %s"); static int quitmore = 0; @@ -1207,7 +1212,7 @@ static char *skip_colon_white(const char *p, bool skipleadingwhite) /// Set the addr type for command /// /// @param p pointer to character after command name in cmdline -void set_cmd_addr_type(exarg_T *eap, char_u *p) +void set_cmd_addr_type(exarg_T *eap, char *p) { // ea.addr_type for user commands is set by find_ucmd if (IS_USER_CMDIDX(eap->cmdidx)) { @@ -1220,7 +1225,7 @@ void set_cmd_addr_type(exarg_T *eap, char_u *p) } // :wincmd range depends on the argument if (eap->cmdidx == CMD_wincmd && p != NULL) { - get_wincmd_addr_type(skipwhite((char *)p), eap); + get_wincmd_addr_type(skipwhite(p), eap); } // :.cc in quickfix window uses line number if ((eap->cmdidx == CMD_cc || eap->cmdidx == CMD_ll) && bt_quickfix(curbuf)) { @@ -1400,6 +1405,8 @@ bool is_cmd_ni(cmdidx_T cmdidx) } /// Parse command line and return information about the first command. +/// If parsing is done successfully, need to free cmod_filter_regmatch.regprog after calling, +/// usually done using undo_cmdmod() or execute_cmd(). /// /// @param cmdline Command line string /// @param[out] eap Ex command arguments @@ -1427,6 +1434,7 @@ bool parse_cmdline(char *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, char **er // Parse command modifiers if (parse_command_modifiers(eap, errormsg, &cmdinfo->cmdmod, false) == FAIL) { + vim_regfree(cmdinfo->cmdmod.cmod_filter_regmatch.regprog); return false; } after_modifier = eap->cmd; @@ -1439,9 +1447,13 @@ bool parse_cmdline(char *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, char **er eap->cmd = skipwhite(eap->cmd + 1); } p = find_ex_command(eap, NULL); + if (p == NULL) { + *errormsg = _(e_ambiguous_use_of_user_defined_command); + return false; + } // Set command address type and parse command range - set_cmd_addr_type(eap, (char_u *)p); + set_cmd_addr_type(eap, p); eap->cmd = cmd; if (parse_cmd_address(eap, errormsg, false) == FAIL) { return false; @@ -1455,7 +1467,7 @@ bool parse_cmdline(char *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, char **er } // Fail if command is invalid if (eap->cmdidx == CMD_SIZE) { - STRCPY(IObuff, _("E492: Not an editor command")); + STRCPY(IObuff, _(e_not_an_editor_command)); // If the modifier was parsed OK the error must be in the following command char *cmdname = after_modifier ? after_modifier : cmdline; append_command(cmdname); @@ -1812,7 +1824,7 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter // The ea.cmd pointer is updated to point to the first character following the // range spec. If an initial address is found, but no second, the upper bound // is equal to the lower. - set_cmd_addr_type(&ea, (char_u *)p); + set_cmd_addr_type(&ea, p); ea.cmd = cmd; if (parse_cmd_address(&ea, &errormsg, false) == FAIL) { @@ -1886,14 +1898,14 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter if (p == NULL) { if (!ea.skip) { - errormsg = _("E464: Ambiguous use of user-defined command"); + errormsg = _(e_ambiguous_use_of_user_defined_command); } goto doend; } // Check for wrong commands. if (ea.cmdidx == CMD_SIZE) { if (!ea.skip) { - STRCPY(IObuff, _("E492: Not an editor command")); + STRCPY(IObuff, _(e_not_an_editor_command)); // If the modifier was parsed OK the error must be in the following // command char *cmdname = after_modifier ? after_modifier : *cmdlinep; @@ -2655,8 +2667,8 @@ static void apply_cmdmod(cmdmod_T *cmod) if ((cmod->cmod_flags & CMOD_NOAUTOCMD) && cmod->cmod_save_ei == NULL) { // Set 'eventignore' to "all". // First save the existing option value for restoring it later. - cmod->cmod_save_ei = vim_strsave(p_ei); - set_string_option_direct("ei", -1, (char_u *)"all", OPT_FREE, SID_NONE); + cmod->cmod_save_ei = (char *)vim_strsave(p_ei); + set_string_option_direct("ei", -1, "all", OPT_FREE, SID_NONE); } } @@ -2676,7 +2688,7 @@ static void undo_cmdmod(cmdmod_T *cmod) if (cmod->cmod_save_ei != NULL) { // Restore 'eventignore' to the value before ":noautocmd". - set_string_option_direct("ei", -1, (char_u *)cmod->cmod_save_ei, OPT_FREE, SID_NONE); + set_string_option_direct("ei", -1, cmod->cmod_save_ei, OPT_FREE, SID_NONE); free_string_option((char_u *)cmod->cmod_save_ei); cmod->cmod_save_ei = NULL; } @@ -5792,7 +5804,7 @@ static void uc_list(char *name, size_t name_len) } while (len < 25 - over); IObuff[len] = '\0'; - msg_outtrans(IObuff); + msg_outtrans((char *)IObuff); msg_outtrans_special(cmd->uc_rep, false, name_len == 0 ? Columns - 47 : 0); @@ -7562,7 +7574,7 @@ static void ex_recover(exarg_T *eap) | CCGD_EXCMD) && (*eap->arg == NUL - || setfname(curbuf, (char_u *)eap->arg, NULL, true) == OK)) { + || setfname(curbuf, eap->arg, NULL, true) == OK)) { ml_recover(true); } recoverymode = false; @@ -7750,9 +7762,9 @@ static void ex_tabs(exarg_T *eap) if (buf_spname(wp->w_buffer) != NULL) { STRLCPY(IObuff, buf_spname(wp->w_buffer), IOSIZE); } else { - home_replace(wp->w_buffer, (char_u *)wp->w_buffer->b_fname, IObuff, IOSIZE, true); + home_replace(wp->w_buffer, wp->w_buffer->b_fname, (char *)IObuff, IOSIZE, true); } - msg_outtrans(IObuff); + msg_outtrans((char *)IObuff); ui_flush(); // output one line at a time os_breakcheck(); } @@ -9634,7 +9646,7 @@ static char *arg_all(void) for (;;) { len = 0; for (idx = 0; idx < ARGCOUNT; idx++) { - p = (char *)alist_name(&ARGLIST[idx]); + p = alist_name(&ARGLIST[idx]); if (p == NULL) { continue; } @@ -10031,44 +10043,6 @@ static void ex_terminal(exarg_T *eap) do_cmdline_cmd(ex_cmd); } -/// Checks if `cmd` is "previewable" (i.e. supported by 'inccommand'). -/// -/// @param[in] cmd Commandline to check. May start with a range or modifier. -/// -/// @return true if `cmd` is previewable -bool cmd_can_preview(char *cmd) -{ - if (cmd == NULL) { - return false; - } - - // Ignore additional colons at the start... - cmd = skip_colon_white(cmd, true); - - // Ignore any leading modifiers (:keeppatterns, :verbose, etc.) - for (int len = modifier_len(cmd); len != 0; len = modifier_len(cmd)) { - cmd += len; - cmd = skip_colon_white(cmd, true); - } - - exarg_T ea; - memset(&ea, 0, sizeof(ea)); - // parse the command line - ea.cmd = skip_range(cmd, NULL); - if (*ea.cmd == '*') { - ea.cmd = skipwhite(ea.cmd + 1); - } - - if (find_ex_command(&ea, NULL) == NULL || ea.cmdidx == CMD_SIZE) { - return false; - } else if (!IS_USER_CMDIDX(ea.cmdidx)) { - // find_ex_command sets the flags for user commands automatically - ea.argt = cmdnames[(int)ea.cmdidx].cmd_argt; - } - - return (ea.argt & EX_PREVIEW); -} - /// Gets a map of maps describing user-commands defined for buffer `buf` or /// defined globally if `buf` is NULL. /// |