comparison src/ex_docmd.c @ 19181:94eda51ba9ba v8.2.0149

patch 8.2.0149: maintaining a Vim9 branch separately is more work Commit: https://github.com/vim/vim/commit/8a7d6542b33e5d2b352262305c3bfdb2d14e1cf8 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 26 15:56:19 2020 +0100 patch 8.2.0149: maintaining a Vim9 branch separately is more work Problem: Maintaining a Vim9 branch separately is more work. Solution: Merge the Vim9 script changes.
author Bram Moolenaar <Bram@vim.org>
date Sun, 26 Jan 2020 16:00:05 +0100
parents 69f0e9b5c107
children 133ef7ba4e4e
comparison
equal deleted inserted replaced
19180:8edf0aeb71b9 19181:94eda51ba9ba
25 static char_u *do_one_cmd(char_u **, int, char_u *(*fgetline)(int, void *, int, int), void *cookie); 25 static char_u *do_one_cmd(char_u **, int, char_u *(*fgetline)(int, void *, int, int), void *cookie);
26 static int if_level = 0; // depth in :if 26 static int if_level = 0; // depth in :if
27 #endif 27 #endif
28 static void free_cmdmod(void); 28 static void free_cmdmod(void);
29 static void append_command(char_u *cmd); 29 static void append_command(char_u *cmd);
30 static char_u *find_command(exarg_T *eap, int *full);
31 30
32 #ifndef FEAT_MENU 31 #ifndef FEAT_MENU
33 # define ex_emenu ex_ni 32 # define ex_emenu ex_ni
34 # define ex_menu ex_ni 33 # define ex_menu ex_ni
35 # define ex_menutranslate ex_ni 34 # define ex_menutranslate ex_ni
273 # define ex_const ex_ni 272 # define ex_const ex_ni
274 # define ex_continue ex_ni 273 # define ex_continue ex_ni
275 # define ex_debug ex_ni 274 # define ex_debug ex_ni
276 # define ex_debuggreedy ex_ni 275 # define ex_debuggreedy ex_ni
277 # define ex_delfunction ex_ni 276 # define ex_delfunction ex_ni
277 # define ex_disassemble ex_ni
278 # define ex_echo ex_ni 278 # define ex_echo ex_ni
279 # define ex_echohl ex_ni 279 # define ex_echohl ex_ni
280 # define ex_else ex_ni 280 # define ex_else ex_ni
281 # define ex_endfunction ex_ni 281 # define ex_endfunction ex_ni
282 # define ex_endif ex_ni 282 # define ex_endif ex_ni
298 # define ex_scriptnames ex_ni 298 # define ex_scriptnames ex_ni
299 # define ex_throw ex_ni 299 # define ex_throw ex_ni
300 # define ex_try ex_ni 300 # define ex_try ex_ni
301 # define ex_unlet ex_ni 301 # define ex_unlet ex_ni
302 # define ex_unlockvar ex_ni 302 # define ex_unlockvar ex_ni
303 # define ex_vim9script ex_ni
303 # define ex_while ex_ni 304 # define ex_while ex_ni
305 # define ex_import ex_ni
306 # define ex_export ex_ni
304 #endif 307 #endif
305 #ifndef FEAT_SESSION 308 #ifndef FEAT_SESSION
306 # define ex_loadview ex_ni 309 # define ex_loadview ex_ni
307 #endif 310 #endif
308 #ifndef FEAT_VIMINFO 311 #ifndef FEAT_VIMINFO
1706 */ 1709 */
1707 cmd = ea.cmd; 1710 cmd = ea.cmd;
1708 ea.cmd = skip_range(ea.cmd, NULL); 1711 ea.cmd = skip_range(ea.cmd, NULL);
1709 if (*ea.cmd == '*' && vim_strchr(p_cpo, CPO_STAR) == NULL) 1712 if (*ea.cmd == '*' && vim_strchr(p_cpo, CPO_STAR) == NULL)
1710 ea.cmd = skipwhite(ea.cmd + 1); 1713 ea.cmd = skipwhite(ea.cmd + 1);
1711 p = find_command(&ea, NULL); 1714
1715 #ifdef FEAT_EVAL
1716 if (current_sctx.sc_version == SCRIPT_VERSION_VIM9)
1717 p = find_ex_command(&ea, NULL, lookup_scriptvar, NULL);
1718 else
1719 #endif
1720 p = find_ex_command(&ea, NULL, NULL, NULL);
1712 1721
1713 #ifdef FEAT_EVAL 1722 #ifdef FEAT_EVAL
1714 # ifdef FEAT_PROFILE 1723 # ifdef FEAT_PROFILE
1715 // Count this line for profiling if skip is TRUE. 1724 // Count this line for profiling if skip is TRUE.
1716 if (do_profiling == PROF_YES 1725 if (do_profiling == PROF_YES
1874 // finding the command again. 1883 // finding the command again.
1875 p = (ret 1884 p = (ret
1876 #ifdef FEAT_EVAL 1885 #ifdef FEAT_EVAL
1877 && !aborting() 1886 && !aborting()
1878 #endif 1887 #endif
1879 ) ? find_command(&ea, NULL) : ea.cmd; 1888 ) ? find_ex_command(&ea, NULL, NULL, NULL) : ea.cmd;
1880 } 1889 }
1881 1890
1882 if (p == NULL) 1891 if (p == NULL)
1883 { 1892 {
1884 if (!ea.skip) 1893 if (!ea.skip)
2483 if (ea.errmsg != NULL) 2492 if (ea.errmsg != NULL)
2484 errormsg = _(ea.errmsg); 2493 errormsg = _(ea.errmsg);
2485 } 2494 }
2486 2495
2487 #ifdef FEAT_EVAL 2496 #ifdef FEAT_EVAL
2497 // Set flag that any command was executed, used by ex_vim9script().
2498 if (getline_equal(ea.getline, ea.cookie, getsourceline))
2499 SCRIPT_ITEM(current_sctx.sc_sid).sn_had_command = TRUE;
2500
2488 /* 2501 /*
2489 * If the command just executed called do_cmdline(), any throw or ":return" 2502 * If the command just executed called do_cmdline(), any throw or ":return"
2490 * or ":finish" encountered there must also check the cstack of the still 2503 * or ":finish" encountered there must also check the cstack of the still
2491 * active do_cmdline() that called this do_one_cmd(). Rethrow an uncaught 2504 * active do_cmdline() that called this do_one_cmd(). Rethrow an uncaught
2492 * exception, or reanimate a returned function or finished script file and 2505 * exception, or reanimate a returned function or finished script file and
3106 /* 3119 /*
3107 * Find an Ex command by its name, either built-in or user. 3120 * Find an Ex command by its name, either built-in or user.
3108 * Start of the name can be found at eap->cmd. 3121 * Start of the name can be found at eap->cmd.
3109 * Sets eap->cmdidx and returns a pointer to char after the command name. 3122 * Sets eap->cmdidx and returns a pointer to char after the command name.
3110 * "full" is set to TRUE if the whole command name matched. 3123 * "full" is set to TRUE if the whole command name matched.
3124 *
3125 * If "lookup" is not NULL recognize expression without "eval" or "call" and
3126 * assignment without "let". Sets eap->cmdidx to the command while returning
3127 * "eap->cmd".
3128 *
3111 * Returns NULL for an ambiguous user command. 3129 * Returns NULL for an ambiguous user command.
3112 */ 3130 */
3113 static char_u * 3131 char_u *
3114 find_command(exarg_T *eap, int *full UNUSED) 3132 find_ex_command(
3133 exarg_T *eap,
3134 int *full UNUSED,
3135 int (*lookup)(char_u *, size_t, cctx_T *) UNUSED,
3136 cctx_T *cctx UNUSED)
3115 { 3137 {
3116 int len; 3138 int len;
3117 char_u *p; 3139 char_u *p;
3118 int i; 3140 int i;
3141
3142 #ifdef FEAT_EVAL
3143 /*
3144 * Recognize a Vim9 script function/method call and assignment:
3145 * "lvar = value", "lvar(arg)", "[1, 2 3]->Func()"
3146 */
3147 if (lookup != NULL && (p = to_name_const_end(eap->cmd)) > eap->cmd
3148 && *p != NUL)
3149 {
3150 int oplen;
3151 int heredoc;
3152
3153 // "funcname(" is always a function call.
3154 // "varname[]" is an expression.
3155 // "g:varname" is an expression.
3156 // "varname->expr" is an expression.
3157 if (*p == '('
3158 || *p == '['
3159 || p[1] == ':'
3160 || (*p == '-' && p[1] == '>'))
3161 {
3162 eap->cmdidx = CMD_eval;
3163 return eap->cmd;
3164 }
3165
3166 oplen = assignment_len(skipwhite(p), &heredoc);
3167 if (oplen > 0)
3168 {
3169 // Recognize an assignment if we recognize the variable name:
3170 // "g:var = expr"
3171 // "var = expr" where "var" is a local var name.
3172 if (((p - eap->cmd) > 2 && eap->cmd[1] == ':')
3173 || lookup(eap->cmd, p - eap->cmd, cctx) >= 0)
3174 {
3175 eap->cmdidx = CMD_let;
3176 return eap->cmd;
3177 }
3178 }
3179 }
3180 #endif
3119 3181
3120 /* 3182 /*
3121 * Isolate the command and search for it in the command table. 3183 * Isolate the command and search for it in the command table.
3122 * Exceptions: 3184 * Exceptions:
3123 * - the 'k' command can directly be followed by any character. 3185 * - the 'k' command can directly be followed by any character.
3147 { 3209 {
3148 while (ASCII_ISALPHA(*p)) 3210 while (ASCII_ISALPHA(*p))
3149 ++p; 3211 ++p;
3150 // for python 3.x support ":py3", ":python3", ":py3file", etc. 3212 // for python 3.x support ":py3", ":python3", ":py3file", etc.
3151 if (eap->cmd[0] == 'p' && eap->cmd[1] == 'y') 3213 if (eap->cmd[0] == 'p' && eap->cmd[1] == 'y')
3214 {
3152 while (ASCII_ISALNUM(*p)) 3215 while (ASCII_ISALNUM(*p))
3153 ++p; 3216 ++p;
3217 }
3218 else if (*p == '9' && STRNCMP("vim9", eap->cmd, 4) == 0)
3219 {
3220 // include "9" for "vim9script"
3221 ++p;
3222 while (ASCII_ISALPHA(*p))
3223 ++p;
3224 }
3154 3225
3155 // check for non-alpha command 3226 // check for non-alpha command
3156 if (p == eap->cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL) 3227 if (p == eap->cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL)
3157 ++p; 3228 ++p;
3158 len = (int)(p - eap->cmd); 3229 len = (int)(p - eap->cmd);
3305 3376
3306 // Check built-in commands and user defined commands. 3377 // Check built-in commands and user defined commands.
3307 // For ":2match" and ":3match" we need to skip the number. 3378 // For ":2match" and ":3match" we need to skip the number.
3308 ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name; 3379 ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name;
3309 ea.cmdidx = (cmdidx_T)0; 3380 ea.cmdidx = (cmdidx_T)0;
3310 p = find_command(&ea, &full); 3381 p = find_ex_command(&ea, &full, NULL, NULL);
3311 if (p == NULL) 3382 if (p == NULL)
3312 return 3; 3383 return 3;
3313 if (vim_isdigit(*name) && ea.cmdidx != CMD_match) 3384 if (vim_isdigit(*name) && ea.cmdidx != CMD_match)
3314 return 0; 3385 return 0;
3315 if (*skipwhite(p) != NUL) 3386 if (*skipwhite(p) != NUL)
8556 end_global_changes(); 8627 end_global_changes();
8557 # endif 8628 # endif
8558 } 8629 }
8559 #endif 8630 #endif
8560 8631
8561 #ifdef FEAT_QUICKFIX 8632 #if defined(FEAT_QUICKFIX) || defined(PROTO)
8562 /* 8633 /*
8563 * Returns TRUE if the supplied Ex cmdidx is for a location list command 8634 * Returns TRUE if the supplied Ex cmdidx is for a location list command
8564 * instead of a quickfix command. 8635 * instead of a quickfix command.
8565 */ 8636 */
8566 int 8637 int