vim-jetpack icon indicating copy to clipboard operation
vim-jetpack copied to clipboard

[HELP] How to lazy load "ale", "vim-lsp", and "deoplete" properly? Any examples?

Open lee-shun opened this issue 3 years ago • 5 comments

Hello! Thank you for your excellent work! I love it!

Now I am new to vim-jetpack, I want to lazy load the "deoplete" and "lsp" stuff using the event options.

I add the following lines in my vimrc:

packadd vim-jetpack

call jetpack#begin()
Jetpack 'tani/vim-jetpack', {'opt': 1}
.....
    Jetpack 'Shougo/deoplete.nvim', {'event':"BufReadPre"}
    Jetpack 'roxma/nvim-yarp',{'event':'User JetpackDeopleteNvimPre'}
    Jetpack 'roxma/vim-hug-neovim-rpc',{'event':'User JetpackDeopleteNvimPre'}
.....
call jetpack#end()

" config the deoplete
let g:deoplete#enable_at_startup = 1
call deoplete#custom#option({
            \ 'auto_complete_delay': 10,
            \ 'smart_case': v:true,
            \ })
" for latex
if(exists('g:loaded_vimtex'))
    call deoplete#custom#var('omni', 'input_patterns', {
                \ 'tex': g:vimtex#re#deoplete
                \})
endif

But when I start vim, the error says:

Unknown function deoplete#custom#option() .....

I guess that is because the deoplete is lazyloaded but the config of deopelte is called as usual. How could I let the config of deoplete right after the plug is loaded properly?

Thank you!

lee-shun avatar Sep 15 '22 01:09 lee-shun

Hi, thank you for using vim-jetpack.

I guess that is because the deoplete is lazyloaded but the config of deopelte is called as usual.

Exactly. deopelete is loaded lazily as you expected. You need to configure deopelete after loading deopelete but your configuration is set before loading deopelete because BufReadPre is fired after the loading configuration. Hence, I suggest to use hook JetpackDeopeleteNvimPost to set something.

"... something
call jetpack#end()

augroup SetupDeopeleteNvim
au!
au User JetpackDeopeleteNvimPost let g:deoplete#enable_at_startup = 1
au User JetpackDeopeleteNvimPost call deoplete#custom#option({
  \ 'auto_complete_delay': 10,
  \ 'smart_case': v:true,
  \ })
augroup END

"alternatively

function! SetupDeopeleteNvim() abort
  let g:deoplete#enable_at_startup = 1
  call deoplete#custom#option({
  \ 'auto_complete_delay': 10,
  \ 'smart_case': v:true,
  \ })
endfunction

augroup SetupDeopeleteNvim
autocmd!
autocmd User JetpackDeopeleteNvimPost call SetupDeopeleteNvim()
augroup END

tani avatar Sep 15 '22 02:09 tani

Thank you for the quick reply, i will try it tomorrow

lee-shun avatar Sep 15 '22 03:09 lee-shun

Just tested!

The same problem:

packadd vim-jetpack

call jetpack#begin()
Jetpack 'tani/vim-jetpack', {'opt': 1}
.....
    Jetpack 'Shougo/deoplete.nvim', {'event':"BufReadPre"}
    Jetpack 'roxma/nvim-yarp',{'event':'User JetpackDeopleteNvimPre'}
    Jetpack 'roxma/vim-hug-neovim-rpc',{'event':'User JetpackDeopleteNvimPre'}
.....
call jetpack#end()

" ===
" === deoplete
" ===
function! SetupDeopeleteNvim() abort
    call deoplete#custom#option({
                \ 'auto_complete_delay': 10,
                \ 'smart_case': v:true,
                \ })
    " for latex
    if(exists('g:loaded_vimtex'))
        call deoplete#custom#var('omni', 'input_patterns', {
                    \ 'tex': g:vimtex#re#deoplete
                    \})
    endif
endfunction

augroup SetupDeopeleteNvim
    autocmd!
    autocmd User JetpackDeopeleteNvimPost echom "hello Lazy loaded!"
    autocmd User JetpackDeopeleteNvimPost call SetupDeopeleteNvim()
augroup END

I prepared an echom to verify if the User JetpackDeopeleteNvimPost works well, but when I enter vim, there is no message, Also the deoplete is NOT loaded even after the buffer read.....

lee-shun avatar Sep 15 '22 13:09 lee-shun

Hi, I also tried the first option you gave but got the same results... Any help? Thank you.

lee-shun avatar Sep 16 '22 23:09 lee-shun

I am sorry for the inactive status. I will check it locally.

tani avatar Nov 26 '22 07:11 tani