diff options
Diffstat (limited to 'src/nvim/ex_docmd.c')
| -rw-r--r-- | src/nvim/ex_docmd.c | 91 |
1 files changed, 55 insertions, 36 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index e4a8c2735b..ca79270fcc 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -92,6 +92,9 @@ static garray_T ucmds = {0, 0, sizeof(ucmd_T), 4, NULL}; #define USER_CMD(i) (&((ucmd_T *)(ucmds.ga_data))[i]) #define USER_CMD_GA(gap, i) (&((ucmd_T *)((gap)->ga_data))[i]) +/* Wether a command index indicates a user command. */ +# define IS_USER_CMDIDX(idx) ((int)(idx) < 0) + /* Struct for storing a line inside a while/for loop */ typedef struct { char_u *line; /* command line */ @@ -135,7 +138,6 @@ struct dbg_stuff { # include "ex_docmd.c.generated.h" #endif -# define HAVE_EX_SCRIPT_NI # define ex_gui ex_nogui # define ex_tearoff ex_ni # define ex_popup ex_ni @@ -1489,12 +1491,9 @@ static char_u * do_one_cmd(char_u **cmdlinep, goto doend; } - ni = ( - !USER_CMDIDX(ea.cmdidx) && - (cmdnames[ea.cmdidx].cmd_func == ex_ni -#ifdef HAVE_EX_SCRIPT_NI - || cmdnames[ea.cmdidx].cmd_func == ex_script_ni -#endif + ni = (!IS_USER_CMDIDX(ea.cmdidx) + && (cmdnames[ea.cmdidx].cmd_func == ex_ni + || cmdnames[ea.cmdidx].cmd_func == ex_script_ni )); @@ -1509,8 +1508,9 @@ static char_u * do_one_cmd(char_u **cmdlinep, /* * 5. parse arguments */ - if (!USER_CMDIDX(ea.cmdidx)) + if (!IS_USER_CMDIDX(ea.cmdidx)) { ea.argt = (long)cmdnames[(int)ea.cmdidx].cmd_argt; + } if (!ea.skip) { #ifdef HAVE_SANDBOX @@ -1527,8 +1527,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, } if (text_locked() && !(ea.argt & CMDWIN) - && !USER_CMDIDX(ea.cmdidx) - ) { + && !IS_USER_CMDIDX(ea.cmdidx)) { /* Command not allowed when editing the command line. */ if (cmdwin_type != 0) errormsg = (char_u *)_(e_cmdwin); @@ -1542,7 +1541,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, if (!(ea.argt & CMDWIN) && ea.cmdidx != CMD_edit && ea.cmdidx != CMD_checktime - && !USER_CMDIDX(ea.cmdidx) + && !IS_USER_CMDIDX(ea.cmdidx) && curbuf_locked()) goto doend; @@ -1708,17 +1707,15 @@ static char_u * do_one_cmd(char_u **cmdlinep, if ( (ea.argt & REGSTR) && *ea.arg != NUL /* Do not allow register = for user commands */ - && (!USER_CMDIDX(ea.cmdidx) || *ea.arg != '=') + && (!IS_USER_CMDIDX(ea.cmdidx) || *ea.arg != '=') && !((ea.argt & COUNT) && VIM_ISDIGIT(*ea.arg))) { /* check these explicitly for a more specific error message */ if (*ea.arg == '*' || *ea.arg == '+') { errormsg = (char_u *)_(e_invalidreg); goto doend; } - if ( - valid_yank_reg(*ea.arg, (ea.cmdidx != CMD_put - && USER_CMDIDX(ea.cmdidx))) - ) { + if (valid_yank_reg(*ea.arg, (ea.cmdidx != CMD_put + && !IS_USER_CMDIDX(ea.cmdidx)))) { ea.regname = *ea.arg++; /* for '=' register: accept the rest of the line as an expression */ if (ea.arg[-1] == '=' && ea.arg[0] != NUL) { @@ -1832,19 +1829,26 @@ static char_u * do_one_cmd(char_u **cmdlinep, case CMD_leftabove: case CMD_let: case CMD_lockmarks: + case CMD_lua: case CMD_match: + case CMD_mzscheme: case CMD_noautocmd: case CMD_noswapfile: + case CMD_perl: case CMD_psearch: case CMD_python: + case CMD_py3: + case CMD_python3: case CMD_return: case CMD_rightbelow: + case CMD_ruby: case CMD_silent: case CMD_smagic: case CMD_snomagic: case CMD_substitute: case CMD_syntax: case CMD_tab: + case CMD_tcl: case CMD_throw: case CMD_tilde: case CMD_topleft: @@ -1854,7 +1858,8 @@ static char_u * do_one_cmd(char_u **cmdlinep, case CMD_wincmd: break; - default: goto doend; + default: + goto doend; } } @@ -1868,7 +1873,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, * number. Don't do this for a user command. */ if ((ea.argt & BUFNAME) && *ea.arg != NUL && ea.addr_count == 0 - && !USER_CMDIDX(ea.cmdidx) + && !IS_USER_CMDIDX(ea.cmdidx) ) { /* * :bdelete, :bwipeout and :bunload take several arguments, separated @@ -1901,7 +1906,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, ea.cookie = cookie; ea.cstack = cstack; - if (USER_CMDIDX(ea.cmdidx)) { + if (IS_USER_CMDIDX(ea.cmdidx)) { /* * Execute a user-defined command. */ @@ -1949,9 +1954,9 @@ doend: emsg(errormsg); } do_errthrow(cstack, - (ea.cmdidx != CMD_SIZE - && !USER_CMDIDX(ea.cmdidx) - ) ? cmdnames[(int)ea.cmdidx].cmd_name : (char_u *)NULL); + (ea.cmdidx != CMD_SIZE && !IS_USER_CMDIDX(ea.cmdidx)) + ? cmdnames[(int)ea.cmdidx].cmd_name + : (char_u *)NULL); if (verbose_save >= 0) p_verbose = verbose_save; @@ -2464,8 +2469,9 @@ set_one_cmd_context ( /* * 5. parse arguments */ - if (!USER_CMDIDX(ea.cmdidx)) + if (!IS_USER_CMDIDX(ea.cmdidx)) { ea.argt = (long)cmdnames[(int)ea.cmdidx].cmd_argt; + } arg = skipwhite(p); @@ -3290,9 +3296,7 @@ static void get_flags(exarg_T *eap) } } -/* - * Function called for command which is Not Implemented. NI! - */ +/// Stub function for command which is Not Implemented. NI! void ex_ni(exarg_T *eap) { if (!eap->skip) @@ -3300,11 +3304,8 @@ void ex_ni(exarg_T *eap) "E319: Sorry, the command is not available in this version"); } -#ifdef HAVE_EX_SCRIPT_NI -/* - * Function called for script command which is Not Implemented. NI! - * Skips over ":perl <<EOF" constructs. - */ +/// Stub function for script command which is Not Implemented. NI! +/// Skips over ":perl <<EOF" constructs. static void ex_script_ni(exarg_T *eap) { if (!eap->skip) @@ -3312,7 +3313,6 @@ static void ex_script_ni(exarg_T *eap) else free(script_get(eap, eap->arg)); } -#endif /* * Check range in Ex command for validity. @@ -3958,13 +3958,17 @@ static void ex_bunload(exarg_T *eap) */ static void ex_buffer(exarg_T *eap) { - if (*eap->arg) + if (*eap->arg) { eap->errmsg = e_trailing; - else { - if (eap->addr_count == 0) /* default is current buffer */ + } else { + if (eap->addr_count == 0) { // default is current buffer goto_buffer(eap, DOBUF_CURRENT, FORWARD, 0); - else + } else { goto_buffer(eap, DOBUF_FIRST, FORWARD, (int)eap->line2); + } + if (eap->do_ecmd_cmd != NULL) { + do_cmdline_cmd(eap->do_ecmd_cmd); + } } } @@ -3975,6 +3979,9 @@ static void ex_buffer(exarg_T *eap) static void ex_bmodified(exarg_T *eap) { goto_buffer(eap, DOBUF_MOD, FORWARD, (int)eap->line2); + if (eap->do_ecmd_cmd != NULL) { + do_cmdline_cmd(eap->do_ecmd_cmd); + } } /* @@ -3984,6 +3991,9 @@ static void ex_bmodified(exarg_T *eap) static void ex_bnext(exarg_T *eap) { goto_buffer(eap, DOBUF_CURRENT, FORWARD, (int)eap->line2); + if (eap->do_ecmd_cmd != NULL) { + do_cmdline_cmd(eap->do_ecmd_cmd); + } } /* @@ -3995,6 +4005,9 @@ static void ex_bnext(exarg_T *eap) static void ex_bprevious(exarg_T *eap) { goto_buffer(eap, DOBUF_CURRENT, BACKWARD, (int)eap->line2); + if (eap->do_ecmd_cmd != NULL) { + do_cmdline_cmd(eap->do_ecmd_cmd); + } } /* @@ -4006,6 +4019,9 @@ static void ex_bprevious(exarg_T *eap) static void ex_brewind(exarg_T *eap) { goto_buffer(eap, DOBUF_FIRST, FORWARD, 0); + if (eap->do_ecmd_cmd != NULL) { + do_cmdline_cmd(eap->do_ecmd_cmd); + } } /* @@ -4015,6 +4031,9 @@ static void ex_brewind(exarg_T *eap) static void ex_blast(exarg_T *eap) { goto_buffer(eap, DOBUF_LAST, BACKWARD, 0); + if (eap->do_ecmd_cmd != NULL) { + do_cmdline_cmd(eap->do_ecmd_cmd); + } } int ends_excmd(int c) FUNC_ATTR_CONST |