Re: [vim/vim] Refined autoload mechanism explanation (PR #20833)
h_east (Vim Github Repository) <[email protected]>
| Newsgroups | gmane.editors.vim.devel |
|---|---|
| Message-ID | <vim/vim/pull/20833/[email protected]> |
h-east left a comment (vim/vim#20833)
Thanks for the updates on the other points.
You are right that the two snippets are different mechanisms, and my quote was
a poor choice for that reason.
The conclusion still does not follow, though. The evidence for "52.4 does not
apply to Vim9" is a script that prints `false true false true`, and that comes
from the guard, not from the mechanism:
```vim
export var did_load = false
```
A declaration is a statement. `noclear` keeps the item across a re-source, but
the initialiser runs every time, so the value is back to `false` before the
`if` is reached. On a re-source `scriptfile.c` marks the existing script
variables with `DI_FLAGS_RELOAD`, which is what lets the declaration run again
without E1041.
Guard on the existence of an item rather than on a value, which is what `:help
vim9-reload` does with `exists('*SomeFunc')`. 52.4 defines no function on the
first source, so the function cannot serve as the marker there, but the command
it does define can. With that, 52.4 keeps working in Vim9, structure unchanged:
```vim
vim9script noclear
if !exists(':BNRead')
command -nargs=* BNRead g:BufNetRead(<f-args>)
exe 'au FuncUndefined BufNet* source ' .. expand('<sfile>')
finish
endif
def g:BufNetRead(a: string)
...
enddef
```
After the first source only the command exists, the function is not defined
yet. Calling `g:BufNetRead()` fires `FuncUndefined`, the script is sourced
again, the guard lets it through, and the function is defined and runs. That is
the same deferred loading 52.4 describes.
So the note would not be correct. What is worth saying instead is that new
Vim9 code has `import autoload` for this purpose, which is a better thing to
point at than the `FuncUndefined` trick.
On your closing remark: agreed, technical questions deserve verification rather
than being taken at face value. That is the standard I applied to your test
before writing the review.
--
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/pull/20833#issuecomment-5084787609
You are receiving this because you are subscribed to this thread.
Message ID: <vim/vim/pull/20833/[email protected]>
--
--
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 visit https://groups.google.com/d/msgid/vim_dev/vim/vim/pull/20833/c5084787609%40github.com.