Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vitalizer: Wrap function() to ignore error when creating module function list #553

Merged
merged 2 commits into from
Nov 23, 2017

Conversation

haya14busa
Copy link
Member

The function list is generated on Vitalize and #import() func is called in users environment, some function might not be defined as script local function and function('s:{funcname}') will throw errors.

Fix #537

return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! ${autoload_import}() abort', printf("return map(${funcdict}, \"vital#_${plugin_name}#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
delfunction! s:_SID

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[vint] reported by reviewdog 🐶
E477: No ! allowed (see ynkdir/vim-vimlparser)

Problem: delfunction s:_SID causes unexpected following error:
"E130: Unknown function: s:_SID"

It seems this error occurs because 'delfunction' is executed twice.

Root cause:

sourceing an autoload file will source same file unexpectedly in the
middle of first source process on defining autoload function.

1. Start sourcing autoload/hoge.vim
2. When executing line 2, Vim stops executing following scripts and Vim
starts sourcing same file from at the beginning of autoload/hoge.vim and
execute whole files. (echom at line 4 is
executed.
3. Restart sourcing autoload/hoge.vim from line 3.
4. echom at line 4 is executed at second time.

autoload/hoge.vim:
1 | " hoge.vim
2 | function! hoge#foo()
3 | endfunction
4 | echom 'hoge.vim is sourced'
@haya14busa
Copy link
Member Author

I updated the commit message to describe why we switched to use try-catch when calling #import() function.

Copy link
Member

@thinca thinca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants