Patch 8.2.4136
Problem: Vim9: the "autoload" argument of ":vim9script" is not useful.
Solution: Remove the argument. (closes #9555)
Files: runtime/doc/vim9.txt, runtime/doc/repeat.txt, src/vim9script.c,
src/errors.h, src/testdir/test_vim9_import.vim
*** ../vim-8.2.4135/runtime/doc/vim9.txt 2022-01-09 21:32:57.709739119
+0000
--- runtime/doc/vim9.txt 2022-01-18 16:16:24.739338986 +0000
***************
*** 1471,1489 ****
longer and unique, to avoid loading the wrong file.
Note that "after/import" is not used.
Once a vim9 script file has been imported, the result is cached and used the
next time the same script is imported. It will not be read again.
It is not allowed to import the same script twice, also when using two
different "as" names.
! *:import-cycle*
The `import` commands are executed when encountered. If that script (directly
or indirectly) imports the current script, then items defined after the
`import` won't be processed yet. Therefore cyclic imports can exist, but may
result in undefined items.
! Import in an autoload script ~
*vim9-autoload*
For optimal startup speed, loading scripts should be postponed until they are
actually needed. Using the autoload mechanism is recommended:
--- 1483,1510 ----
longer and unique, to avoid loading the wrong file.
Note that "after/import" is not used.
+ If the name does not end in ".vim" then the use of "as name" is required.
+
Once a vim9 script file has been imported, the result is cached and used the
next time the same script is imported. It will not be read again.
It is not allowed to import the same script twice, also when using two
different "as" names.
!
! When using the imported name the dot and the item name must be in the same
! line, there can be no line break: >
! echo that.
! name # Error!
! echo that
! .name # Error!
! < *:import-cycle*
The `import` commands are executed when encountered. If that script (directly
or indirectly) imports the current script, then items defined after the
`import` won't be processed yet. Therefore cyclic imports can exist, but may
result in undefined items.
! Importing an autoload script ~
*vim9-autoload*
For optimal startup speed, loading scripts should be postponed until they are
actually needed. Using the autoload mechanism is recommended:
***************
*** 1502,1532 ****
directory.
2. In the autoload script put the bulk of the code. >
! vim9script autoload
export def Stuff(arg: string)
...
< This goes in .../autoload/for/search.vim.
! Adding "autoload" to `:vim9script` has the effect that "for#search#" will
! be prefixed to every exported item. The prefix is obtained from the file
! name, as you would to manually in a legacy autoload script. Thus the
! exported function can be found with "for#search#Stuff", but you would
! normally use `import autoload` and not need to specify the prefix.
You can split up the functionality and import other scripts from the
autoload script as you like. This way you can share code between plugins.
When compiling a `:def` function and a function in an autoload script is
encountered, the script is not loaded until the `:def` function is called.
This also means you get any errors only at runtime, since the argument and
return types are not known yet.
Import in legacy Vim script ~
If an `import` statement is used in legacy Vim script, the script-local "s:"
! namespace will be used for the imported item, even when "s:" is not specified.
==============================================================================
--- 1523,1568 ----
directory.
2. In the autoload script put the bulk of the code. >
! vim9script
export def Stuff(arg: string)
...
< This goes in .../autoload/for/search.vim.
! Putting the "search.vim" script under the "/autoload/for/" directory has
! the effect that "for#search#" will be prefixed to every exported item. The
! prefix is obtained from the file name, as you would to manually in a
! legacy autoload script. Thus the exported function can be found with
! "for#search#Stuff", but you would normally use `import autoload` and not
! use the prefix.
You can split up the functionality and import other scripts from the
autoload script as you like. This way you can share code between plugins.
+ For defining a mapping that uses the imported autoload script the special key
+ |<ScriptCmd>| is useful. It allows for a command in a mapping to use the
+ script context of where the mapping was defined.
+
When compiling a `:def` function and a function in an autoload script is
encountered, the script is not loaded until the `:def` function is called.
This also means you get any errors only at runtime, since the argument and
return types are not known yet.
+ For testing the |test_override()| function can be used to have the
+ `import autoload` load the script right away, so that the items and types can
+ be checked without waiting for them to be actually used: >
+ test_override('autoload', 1)
+ Reset it later with: >
+ test_override('autoload', 0)
+ Or: >
+ test_override('ALL', 0)
+
Import in legacy Vim script ~
If an `import` statement is used in legacy Vim script, the script-local "s:"
! namespace will be used for the imported items, even when "s:" is not
! specified.
==============================================================================
*** ../vim-8.2.4135/runtime/doc/repeat.txt 2022-01-18 14:16:55.144654083
+0000
--- runtime/doc/repeat.txt 2022-01-18 16:14:19.815588972 +0000
***************
*** 354,365 ****
Vim version, or update Vim to a newer version. See
|vimscript-version| for what changed between versions.
! :vim9s[cript] [noclear] [autoload] *:vim9s* *:vim9script*
Marks a script file as containing |Vim9-script|
commands. Also see |vim9-namespace|.
Must be the first command in the file.
For [noclear] see |vim9-reload|.
- For [autoload] see |vim9-autoload|.
Without the |+eval| feature this changes the syntax
for some commands.
See |:vim9cmd| for executing one command with Vim9
--- 365,375 ----
Vim version, or update Vim to a newer version. See
|vimscript-version| for what changed between versions.
! :vim9s[cript] [noclear] *:vim9s* *:vim9script*
Marks a script file as containing |Vim9-script|
commands. Also see |vim9-namespace|.
Must be the first command in the file.
For [noclear] see |vim9-reload|.
Without the |+eval| feature this changes the syntax
for some commands.
See |:vim9cmd| for executing one command with Vim9
***************
*** 367,374 ****
*:scr* *:scriptnames*
:scr[iptnames] List all sourced script names, in the order
they were
! first sourced. The number is used for the script ID
! |<SID>|.
For a script that was used with `import autoload` but
was not actually sourced yet an "A" is shown after the
script ID.
--- 377,384 ----
*:scr* *:scriptnames*
:scr[iptnames] List all sourced script names, in the order
they were
! first encountered. The number is used for the script
! ID |<SID>|.
For a script that was used with `import autoload` but
was not actually sourced yet an "A" is shown after the
script ID.
*** ../vim-8.2.4135/src/vim9script.c 2022-01-18 13:43:54.303254562 +0000
--- src/vim9script.c 2022-01-18 16:12:25.559830849 +0000
***************
*** 69,75 ****
int sid = current_sctx.sc_sid;
scriptitem_T *si;
int found_noclear = FALSE;
- int found_autoload = FALSE;
char_u *p;
if (!getline_equal(eap->getline, eap->cookie, getsourceline))
--- 69,74 ----
***************
*** 96,115 ****
}
found_noclear = TRUE;
}
- else if (STRNCMP(p, "autoload", 8) == 0 && IS_WHITE_OR_NUL(p[8]))
- {
- if (found_autoload)
- {
- semsg(_(e_duplicate_argument_str), p);
- return;
- }
- found_autoload = TRUE;
- if (script_name_after_autoload(si) == NULL)
- {
-
emsg(_(e_using_autoload_in_script_not_under_autoload_directory));
- return;
- }
- }
else
{
semsg(_(e_invalid_argument_str), eap->arg);
--- 95,100 ----
*** ../vim-8.2.4135/src/errors.h 2022-01-16 19:38:04.218156782 +0000
--- src/errors.h 2022-01-18 16:19:50.862951418 +0000
***************
*** 3208,3215 ****
INIT(= N_("E1261: Cannot import .vim without using \"as\""));
EXTERN char e_cannot_import_same_script_twice_str[]
INIT(= N_("E1262: Cannot import the same script twice: %s"));
! EXTERN char e_using_autoload_in_script_not_under_autoload_directory[]
! INIT(= N_("E1263: Using autoload in a script not under an autoload
directory"));
EXTERN char e_autoload_import_cannot_use_absolute_or_relative_path[]
INIT(= N_("E1264: Autoload import cannot use absolute or relative path:
%s"));
EXTERN char e_cannot_use_partial_here[]
--- 3208,3214 ----
INIT(= N_("E1261: Cannot import .vim without using \"as\""));
EXTERN char e_cannot_import_same_script_twice_str[]
INIT(= N_("E1262: Cannot import the same script twice: %s"));
! // E1263 unused
EXTERN char e_autoload_import_cannot_use_absolute_or_relative_path[]
INIT(= N_("E1264: Autoload import cannot use absolute or relative path:
%s"));
EXTERN char e_cannot_use_partial_here[]
*** ../vim-8.2.4135/src/testdir/test_vim9_import.vim 2022-01-18
14:16:55.144654083 +0000
--- src/testdir/test_vim9_import.vim 2022-01-18 16:22:50.830631423 +0000
***************
*** 1196,1204 ****
var save_rtp = &rtp
exe 'set rtp^=' .. getcwd() .. '/Xdir'
! # when using "vim9script autoload" prefix is not needed
var lines =<< trim END
! vim9script autoload
g:prefixed_loaded += 1
export def Gettest(): string
--- 1196,1204 ----
var save_rtp = &rtp
exe 'set rtp^=' .. getcwd() .. '/Xdir'
! # when the path has "/autoload/" prefix is not needed
var lines =<< trim END
! vim9script
g:prefixed_loaded += 1
export def Gettest(): string
***************
*** 1262,1268 ****
exe 'set rtp^=' .. getcwd() .. '/Xdir'
var lines =<< trim END
! vim9script autoload
export def RetArg(arg: string): string
return arg
--- 1262,1268 ----
exe 'set rtp^=' .. getcwd() .. '/Xdir'
var lines =<< trim END
! vim9script
export def RetArg(arg: string): string
return arg
***************
*** 1300,1306 ****
exe 'set rtp^=' .. getcwd() .. '/Xdir'
var lines =<< trim END
! vim9script autoload
g:loaded_postponed = 'true'
export var variable = 'bla'
--- 1300,1306 ----
exe 'set rtp^=' .. getcwd() .. '/Xdir'
var lines =<< trim END
! vim9script
g:loaded_postponed = 'true'
export var variable = 'bla'
***************
*** 1337,1343 ****
test_override('autoload', 1)
var lines =<< trim END
! vim9script autoload
g:loaded_override = 'true'
export var variable = 'bla'
--- 1337,1343 ----
test_override('autoload', 1)
var lines =<< trim END
! vim9script
g:loaded_override = 'true'
export var variable = 'bla'
***************
*** 1372,1378 ****
exe 'set rtp^=' .. getcwd() .. '/Xdir'
var lines =<< trim END
! vim9script autoload
g:toggle_loaded = 'yes'
--- 1372,1378 ----
exe 'set rtp^=' .. getcwd() .. '/Xdir'
var lines =<< trim END
! vim9script
g:toggle_loaded = 'yes'
***************
*** 1423,1429 ****
vim9script autoload
var n = 0
END
! CheckScriptFailure(lines, 'E1263:')
enddef
def Test_import_autoload_fails()
--- 1423,1435 ----
vim9script autoload
var n = 0
END
! CheckScriptFailure(lines, 'E475: Invalid argument: autoload')
!
! lines =<< trim END
! vim9script noclear noclear
! var n = 0
! END
! CheckScriptFailure(lines, 'E983: Duplicate argument: noclear')
enddef
def Test_import_autoload_fails()
***************
*** 1516,1522 ****
" test using a autoloaded file that is case sensitive
def Test_vim9_autoload_case_sensitive()
var lines =<< trim END
! vim9script autoload
export def CaseSensitive(): string
return 'done'
enddef
--- 1522,1528 ----
" test using a autoloaded file that is case sensitive
def Test_vim9_autoload_case_sensitive()
var lines =<< trim END
! vim9script
export def CaseSensitive(): string
return 'done'
enddef
*** ../vim-8.2.4135/src/version.c 2022-01-18 14:16:55.148654082 +0000
--- src/version.c 2022-01-18 16:24:47.406430623 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4136,
/**/
--
With sufficient thrust, pigs fly just fine.
-- RFC 1925
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20220118162751.A35781C044E%40moolenaar.net.