summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-02-21 18:42:43 +0100
committerBram Moolenaar <Bram@vim.org>2020-02-21 18:42:43 +0100
commit5b1c8fe3d588ab450d4646a0088db4efda88200a (patch)
treedcfaed845bd66c02605092c0d75ebaba499c800b /src
parent818fc9ad143911b2faa0d7cee86724aa70a02080 (diff)
downloadvim-git-5b1c8fe3d588ab450d4646a0088db4efda88200a.tar.gz
patch 8.2.0294: cannot use Ex command that is also a function namev8.2.0294
Problem: Cannot use Ex command that is also a function name. Solution: Recognize an Ex command by a colon prefix.
Diffstat (limited to 'src')
-rw-r--r--src/testdir/test_vim9_script.vim7
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c87
3 files changed, 57 insertions, 39 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index f7205b3d5..107ee0245 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -570,5 +570,12 @@ def Test_delfunc()
delete('XToDelFunc')
enddef
+def Test_substitute_cmd()
+ new
+ setline(1, 'something')
+ :substitute(some(other(
+ assert_equal('otherthing', getline(1))
+enddef
+
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
diff --git a/src/version.c b/src/version.c
index 196941ff4..043931dd6 100644
--- a/src/version.c
+++ b/src/version.c
@@ -739,6 +739,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 294,
+/**/
293,
/**/
292,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index e35494454..aeb950ca6 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -4739,6 +4739,8 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
*/
for (;;)
{
+ int is_ex_command;
+
if (line != NULL && *line == '|')
// the line continues after a '|'
++line;
@@ -4793,6 +4795,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
line = compile_block(ea.cmd, &cctx);
continue;
}
+ is_ex_command = *ea.cmd == ':';
/*
* COMMAND MODIFIERS
@@ -4810,48 +4813,53 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
if (checkforcmd(&ea.cmd, "call", 3))
ea.cmd = skipwhite(ea.cmd);
- // Assuming the command starts with a variable or function name, find
- // what follows. Also "&opt = val", "$ENV = val" and "@r = val".
- p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@')
- ? ea.cmd + 1 : ea.cmd;
- p = to_name_end(p);
- if (p > ea.cmd && *p != NUL)
+ if (!is_ex_command)
{
- int oplen;
- int heredoc;
-
- // "funcname(" is always a function call.
- // "varname[]" is an expression.
- // "varname->expr" is an expression.
- if (*p == '('
- || *p == '['
- || ((p - ea.cmd) > 2 && ea.cmd[1] == ':')
- || (*p == '-' && p[1] == '>'))
- {
- // TODO
- }
-
- oplen = assignment_len(skipwhite(p), &heredoc);
- if (oplen > 0)
+ // Assuming the command starts with a variable or function name,
+ // find what follows. Also "&opt = val", "$ENV = val" and "@r =
+ // val".
+ p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@')
+ ? ea.cmd + 1 : ea.cmd;
+ p = to_name_end(p);
+ if (p > ea.cmd && *p != NUL)
{
- // Recognize an assignment if we recognize the variable name:
- // "g:var = expr"
- // "var = expr" where "var" is a local var name.
- // "&opt = expr"
- // "$ENV = expr"
- // "@r = expr"
- if (*ea.cmd == '&'
- || *ea.cmd == '$'
- || *ea.cmd == '@'
+ int oplen;
+ int heredoc;
+
+ // "funcname(" is always a function call.
+ // "varname[]" is an expression.
+ // "varname->expr" is an expression.
+ if (*p == '('
+ || *p == '['
|| ((p - ea.cmd) > 2 && ea.cmd[1] == ':')
- || lookup_local(ea.cmd, p - ea.cmd, &cctx) >= 0
- || lookup_script(ea.cmd, p - ea.cmd) == OK
- || find_imported(ea.cmd, p - ea.cmd, &cctx) != NULL)
+ || (*p == '-' && p[1] == '>'))
{
- line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx);
- if (line == NULL)
- goto erret;
- continue;
+ // TODO
+ }
+
+ oplen = assignment_len(skipwhite(p), &heredoc);
+ if (oplen > 0)
+ {
+ // Recognize an assignment if we recognize the variable
+ // name:
+ // "g:var = expr"
+ // "var = expr" where "var" is a local var name.
+ // "&opt = expr"
+ // "$ENV = expr"
+ // "@r = expr"
+ if (*ea.cmd == '&'
+ || *ea.cmd == '$'
+ || *ea.cmd == '@'
+ || ((p - ea.cmd) > 2 && ea.cmd[1] == ':')
+ || lookup_local(ea.cmd, p - ea.cmd, &cctx) >= 0
+ || lookup_script(ea.cmd, p - ea.cmd) == OK
+ || find_imported(ea.cmd, p - ea.cmd, &cctx) != NULL)
+ {
+ line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx);
+ if (line == NULL)
+ goto erret;
+ continue;
+ }
}
}
}
@@ -4860,7 +4868,8 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
* COMMAND after range
*/
ea.cmd = skip_range(ea.cmd, NULL);
- p = find_ex_command(&ea, NULL, lookup_local, &cctx);
+ p = find_ex_command(&ea, NULL, is_ex_command ? NULL : lookup_local,
+ &cctx);
if (p == ea.cmd && ea.cmdidx != CMD_SIZE)
{