[vim/vim] Vim9: inconsistent rule for function names starting with underscore (Issue #9713)

25 views
Skip to first unread message

lacygoill

unread,
Feb 7, 2022, 10:58:46 AM2/7/22
to vim/vim, Subscribed

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.Message ID: <vim/vim/issues/9713@github.com>

Bram Moolenaar

unread,
Feb 7, 2022, 3:31:47 PM2/7/22
to vim/vim, Subscribed

Closed #9713 via f681cfb.


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.Message ID: <vim/vim/issue/9713/issue_event/6022121476@github.com>

lacygoill

unread,
Feb 7, 2022, 3:51:37 PM2/7/22
to vim/vim, Subscribed

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.Message ID: <vim/vim/issues/9713/1031907953@github.com>

lacygoill

unread,
Feb 7, 2022, 3:52:50 PM2/7/22
to vim/vim, Subscribed

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.Message ID: <vim/vim/issues/9713/1031908947@github.com>

Bram Moolenaar

unread,
Feb 7, 2022, 4:23:23 PM2/7/22
to vim/vim, Subscribed

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.Message ID: <vim/vim/issues/9713/1031938822@github.com>

lacygoill

unread,
Feb 7, 2022, 4:31:54 PM2/7/22
to vim/vim, Subscribed

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.Message ID: <vim/vim/issues/9713/1031946414@github.com>

lacygoill

unread,
Feb 7, 2022, 4:33:17 PM2/7/22
to vim/vim, Subscribed

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.Message ID: <vim/vim/issues/9713/1031947732@github.com>

Reply all
Reply to author
Forward
0 new messages