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

Cannot register autocmd from function call #204

Open
timeyyy opened this issue May 9, 2016 · 3 comments
Open

Cannot register autocmd from function call #204

timeyyy opened this issue May 9, 2016 · 3 comments

Comments

@timeyyy
Copy link
Contributor

timeyyy commented May 9, 2016

The following autocmd works if i uncomment self.ensemble from within the init function.

@neovim.plugin
class Main(util.VimMix, object):
    def __init__(self, vim):
        self.vim = vim
        # self.ensemble(('CursorMoved', 'woosh.wav'))

    @neovim.function('Ensemble', sync=True)
    def ensemble(self, args):
        ...

        @neovim.autocmd(when)
        def func(nvim):
            ...
        setattr(self, '_'+when, func)

Now if i try doing this from my vimrc..

" Load the python3 plugin so we can use the functions...
runtime! plugin/rplugin.vim
call Ensemble('CursorMoved', 'woosh.wav')

The ensemble function runs but the autocmd doesn't work.

@bfredl
Copy link
Member

bfredl commented May 9, 2016

It can't work, as ftm the host only checks for handlers at startup.
For now you need to define it as a function directly in the class and use vim.command("autocmd ... TheFunction()").

Though not to far in the future we will refactor the rplugin infrastructure to don't need UpdateRemotePlugins anymore, allow new plugins to be re/loaded at runtime and as part of that we should allow plugins to register new handlers at runtime.

@timeyyy
Copy link
Contributor Author

timeyyy commented May 9, 2016

Ok I will give that a go.

I.e doing a vim.command from within the init function stops the plugin from being found when I do updateremoteplugins...

is this the correct place to report this?

@bfredl
Copy link
Member

bfredl commented May 9, 2016

it might be a bit inconvenient, but a plugin shouldn't do stuff that has an effect on nvim in __init__ as the plugin has no control when init is run. The proper way is to have a function/command that will be called whenever is the right time (say a FileType, a user command or in a plugin/myplugin.vim if the plugin really needs to start at nvim startup, but a VimEnter autocommand might work for this too).

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

No branches or pull requests

2 participants