> Wether a function is script-local or global (when not using a "s:" or "g:" prefix) depends on the script it's defined in
> The rule is "at the script level, the type of script defines what the scope of the items is". I think that's easy to understand. You know, I think the other rule is arguably easier to understand: "def functions are always script-local". What are people's thoughts ? In a sense the rule above could be used to advantage for "internal linkage" functions of a plugin. For example: - I have a "public" interface of "function" functions - these are legacy vimscript for compatibility/interop - internally in my "plugin" (let's say a single .vim file), I have some def functions for performance, convenience - they are script-local by default. I admit the current behaviour is not difficult to explain or learn, but perhaps the "def functions are always internal unless "exported" or "g:" prefixed" is simpler logically? On Thursday, February 17, 2022 at 10:59:18 AM UTC Bram Moolenaar wrote: > > Maxim Kim wrote: > > > Shouldn't def functions be prohibited in legacy vimscript? > > > > > https://vi.stackexchange.com/questions/36829/how-can-i-define-vim9-functions-and-vim9-lambdas-in-a-vim9-script > > > > Basically if you add > > > > def! Hello() > > echo "hello world" > > enddef > > > > to a regular legacy vim file (.vimrc, for example), function Hello is > > globally defined and one can :call Hello() and get echoed "hello world". > > In case you have some code that needs to be executed fast, but the rest > of the script has some stuff you don't want to convert to Vim9, then > putting that code in a compiled function is very useful. > > Wether a function is script-local or global (when not using a "s:" or > "g:" prefix) depends on the script it's defined in. An alternatie could > be to make :def functions always script-local by default, then you would > have to use "g:" to make them global. I don't think this helps and it > can be confusing. > > The rule is "at the script level, the type of script defines what the > scope of the items is". I think that's easy to understand. > > -- > Keyboard not found. Think ENTER to continue. > > /// Bram Moolenaar -- br...@moolenaar.net -- 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 vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/5e525c68-abc8-44c7-8493-a8703462a849n%40googlegroups.com.