Shougo / dein.vim

:zap: Dark powered Vim/Neovim plugin manager
MIT License
3.42k stars 197 forks source link

open / close function for hook_source #322

Closed kayfay closed 5 years ago

kayfay commented 5 years ago

Warning: I will close the bug issue without the minimal init.vim and the reproduce ways.

Problems summary

Trying to call the below two at startup and at exit.

      autocmd FileType r if string(g:SendCmdToR) == "function('SendCmdToR_fake')" | call StartR("R") | endif
      autocmd VimLeave * if exists("g:SendCmdToR") && string(g:SendCmdToR) != "function('SendCmdToR fake')" | call RQuit("nosave") | endif

---- from docs method as a function seemed to be the only way to implement ----

         hook_source  (String) or (Function)
  It is executed before plugins are sourced.
  Note: The "sourced" means after |dein#end()| or when
  |VimEnter| or autoloaded.

  call dein#add('artur-shaik/vim-javacomplete2')
  call dein#config('artur-shaik/vim-javacomplete2', {
  \ 'hook_source': 'autocmd FileType java
  \                 setlocal omnifunc=javacomplete#Complete'
  \ })
  function! Func() abort
    autocmd FileType qf nnoremap <buffer> r :<C-u>Qfreplace<CR>
  endfunction
  call dein#source('thinca/vim-qfreplace',
  \ 'hook_source': function('Func'))

  Note: non lazy plugins' |dein-options-hook_source| cannot be
  called.  You must call it by |dein#call_hook()| if needed.

  call dein#begin()
  ...
  call dein#end()
        call dein#call_hook('source')

And AutoOpenREPL or AutoCloseREPL functions do not activate.

Expected

I'm thinking call dein#call_hook('source') will activate call dein#source('....') entries and cause the functions to activate and startup and shutdown of nvim/vim

Environment Information (Required!)

Provide a minimal .vimrc with less than 50 lines (Required!)

"dein Scripts-----------------------------
if &compatible
  set nocompatible               " Be iMproved
endif

" Required:
set runtimepath+=/home/atools/.cache/dein/repos/github.com/Shougo/dein.vim

" Required:
if dein#load_state('/home/atools/.cache/dein')

  call dein#begin('/home/atools/.cache/dein')

  " Let dein manage dein
  " Required:
  call dein#add('/home/atools/.cache/dein/repos/github.com/Shougo/dein.vim')

  " Add or remove your plugins here like this:

   " Calls to functions for open/close R REPL on startup/exit
   function! AutoOpenREPL() abort
      autocmd FileType r if string(g:SendCmdToR) == "function('SendCmdToR_fake')" | call StartR("R") | endif
   endfunction

   function! AutoCloseREPL() abort
      autocmd VimLeave * if exists("g:SendCmdToR") && string(g:SendCmdToR) != "function('SendCmdToR fake')" | call RQuit("nosave") | endif
   endfunction

   call dein#add('jalvesaq/Nvim-R')

   call dein#source('jalvesaq/Nvim-R', {
   \ 'hook_source': function('AutoOpenREPL'),
   \ })

   call dein#source('jalvesaq/Nvim-R', {
   \ 'hook_source': function('AutoCloseREPL')
   \ })

  " Required:
  call dein#end()
  call dein#call_hook('source')
  call dein#save_state()
endif

" Required:
filetype plugin indent on
syntax enable

The reproduce ways from Vim starting (Required!)

  1. nvim/vim is linked to .vimrc and referenced on startup
  2. notice no activation/deactivation for terminal process
  3. shut down nvim/vim

Screen shot (if possible)

After startup should look like this, it's vim with a REPL...

screenshot from 2019-01-27 18-50-45

Upload the log messages by :redir and :message (if errored)

n/a

Shougo commented 5 years ago

You should know what is your code.

call dein#call_hook('source') defines autocmd FileType r, but it does not call FileType r autocmd.

You should use lazy load. It calles FileType r autocmd automatically.

   function! AutoOpenREPL() abort
      autocmd FileType r if string(g:SendCmdToR) == "function('SendCmdToR_fake')" | call StartR("R") | endif
      autocmd VimLeave * if exists("g:SendCmdToR") && string(g:SendCmdToR) != "function('SendCmdToR fake')" | call RQuit("nosave") | endif
   endfunction
   call dein#source('jalvesaq/Nvim-R', {
   \ 'hook_source': function('AutoOpenREPL'),
   \ 'on_ft': 'r',
   \ })
kayfay commented 5 years ago

Im not following...

You should know what is your code.

Should I re-open a ticket and be more clear?

And can you be more clear about what you're talking about. What was the point you were making about using lazy load, did you just copy / paste a block of my code or is that refactored?

Shougo commented 5 years ago
  function! AutoOpenREPL() abort
      autocmd FileType r if string(g:SendCmdToR) == "function('SendCmdToR_fake')" | call StartR("R") | endif
      autocmd VimLeave * if exists("g:SendCmdToR") && string(g:SendCmdToR) != "function('SendCmdToR fake')" | call RQuit("nosave") | endif
   endfunction
   call dein#add('jalvesaq/Nvim-R', {
   \ 'hook_source': function('AutoOpenREPL'),
   \ 'on_ft': 'r',
   \ })

I have mistake the code. You must use dein#add() instead. It works for me.

But ... you should read the documentation.

Shougo commented 5 years ago
"dein Scripts-----------------------------
if &compatible
  set nocompatible               " Be iMproved
endif

" Required:
set runtimepath+=/home/atools/.cache/dein/repos/github.com/Shougo/dein.vim

" Required:
if dein#load_state('/home/atools/.cache/dein')

  call dein#begin('/home/atools/.cache/dein')

  " Let dein manage dein
  " Required:
  call dein#add('/home/atools/.cache/dein/repos/github.com/Shougo/dein.vim')

  " Add or remove your plugins here like this:

  function! AutoOpenREPL() abort
      autocmd FileType r if string(g:SendCmdToR) == "function('SendCmdToR_fake')" | call StartR("R") | endif
      autocmd VimLeave * if exists("g:SendCmdToR") && string(g:SendCmdToR) != "function('SendCmdToR fake')" | call RQuit("nosave") | endif
   endfunction

   call dein#add('jalvesaq/Nvim-R', {
   \ 'hook_source': function('AutoOpenREPL'),
   \ 'on_ft': 'r',
   \ })

  " Required:
  call dein#end()
  call dein#call_hook('source')
  call dein#save_state()
endif

" Required:
filetype plugin indent on
syntax enable

And can you be more clear about what you're talking about. What was the point you were making about using lazy load, did you just copy / paste a block of my code or is that refactored?

I am very busy to develop plugins.

kayfay commented 5 years ago

I understand and this is really great, I appreciate it alot!