tani / vim-jetpack

The lightning-fast plugin manager, alternative to vim-plug
https://gist.asciidoctor.org/?github-tani/vim-jetpack/main//README.adoc&source-highlighter=highlightjs
MIT License
315 stars 31 forks source link

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

Open lee-shun opened 1 year ago

lee-shun commented 1 year ago

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!

tani commented 1 year ago

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
lee-shun commented 1 year ago

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

lee-shun commented 1 year ago

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 commented 1 year ago

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

tani commented 1 year ago

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