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)

On 1, "without using globals": that works as well. Same structure as 52.4, one
file, no `g:` anywhere, with a script-local `def`:

```vim
	vim9script noclear

	if !exists(':BNRead')
	  command -nargs=* BNRead BufNetRead(<f-args>)
	  exe 'au FuncUndefined BufNet* source ' .. expand('<script>')
	  finish
	endif

	def BufNetRead(...args: list<string>)
	  echo 'BufNetRead(' .. string(args) .. ')'
	enddef
```

The first source defines only the command. `:BNRead abc def` then fires
`FuncUndefined`, the script is sourced again, the `def` is defined and the call
runs. Checked here with 9.2.

`BufNetRead()` above is script-local, not global. From `:help vim9-scopes`:

	When using `:function` or `:def` to specify a new function at the
	script level in a Vim9 script, the function is local to the script.
	Like prefixing "s:" in legacy script.

The only change from 52.4 is that the guard tests the existence of an item
instead of a value, for the reason given in my previous comment. That is also
the counter-example asked for in 2.

3 is fair for the section as it stands. 52.4 is built around a single file, so
`import autoload` does not fit into it unchanged.

One remark on the additional file, though. A separate script under `autoload/`
is the normal layout for Vim plugins, and close to all of them are written that
way, so it is the convention rather than an extra cost.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/pull/20833#issuecomment-5088464407
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/c5088464407%40github.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.