Mercurial > vim
comparison src/vim9compile.c @ 25939:377a7686a52f v8.2.3503
patch 8.2.3503: Vim9: using g:pat:cmd is confusing
Commit: https://github.com/vim/vim/commit/7b829268921e8fc1c63c34d245063c1c4e7d21af
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Oct 13 15:04:34 2021 +0100
patch 8.2.3503: Vim9: using g:pat:cmd is confusing
Problem: Vim9: using g:pat:cmd is confusing.
Solution: Do not recognize g: as the :global command. Also for s:pat:repl.
(closes #8982)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 13 Oct 2021 16:15:04 +0200 |
parents | d9a0847550c6 |
children | 965a4823e5ef |
comparison
equal
deleted
inserted
replaced
25938:26aa27d37199 | 25939:377a7686a52f |
---|---|
9471 return p; | 9471 return p; |
9472 } | 9472 } |
9473 #endif | 9473 #endif |
9474 | 9474 |
9475 /* | 9475 /* |
9476 * Check if the separator for a :global or :substitute command is OK. | |
9477 */ | |
9478 int | |
9479 check_global_and_subst(char_u *cmd, char_u *arg) | |
9480 { | |
9481 if (arg == cmd + 1 && vim_strchr(":-.", *arg) != NULL) | |
9482 { | |
9483 semsg(_(e_separator_not_supported_str), arg); | |
9484 return FAIL; | |
9485 } | |
9486 if (VIM_ISWHITE(cmd[1])) | |
9487 { | |
9488 semsg(_(e_no_white_space_allowed_before_separator_str), cmd); | |
9489 return FAIL; | |
9490 } | |
9491 return OK; | |
9492 } | |
9493 | |
9494 | |
9495 /* | |
9476 * Add a function to the list of :def functions. | 9496 * Add a function to the list of :def functions. |
9477 * This sets "ufunc->uf_dfunc_idx" but the function isn't compiled yet. | 9497 * This sets "ufunc->uf_dfunc_idx" but the function isn't compiled yet. |
9478 */ | 9498 */ |
9479 static int | 9499 static int |
9480 add_def_function(ufunc_T *ufunc) | 9500 add_def_function(ufunc_T *ufunc) |
10064 ea.cmd = cmd; | 10084 ea.cmd = cmd; |
10065 line = compile_put(p, &ea, &cctx); | 10085 line = compile_put(p, &ea, &cctx); |
10066 break; | 10086 break; |
10067 | 10087 |
10068 case CMD_substitute: | 10088 case CMD_substitute: |
10089 if (check_global_and_subst(ea.cmd, p) == FAIL) | |
10090 goto erret; | |
10069 if (cctx.ctx_skip == SKIP_YES) | 10091 if (cctx.ctx_skip == SKIP_YES) |
10070 line = (char_u *)""; | 10092 line = (char_u *)""; |
10071 else | 10093 else |
10072 { | 10094 { |
10073 ea.arg = p; | 10095 ea.arg = p; |
10130 // heredoc lines have been concatenated with NL | 10152 // heredoc lines have been concatenated with NL |
10131 // characters in get_function_body() | 10153 // characters in get_function_body() |
10132 line = compile_script(line, &cctx); | 10154 line = compile_script(line, &cctx); |
10133 break; | 10155 break; |
10134 | 10156 |
10157 case CMD_global: | |
10158 if (check_global_and_subst(ea.cmd, p) == FAIL) | |
10159 goto erret; | |
10160 // FALLTHROUGH | |
10135 default: | 10161 default: |
10136 // Not recognized, execute with do_cmdline_cmd(). | 10162 // Not recognized, execute with do_cmdline_cmd(). |
10137 ea.arg = p; | 10163 ea.arg = p; |
10138 line = compile_exec(line, &ea, &cctx); | 10164 line = compile_exec(line, &ea, &cctx); |
10139 break; | 10165 break; |