Skip to content

Commit 46d78a0

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 78ff9e9 + b5ed266 commit 46d78a0

31 files changed

Lines changed: 933 additions & 318 deletions

runtime/doc/vim9.txt

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,17 @@ comments start with #. >
7171
7272
The reason is that a double quote can also be the start of a string. In many
7373
places, especially halfway an expression with a line break, it's hard to tell
74-
what the meaning is. To avoid confusion only # comments are recognized.
75-
This is the same as in shell scripts and Python programs.
74+
what the meaning is, since both a string and a comment can be followed by
75+
arbitrary text. To avoid confusion only # comments are recognized. This is
76+
the same as in shell scripts and Python programs.
7677

7778
In Vi # is a command to list text with numbers. In Vim9 script you can use
7879
`:number` for that. >
79-
101number
80+
101 number
8081
8182
To improve readability there must be a space between a command and the #
8283
that starts a comment. Note that #{ is the start of a dictionary, therefore
83-
it cannot start a comment.
84+
it does not start a comment.
8485

8586

8687
Vim9 functions ~
@@ -93,7 +94,7 @@ The syntax is strict, to enforce code that is easy to read and understand.
9394

9495
Compilation is done when the function is first called, or when the
9596
`:defcompile` command is encountered in the script where the function was
96-
defined.
97+
defined. `:disassemble` also compiles the function.
9798

9899
`:def` has no options like `:function` does: "range", "abort", "dict" or
99100
"closure". A `:def` function always aborts on an error, does not get a range
@@ -104,7 +105,7 @@ be used, type checking will then be done at runtime, like with legacy
104105
functions.
105106

106107
Arguments are accessed by name, without "a:". There is no "a:" dictionary or
107-
"a:000" list.
108+
"a:000" list. Just like any other language.
108109

109110
Variable arguments are defined as the last argument, with a name and have a
110111
list type, similar to Typescript. For example, a list of numbers: >
@@ -216,29 +217,29 @@ Functions can be called without `:call`: >
216217
Using `:call` is still possible, but this is discouraged.
217218

