Update runtime files

This commit is contained in:
Bram Moolenaar
2022-09-10 13:13:14 +01:00
parent 2da11a4124
commit 71b6d33976
26 changed files with 498 additions and 140 deletions

View File

@ -1,4 +1,4 @@
*vim9.txt* For Vim version 9.0. Last change: 2022 Jun 25
*vim9.txt* For Vim version 9.0. Last change: 2022 Sep 10
VIM REFERENCE MANUAL by Bram Moolenaar
@ -1311,7 +1311,7 @@ Make sure to define the breakpoint before compiling the outer function.
The "inloop" variable will exist only once, all closures put in the list refer
to the same instance, which in the end will have the value 4. This is
efficient, also when looping many times. If you do want a separate context
for each closure call a function to define it: >
for each closure, call a function to define it: >
def GetClosure(i: number): func
var infunc = i
return () => infunc
@ -1327,6 +1327,30 @@ for each closure call a function to define it: >
In some situations, especially when calling a Vim9 closure from legacy
context, the evaluation will fail. *E1248*
Note that at the script level the loop variable will be invalid after the
loop, also when used in a closure that is called later, e.g. with a timer.
This will generate error |E1302|: >
for n in range(4)
timer_start(500 * n, (_) => {
echowin n
})
endfor
You need to create a closure to store the current value of "n", so that it is
evaluated at the time the closure is created: >
def GetClosure(nr: number): func
return (_) => {
echowindow nr
}
enddef
for n in range(4)
timer_start(500 * n, GetClosure(n))
endfor
Using `echowindow` is useful in a timer, the messages go into a popup and will
not interfere with what the user is doing when it triggers.
Converting a function from legacy to Vim9 ~
*convert_legacy_function_to_vim9*
@ -1618,7 +1642,7 @@ type, it can not be used in Vim9 script.
*E1211* *E1217* *E1218* *E1219* *E1220* *E1221*
*E1222* *E1223* *E1224* *E1225* *E1226* *E1227*
*E1228* *E1238* *E1250* *E1251* *E1252* *E1253*
*E1256* *E1297* *E1298*
*E1256* *E1297* *E1298* *E1301*
Types are checked for most builtin functions to make it easier to spot
mistakes.