Cannot register autocmd from function call
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.
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.
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?
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).