• R/O
  • SSH

vim: 提交

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

修订版b09afbebffee898b8b691dc275a989a04f3be7f1 (tree)
时间2020-02-22 02:45:06
作者Bram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.0294: cannot use Ex command that is also a function name

Commit: https://github.com/vim/vim/commit/5b1c8fe3d588ab450d4646a0088db4efda88200a
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Feb 21 18:42:43 2020 +0100

patch 8.2.0294: cannot use Ex command that is also a function name
Problem: Cannot use Ex command that is also a function name.
Solution: Recognize an Ex command by a colon prefix.

更改概述

差异

diff -r fa1ea6285f80 -r b09afbebffee runtime/doc/vim9.txt
--- a/runtime/doc/vim9.txt Fri Feb 21 18:00:06 2020 +0100
+++ b/runtime/doc/vim9.txt Fri Feb 21 18:45:06 2020 +0100
@@ -1,4 +1,4 @@
1-*vim9.txt* For Vim version 8.2. Last change: 2020 Feb 13
1+*vim9.txt* For Vim version 8.2. Last change: 2020 Feb 21
22
33
44 VIM REFERENCE MANUAL by Bram Moolenaar
@@ -140,6 +140,13 @@
140140 "foobar"->Process() " does NOT work
141141 eval "foobar"->Process() " works
142142
143+In case there is ambiguity between a function name and an Ex command, use ":"
144+to make clear you want to use the Ex command. For example, there is both the
145+`:substitute` command and the `substitute()` function. When the line starts
146+with `substitute(` this will use the function, prepend a colon to use the
147+command instead: >
148+ :substitute(pattern(replacement(
149+
143150
144151 No curly braces expansion ~
145152
@@ -175,6 +182,9 @@
175182 call Func(arg) " OK
176183 call Func(
177184 \ arg) " OK
185+ call Func(
186+ \ arg " OK
187+ \ )
178188
179189
180190 Conditions and expressions ~
@@ -254,6 +264,12 @@
254264 :enddef End of a function defined with `:def`.
255265
256266
267+If the script the function is defined in is Vim9 script, then script-local
268+variables can be accessed without the "s:" prefix. They must be defined
269+before the function. If the script the function is defined in is legacy
270+script, then script-local variables must be accessed with the "s:" prefix.
271+
272+
257273 *:disa* *:disassemble*
258274 :disa[ssemble] {func} Show the instructions generated for {func}.
259275 This is for debugging and testing.
diff -r fa1ea6285f80 -r b09afbebffee src/testdir/test_vim9_script.vim
--- a/src/testdir/test_vim9_script.vim Fri Feb 21 18:00:06 2020 +0100
+++ b/src/testdir/test_vim9_script.vim Fri Feb 21 18:45:06 2020 +0100
@@ -570,5 +570,12 @@
570570 delete('XToDelFunc')
571571 enddef
572572
573+def Test_substitute_cmd()
574+ new
575+ setline(1, 'something')
576+ :substitute(some(other(
577+ assert_equal('otherthing', getline(1))
578+enddef
579+
573580
574581 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
diff -r fa1ea6285f80 -r b09afbebffee src/version.c
--- a/src/version.c Fri Feb 21 18:00:06 2020 +0100
+++ b/src/version.c Fri Feb 21 18:45:06 2020 +0100
@@ -739,6 +739,8 @@
739739 static int included_patches[] =
740740 { /* Add new patch number below this line */
741741 /**/
742+ 294,
743+/**/
742744 293,
743745 /**/
744746 292,
diff -r fa1ea6285f80 -r b09afbebffee src/vim9compile.c
--- a/src/vim9compile.c Fri Feb 21 18:00:06 2020 +0100
+++ b/src/vim9compile.c Fri Feb 21 18:45:06 2020 +0100
@@ -4739,6 +4739,8 @@
47394739 */
47404740 for (;;)
47414741 {
4742+ int is_ex_command;
4743+
47424744 if (line != NULL && *line == '|')
47434745 // the line continues after a '|'
47444746 ++line;
@@ -4793,6 +4795,7 @@
47934795 line = compile_block(ea.cmd, &cctx);
47944796 continue;
47954797 }
4798+ is_ex_command = *ea.cmd == ':';
47964799
47974800 /*
47984801 * COMMAND MODIFIERS
@@ -4810,48 +4813,53 @@
48104813 if (checkforcmd(&ea.cmd, "call", 3))
48114814 ea.cmd = skipwhite(ea.cmd);
48124815
4813- // Assuming the command starts with a variable or function name, find
4814- // what follows. Also "&opt = val", "$ENV = val" and "@r = val".
4815- p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@')
4816- ? ea.cmd + 1 : ea.cmd;
4817- p = to_name_end(p);
4818- if (p > ea.cmd && *p != NUL)
4816+ if (!is_ex_command)
48194817 {
4820- int oplen;
4821- int heredoc;
4822-
4823- // "funcname(" is always a function call.
4824- // "varname[]" is an expression.
4825- // "varname->expr" is an expression.
4826- if (*p == '('
4827- || *p == '['
4828- || ((p - ea.cmd) > 2 && ea.cmd[1] == ':')
4829- || (*p == '-' && p[1] == '>'))
4818+ // Assuming the command starts with a variable or function name,
4819+ // find what follows. Also "&opt = val", "$ENV = val" and "@r =
4820+ // val".
4821+ p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@')
4822+ ? ea.cmd + 1 : ea.cmd;
4823+ p = to_name_end(p);
4824+ if (p > ea.cmd && *p != NUL)
48304825 {
4831- // TODO
4832- }
4833-
4834- oplen = assignment_len(skipwhite(p), &heredoc);
4835- if (oplen > 0)
4836- {
4837- // Recognize an assignment if we recognize the variable name:
4838- // "g:var = expr"
4839- // "var = expr" where "var" is a local var name.
4840- // "&opt = expr"
4841- // "$ENV = expr"
4842- // "@r = expr"
4843- if (*ea.cmd == '&'
4844- || *ea.cmd == '$'
4845- || *ea.cmd == '@'
4826+ int oplen;
4827+ int heredoc;
4828+
4829+ // "funcname(" is always a function call.
4830+ // "varname[]" is an expression.
4831+ // "varname->expr" is an expression.
4832+ if (*p == '('
4833+ || *p == '['
48464834 || ((p - ea.cmd) > 2 && ea.cmd[1] == ':')
4847- || lookup_local(ea.cmd, p - ea.cmd, &cctx) >= 0
4848- || lookup_script(ea.cmd, p - ea.cmd) == OK
4849- || find_imported(ea.cmd, p - ea.cmd, &cctx) != NULL)
4835+ || (*p == '-' && p[1] == '>'))
48504836 {
4851- line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx);
4852- if (line == NULL)
4853- goto erret;
4854- continue;
4837+ // TODO
4838+ }
4839+
4840+ oplen = assignment_len(skipwhite(p), &heredoc);
4841+ if (oplen > 0)
4842+ {
4843+ // Recognize an assignment if we recognize the variable
4844+ // name:
4845+ // "g:var = expr"
4846+ // "var = expr" where "var" is a local var name.
4847+ // "&opt = expr"
4848+ // "$ENV = expr"
4849+ // "@r = expr"
4850+ if (*ea.cmd == '&'
4851+ || *ea.cmd == '$'
4852+ || *ea.cmd == '@'
4853+ || ((p - ea.cmd) > 2 && ea.cmd[1] == ':')
4854+ || lookup_local(ea.cmd, p - ea.cmd, &cctx) >= 0
4855+ || lookup_script(ea.cmd, p - ea.cmd) == OK
4856+ || find_imported(ea.cmd, p - ea.cmd, &cctx) != NULL)
4857+ {
4858+ line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx);
4859+ if (line == NULL)
4860+ goto erret;
4861+ continue;
4862+ }
48554863 }
48564864 }
48574865 }
@@ -4860,7 +4868,8 @@
48604868 * COMMAND after range
48614869 */
48624870 ea.cmd = skip_range(ea.cmd, NULL);
4863- p = find_ex_command(&ea, NULL, lookup_local, &cctx);
4871+ p = find_ex_command(&ea, NULL, is_ex_command ? NULL : lookup_local,
4872+ &cctx);
48644873
48654874 if (p == ea.cmd && ea.cmdidx != CMD_SIZE)
48664875 {
Show on old repository browser