Steps to reproduce
Run this shell command:
vim -Nu NONE -S <(tee <<'EOF'
vim9script
def _Inner()
echomsg 'from _Inner()'
enddef
_Inner()
EOF
)
An error is given:
E128: Function name must start with a capital or "s:": _Inner()
Run this other shell command:
vim -Nu NONE -S <(tee <<'EOF'
vim9script
def Outer()
def _Inner()
echomsg 'from _Inner()'
enddef
_Inner()
enddef
Outer()
EOF
)
No error is given. from _Inner() is echo'ed.
Expected behavior
Not sure, but the current situation is confusing. It would be more consistent if both commands succeeded or both failed.
Version of Vim
8.2 Included patches: 1-4319
Environment
Operating system: Ubuntu 20.04.3 LTS
Terminal: xterm
Value of $TERM: xterm-256color
Shell: zsh 5.8
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
Why do we allow function names to start with an underscore when prefixed with s:, but not with g:?
vim9script def s:_Bar() enddef s:_Bar()
no error
vim9script def g:_Bar() enddef g:_Bar()
E128: Function name must start with a capital or "s:": g:_Bar()
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
In legacy, g:_ is a valid prefix:
function g:_Legacy() echomsg 'from g:_Legacy()' endfunction call g:_Legacy()
from g:_Legacy()
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
Allowing s:_Func was not intentional.
In Vim9 script we started disallowing function names starting with underscore, but it wasn't fully done.
I think it is good to first make it consistent, disallow any leading underscore.
I wonder why users would want to define functions starting with an underscore. In some languages this has a meaning (usually private), but in Vim it is not special. We do have the single underscore as the "not used" name. Making a clear separation between them seems useful.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
I wonder why users would want to define functions starting with an underscore. In some languages this has a meaning (usually private), but in Vim it is not special.
I think that in python it means private, but the item can still be accessed. It's just a convention.
If that's the case, maybe the same convention could be useful in Vim. Suppose for some reason, a plugin author really needs a global function to implement some feature. But they want some guarantee that there won't be any conflict in the global user namespace. Prefixing the name of the function with one or two underscores might help then.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
Prefixing the name of the function with one or two underscores might help then.
Ah no, that wouldn't help much. If every plugin author does that, there could be still conflicts.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()