218219
A method call without `eval` is possible, so long as the start is an
219-
identifier or can't be an Ex command. It does NOT work for string constants: >
220-
myList->add(123) # works
221-
g:myList->add(123) # works
222-
[1, 2, 3]->Process() # works
223-
#{a: 1, b: 2}->Process() # works
224-
{'a': 1, 'b': 2}->Process() # works
225-
"foobar"->Process() # does NOT work
226-
("foobar")->Process() # works
227-
'foobar'->Process() # does NOT work
228-
('foobar')->Process() # works
229-
230-
In case there is ambiguity between a function name and an Ex command, use ":"
231-
to make clear you want to use the Ex command. For example, there is both the
232-
`:substitute` command and the `substitute()` function. When the line starts
233-
with `substitute(` this will use the function, prepend a colon to use the
234-
command instead: >
220+
identifier or can't be an Ex command. Examples: >
221+
myList->add(123)
222+
g:myList->add(123)
223+
[1, 2, 3]->Process()
224+
#{a: 1, b: 2}->Process()
225+
{'a': 1, 'b': 2}->Process()
226+
"foobar"->Process()
227+
("foobar")->Process()
228+
'foobar'->Process()
229+
('foobar')->Process()
230+
231+
In rare case there is ambiguity between a function name and an Ex command, use
232+
":" to make clear you want to use the Ex command. For example, there is both
233+
the `:substitute` command and the `substitute()` function. When the line
234+
starts with `substitute(` this will use the function. Prepend a colon to use
235+
the command instead: >
235236
:substitute(pattern (replacement (
236237
237238
Note that while variables need to be defined before they can be used,
238239
functions can be called before being defined. This is required to be able
239240
have cyclic dependencies between functions. It is slightly less efficient,
240241
since the function has to be looked up by name. And a typo in the function
241-
name will only be found when the call is executed.
242+
name will only be found when the function is called.
242243

243244

244245
Omitting function() ~
@@ -347,9 +348,10 @@ No curly braces expansion ~
347348
|curly-braces-names| cannot be used.
348349

349350

350-
No :append, :change or :insert ~
351+
No :xit, :append, :change or :insert ~
351352

352-
These commands are too quickly confused with local variable names.
353+
These commands are too easily confused with local variable names. Instead of
354+
`:x` or `:xit` you can use `:exit`.
353355

354356

355357
Comparators ~

src/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,10 +2327,7 @@ test_libvterm:
23272327

23282328
# Run individual OLD style test.
23292329
# These do not depend on the executable, compile it when needed.
2330-
test1 \
2331-
test42 test49 \
2332-
test52 test59 \
2333-
test70:
2330+
test1 test42 test49 test59:
23342331
cd testdir; rm -f $@.out; $(MAKE) -f Makefile $@.out VIMPROG=../$(VIMTESTTARGET) $(GUI_TESTARG) SCRIPTSOURCE=../$(SCRIPTSOURCE)
23352332

23362333
# Run individual NEW style test.

src/auto/configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12239,7 +12239,7 @@ if test "x$olibs" = "x$LIBS"; then
1223912239
$as_echo_n "checking for tgetent()... " >&6; }
1224012240
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1224112241
/* end confdefs.h. */
12242-
12242+
int tgetent(char *, const char *);
1224312243
int
1224412244
main ()
1224512245
{

src/configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3608,7 +3608,7 @@ fi
36083608

36093609
if test "x$olibs" = "x$LIBS"; then
36103610
AC_MSG_CHECKING([for tgetent()])
3611-
AC_TRY_LINK([],
3611+
AC_TRY_LINK([int tgetent(char *, const char *);],
36123612
[char s[10000]; int res = tgetent(s, "thisterminaldoesnotexist");],
36133613
AC_MSG_RESULT(yes),
36143614
AC_MSG_ERROR([NOT FOUND!

src/eval.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3464,7 +3464,7 @@ eval_index(
34643464
* dict.name
34653465
*/
34663466
key = *arg + 1;
3467-
for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len)
3467+
for (len = 0; eval_isdictc(key[len]); ++len)
34683468
;
34693469
if (len == 0)
34703470
return FAIL;
@@ -4997,7 +4997,7 @@ find_name_end(
49974997
&& (eval_isnamec(*p)
49984998
|| (*p == '{' && !vim9script)
49994999
|| ((flags & FNE_INCL_BR) && (*p == '['
5000-
|| (*p == '.' && eval_isnamec1(p[1]))))
5000+
|| (*p == '.' && eval_isdictc(p[1]))))
50015001
|| mb_nest != 0
50025002
|| br_nest != 0); MB_PTR_ADV(p))
50035003
{
@@ -5128,7 +5128,7 @@ make_expanded_name(
51285128
int
51295129
eval_isnamec(int c)
51305130
{
5131-
return (ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR);
5131+
return ASCII_ISALNUM(c) || c == '_' || c == ':' || c == AUTOLOAD_CHAR;
51325132
}
51335133

51345134
/*
@@ -5138,7 +5138,17 @@ eval_isnamec(int c)
51385138
int
51395139
eval_isnamec1(int c)
51405140
{
5141-
return (ASCII_ISALPHA(c) || c == '_');
5141+
return ASCII_ISALPHA(c) || c == '_';
5142+
}
5143+
5144+
/*
5145+
* Return TRUE if character "c" can be used as the first character of a
5146+
* dictionary key.
5147+
*/
5148+
int
5149+
eval_isdictc(int c)
5150+
{
5151+
return ASCII_ISALNUM(c) || c == '_';
51425152
}
51435153

51445154
/*
@@ -5171,8 +5181,7 @@ handle_subscript(
51715181
// the next line then consume the line break.
51725182
p = eval_next_non_blank(*arg, evalarg, &getnext);
51735183
if (getnext
5174-
&& ((rettv->v_type == VAR_DICT && *p == '.'
5175-
&& ASCII_ISALPHA(p[1]))
5184+
&& ((rettv->v_type == VAR_DICT && *p == '.' && eval_isdictc(p[1]))
51765185
|| (*p == '-' && p[1] == '>'
51775186
&& (p[2] == '{' || ASCII_ISALPHA(p[2])))))
51785187
{

src/ex_cmds.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,6 +3176,10 @@ ex_append(exarg_T *eap)
31763176
int vcol;
31773177
int empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
31783178

3179+
#ifdef FEAT_EVAL
3180+
if (not_in_vim9(eap) == FAIL)
3181+
return;
3182+
#endif
31793183
// the ! flag toggles autoindent
31803184
if (eap->forceit)
31813185
curbuf->b_p_ai = !curbuf->b_p_ai;
@@ -3317,6 +3321,10 @@ ex_change(exarg_T *eap)
33173321
{
33183322
linenr_T lnum;
33193323

3324+
#ifdef FEAT_EVAL
3325+
if (not_in_vim9(eap) == FAIL)
3326+
return;
3327+
#endif
33203328
if (eap->line2 >= eap->line1
33213329
&& u_save(eap->line1 - 1, eap->line2 + 1) == FAIL)
33223330
return;

0 commit comments

Comments
 (0)