summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-06-12 14:53:05 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-12 14:53:05 +0200
commit742357718000927d652b1a98d313a3950571c8ec (patch)
tree2c949be108cedce8153f585a013ca4b13ba67b3e
parent6654ca702ca64c99965efcad3243ea5f95473252 (diff)
downloadvim-git-742357718000927d652b1a98d313a3950571c8ec.tar.gz
patch 8.2.2982: Vim9: future commands are not reserved yetv8.2.2982
Problem: Vim9: future commands are not reserved yet. Solution: Add commands to be implemented later. Make "this" a reserved name.
-rw-r--r--runtime/doc/vim9.txt76
-rw-r--r--src/ex_cmdidxs.h60
-rw-r--r--src/ex_cmds.h12
-rw-r--r--src/testdir/test_vim9_assign.vim2
-rw-r--r--src/version.c2
-rw-r--r--src/vim9script.c1
6 files changed, 111 insertions, 42 deletions
diff --git a/runtime/doc/vim9.txt b/runtime/doc/vim9.txt
index 6c2588271..406aedcfe 100644
--- a/runtime/doc/vim9.txt
+++ b/runtime/doc/vim9.txt
@@ -1,4 +1,4 @@
-*vim9.txt* For Vim version 8.2. Last change: 2021 May 26
+*vim9.txt* For Vim version 8.2. Last change: 2021 Jun 12
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -169,6 +169,14 @@ created yet. In this case you can call `execute()` to invoke it at runtime. >
used for the command or inside a `:try` block), does not get a range passed
cannot be a "dict" function, and can always be a closure.
+Later classes will be added, which replaces the "dict function" mechanism.
+For now you will need to pass the dictionary explicitly: >
+ def DictFunc(d: dict<any>, arg: string)
+ echo d[arg]
+ enddef
+ var d = {item: 'value', func: DictFunc}
+ d.func(d, 'item')
+
The argument types and return type need to be specified. The "any" type can
be used, type checking will then be done at runtime, like with legacy
functions.
@@ -445,7 +453,7 @@ it is the start of a lambda or a dictionary, which is now more complicated
because of the use of argument types.
To avoid these problems Vim9 script uses a different syntax for a lambda,
-which is similar to Javascript: >
+which is similar to JavaScript: >
var Lambda = (arg) => expression
No line break is allowed in the arguments of a lambda up to and including the
@@ -522,7 +530,7 @@ And when a dict spans multiple lines: >
one: 1,
two: 2,
}
-Function call: >
+With a function call: >
var result = Func(
arg1,
arg2
@@ -555,10 +563,31 @@ at the start of the line indicates line continuation: >
| echo 'match'
| endif
+Note that this means that in heredoc the first line cannot be a bar: >
+ var lines =<< trim END
+ | this doesn't work
+ END
+Either use an empty line at the start or do not use heredoc. Or temporarily
+add the "C" flag to 'cpoptions': >
+ set cpo+=C
+ var lines =<< trim END
+ | this doesn't work
+ END
+ set cpo-=C
+If the heredoc is inside a function 'cpoptions' must be set before :def and
+restored after the :enddef.
+
+In places where line continuation with a backslash is still needed, such as
+splitting up a long Ex command, comments can start with #\ instead of "\: >
+ syn region Text
+ \ start='foo'
+ #\ comment
+ \ end='bar'
+
< *E1050*
To make it possible for the operator at the start of the line to be
-recognized, it is required to put a colon before a range. This will add
-"start" and print: >
+recognized, it is required to put a colon before a range. This example will
+add "start" and print: >
var result = start
+ print
Like this: >
@@ -610,6 +639,9 @@ Notes:
< This does not work: >
echo [1, 2]
[3, 4]
+- In some cases it is difficult for Vim to parse a command, especially when
+ commands are used as an argument to another command, such as `windo`. In
+ those cases the line continuation with a backslash has to be used.
White space ~
@@ -1240,9 +1272,10 @@ Exporting an item can be written as: >
export const someValue = ...
export def MyFunc() ...
export class MyClass ...
+ export interface MyClass ...
As this suggests, only constants, variables, `:def` functions and classes can
-be exported. {not implemented yet: export class}
+be exported. {not implemented yet: class, interface}
*E1042*
`:export` can only be used in Vim9 script, at the script level.
@@ -1342,27 +1375,46 @@ implementing classes is going to be a lot of work, it is left for the future.
For now we'll just make sure classes can be added later.
Thoughts:
-- `class` / `endclass`, everything in one file
-- Class names are always CamelCase
-- Single constructor
+- `class` / `endclass`, the whole class must be in one file
+- Class names are always CamelCase (to avoid a name clash with builtin types)
+- A single constructor called "constructor"
- Single inheritance with `class ThisClass extends BaseClass`
-- `abstract class`
-- `interface` (Abstract class without any implementation)
+- `abstract class` (class with incomplete implementation)
+- `interface` / `endinterface` (abstract class without any implementation)
- `class SomeClass implements SomeInterface`
- Generics for class: `class <Tkey, Tentry>`
- Generics for function: `def <Tkey> GetLast(key: Tkey)`
-Again, much of this is from TypeScript.
+Again, much of this is from TypeScript with a slightly different syntax.
Some things that look like good additions:
- Use a class as an interface (like Dart)
- Extend a class with methods, using an import (like Dart)
+- Mixins
+- For testing: Mock mechanism
An important class that will be provided is "Promise". Since Vim is single
threaded, connecting asynchronous operations is a natural way of allowing
plugins to do their work without blocking the user. It's a uniform way to
invoke callbacks and handle timeouts and errors.
+Some examples: >
+
+ abstract class Person
+ static const prefix = 'xxx'
+ var name: string
+
+ def constructor(name: string)
+ this.name = name;
+ enddef
+
+ def display(): void
+ echo name
+ enddef
+
+ abstract def find(string): Person
+ endclass
+
==============================================================================
9. Rationale *vim9-rationale*
diff --git a/src/ex_cmdidxs.h b/src/ex_cmdidxs.h
index 76b6dff05..3ad1cd8ec 100644
--- a/src/ex_cmdidxs.h
+++ b/src/ex_cmdidxs.h
@@ -6,31 +6,31 @@
static const unsigned short cmdidxs1[26] =
{
/* a */ 0,
- /* b */ 19,
- /* c */ 43,
- /* d */ 110,
- /* e */ 135,
- /* f */ 162,
- /* g */ 179,
- /* h */ 185,
- /* i */ 194,
- /* j */ 213,
- /* k */ 215,
- /* l */ 220,
- /* m */ 283,
- /* n */ 301,
- /* o */ 321,
- /* p */ 333,
- /* q */ 372,
- /* r */ 375,
- /* s */ 395,
- /* t */ 464,
- /* u */ 510,
- /* v */ 521,
- /* w */ 542,
- /* x */ 556,
- /* y */ 566,
- /* z */ 567
+ /* b */ 20,
+ /* c */ 44,
+ /* d */ 111,
+ /* e */ 136,
+ /* f */ 164,
+ /* g */ 181,
+ /* h */ 187,
+ /* i */ 196,
+ /* j */ 216,
+ /* k */ 218,
+ /* l */ 223,
+ /* m */ 286,
+ /* n */ 304,
+ /* o */ 324,
+ /* p */ 336,
+ /* q */ 375,
+ /* r */ 378,
+ /* s */ 398,
+ /* t */ 468,
+ /* u */ 514,
+ /* v */ 525,
+ /* w */ 546,
+ /* x */ 560,
+ /* y */ 570,
+ /* z */ 571
};
/*
@@ -41,15 +41,15 @@ static const unsigned short cmdidxs1[26] =
*/
static const unsigned char cmdidxs2[26][26] =
{ /* a b c d e f g h i j k l m n o p q r s t u v w x y z */
- /* a */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 0, 0, 0, 7, 15, 0, 16, 0, 0, 0, 0, 0 },
+ /* a */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 0, 0, 0, 8, 16, 0, 17, 0, 0, 0, 0, 0 },
/* b */ { 2, 0, 0, 5, 6, 8, 0, 0, 0, 0, 0, 9, 10, 11, 12, 13, 0, 14, 0, 0, 0, 0, 23, 0, 0, 0 },
/* c */ { 3, 12, 16, 18, 20, 22, 25, 0, 0, 0, 0, 33, 38, 41, 47, 57, 59, 60, 61, 0, 63, 0, 66, 0, 0, 0 },
/* d */ { 0, 0, 0, 0, 0, 0, 0, 0, 8, 18, 0, 19, 0, 0, 20, 0, 0, 22, 23, 0, 0, 0, 0, 0, 0, 0 },
- /* e */ { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 11, 0, 0, 0, 0, 0, 0, 0, 21, 0, 22, 0, 0 },
+ /* e */ { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 11, 0, 0, 0, 0, 0, 0, 0, 22, 0, 23, 0, 0 },
/* f */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0 },
/* g */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 4, 5, 0, 0, 0, 0 },
/* h */ { 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- /* i */ { 1, 0, 0, 0, 0, 3, 0, 0, 0, 4, 0, 5, 6, 0, 0, 0, 0, 0, 14, 0, 16, 0, 0, 0, 0, 0 },
+ /* i */ { 1, 0, 0, 0, 0, 3, 0, 0, 0, 4, 0, 5, 6, 0, 0, 0, 0, 0, 15, 0, 17, 0, 0, 0, 0, 0 },
/* j */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
/* k */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
/* l */ { 3, 11, 15, 19, 20, 25, 28, 33, 0, 0, 0, 35, 38, 41, 45, 51, 0, 53, 62, 54, 55, 59, 61, 0, 0, 0 },
@@ -59,7 +59,7 @@ static const unsigned char cmdidxs2[26][26] =
/* p */ { 1, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 16, 17, 26, 0, 27, 0, 28, 0 },
/* q */ { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
/* r */ { 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 19, 0, 0, 0, 0 },
- /* s */ { 2, 6, 15, 0, 19, 23, 0, 25, 26, 0, 0, 29, 31, 35, 39, 41, 0, 50, 0, 51, 0, 63, 64, 0, 65, 0 },
+ /* s */ { 2, 6, 15, 0, 19, 23, 0, 25, 26, 0, 0, 29, 31, 35, 39, 41, 0, 50, 0, 51, 0, 64, 65, 0, 66, 0 },
/* t */ { 2, 0, 19, 0, 24, 26, 0, 27, 0, 28, 0, 29, 33, 36, 38, 39, 0, 40, 42, 0, 43, 0, 0, 0, 45, 0 },
/* u */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
/* v */ { 1, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 12, 15, 0, 0, 0, 0, 18, 0, 19, 0, 0, 0, 0, 0 },
@@ -69,4 +69,4 @@ static const unsigned char cmdidxs2[26][26] =
/* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
-static const int command_count = 584;
+static const int command_count = 588;
diff --git a/src/ex_cmds.h b/src/ex_cmds.h
index 8a1ed5ed6..8ddac37b5 100644
--- a/src/ex_cmds.h
+++ b/src/ex_cmds.h
@@ -122,6 +122,9 @@ EXCMD(CMD_abclear, "abclear", ex_abclear,
EXCMD(CMD_aboveleft, "aboveleft", ex_wrongmodifier,
EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM,
ADDR_NONE),
+EXCMD(CMD_abstract, "abstract", ex_ni,
+ EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
+ ADDR_NONE),
EXCMD(CMD_all, "all", ex_all,
EX_BANG|EX_RANGE|EX_COUNT|EX_TRLBAR,
ADDR_OTHER),
@@ -551,6 +554,9 @@ EXCMD(CMD_emenu, "emenu", ex_emenu,
EXCMD(CMD_endif, "endif", ex_endif,
EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
+EXCMD(CMD_endinterface, "endinterface", ex_ni,
+ EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
+ ADDR_NONE),
EXCMD(CMD_endclass, "endclass", ex_ni,
EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
@@ -734,6 +740,9 @@ EXCMD(CMD_inoremenu, "inoremenu", ex_menu,
EXCMD(CMD_intro, "intro", ex_intro,
EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
+EXCMD(CMD_interface, "interface", ex_ni,
+ EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
+ ADDR_NONE),
EXCMD(CMD_isearch, "isearch", ex_findpat,
EX_BANG|EX_RANGE|EX_DFLALL|EX_WHOLEFOLD|EX_EXTRA|EX_CMDWIN|EX_LOCK_OK,
ADDR_LINES),
@@ -1463,6 +1472,9 @@ EXCMD(CMD_startgreplace, "startgreplace", ex_startinsert,
EXCMD(CMD_startreplace, "startreplace", ex_startinsert,
EX_BANG|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
+EXCMD(CMD_static, "static", ex_ni,
+ EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
+ ADDR_NONE),
EXCMD(CMD_stopinsert, "stopinsert", ex_stopinsert,
EX_BANG|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim
index b8c643363..7b7b62305 100644
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -982,6 +982,8 @@ def Test_assignment_failure()
CheckDefFailure(['var true = 1'], 'E1034:')
CheckDefFailure(['var false = 1'], 'E1034:')
+ CheckDefFailure(['var null = 1'], 'E1034:')
+ CheckDefFailure(['var this = 1'], 'E1034:')
CheckDefFailure(['[a; b; c] = g:list'], 'E452:')
CheckDefExecFailure(['var a: number',
diff --git a/src/version.c b/src/version.c
index 15ee76aed..17ae9a4de 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2982,
+/**/
2981,
/**/
2980,
diff --git a/src/vim9script.c b/src/vim9script.c
index fbb815c28..7078cbe9c 100644
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -979,6 +979,7 @@ static char *reserved[] = {
"true",
"false",
"null",
+ "this",
NULL
};