kevinhwang91 / rnvimr

Make Ranger running in a floating window to communicate with Neovim via RPC
BSD 3-Clause "New" or "Revised" License
800 stars 17 forks source link

Allow loading plugin in background on startup #113

Closed amerlyq closed 2 years ago

amerlyq commented 2 years ago

Problem

First launch of rnvimr is frustratingly long.

Workflow

My usual workflow -- is to navigate ranger and run/close nvim several times a minute. Usually, after opening first file, I open (depending on its content) one more file relative to first one. Then one more file relative to second one (usually in same parent or sibling directory).

It means I almost certainly open rnvimr after several seconds of opening first file I should wait ~1..2 seconds until it ready. And I do that several times a minute.

Idea

Preload rnvimr in background after each startup

vim.defer_fn(function() vim.fn['rnvimr#init']() end, 1000)

NOTE: It's better run this function myself, so there is no need to "add one more option to config".

Issue

There is no way to run rnvimr in background -- it always opens window, and closing it afterwards results in flickering. Maybe, this single in create_ranger can be done conditionally, based on argument passed e.g. "call rnvimr#init(0)"

" function! s:create_ranger(cmd, env) abort
    call rnvimr#context#winid(
                \ nvim_open_win(rnvimr#context#bufnr(), v:true, init_layout))
kevinhwang91 commented 2 years ago

It's a daemon feature. I will take a look tomorrow.

amerlyq commented 2 years ago

Currently I achieved what I wanted by doing:

diff --git i/autoload/rnvimr.vim w/autoload/rnvimr.vim
index 7af68c7..7c6a894 100644
--- i/autoload/rnvimr.vim
+++ w/autoload/rnvimr.vim
@@ -83,7 +83,8 @@ function! s:create_ranger(cmd, env) abort
     call termopen(cmd, {'on_exit': function('s:on_exit')})
     setfiletype rnvimr
     call s:setup_winhl()
-    startinsert
+    " startinsert
+    call nvim_win_close(rnvimr#context#winid(), 0)
 endfunction

 function! s:defer_check_dir(path, bufnr) abort

But now it properly works only as daemon preloaded by timer, and breaks default no-daemon mode. So it definitely needs some thinking, however I'm content with current way to :)

kevinhwang91 commented 2 years ago
vim.defer_fn(function ()
    vim.cmd('RnvimrStartBackground')
end, 1000)
amerlyq commented 2 years ago

Nice! It works, thanks!

MagicDuck commented 1 year ago

hi, I just found the gem that is RnvimrStartBackground and started using it, but noticed that on the first call to RnvimrToggle, it will show the directory from which nvim was started instead of the current file directory. My workaround was:

vim.defer_fn(function ()
    vim.cmd([[
      RnvimrStartBackground
      call rnvimr#context#bufnr(-1)
      call rnvimr#rpc#reset()
    ]])
end, 1000)

Last 2 lines are copied from the on_exit code from here: https://github.com/kevinhwang91/rnvimr/blob/e9af3795f4233b3273e4b7e9d6bb7d7c8e191412/autoload/rnvimr.vim#L60

Wondering it something needs to be adjusted with RnvimrStartBackground call?

kevinhwang91 commented 1 year ago

@MagicDuck Fixed.

MagicDuck commented 1 year ago

thank you for the super-quick fix! It's happy now 😄