Open no-more-secrets opened 1 month ago
Is there anything special that needs to be done with the nvim-drawer API to make it work (or work better) with sessions?
Probably! I haven't used it with sessions, so have no clue what happens at the moment.
Ideally what we'd be able to do is to open a drawer with nvim-tree, then save the session, then have it open up in the same state again upon session load.
Agreed, that would be ideal!
Unfortunately, at first glance, I'm not sure it's possible with just nvim-drawer alone, or how well it will all work.
You could override does_own_window
and does_own_drawer
, and that will make it half work. But the callbacks that should be called won't actually be called. Namely, on_did_create_buffer
(since it's actually the session file that's creating the buffer, not nvim-drawer)
An example of overriding does_own_window
/ does_own_drawer
for nvim-tree ...:
local nvim_tree_drawer = create_drawer(...)
local original_does_own_window = nvim_tree_drawer.does_own_window
function nvim_tree_drawer.does_own_window(winid)
local bufname = vim.api.nvim_buf_get_name(vim.api.nvim_win_get_buf(winid))
return original_does_own_window(winid) or (string.match(bufname, '^NvimTree_') ~= nil)
end
local original_does_own_buffer = nvim_tree_drawer.does_own_buffer
function nvim_tree_drawer.does_own_buffer(bufnr)
local bufname = vim.api.nvim_buf_get_name(bufnr)
return original_does_own_buffer(bufnr) or (string.match(bufname, '^NvimTree_') ~= nil)
end
But you'd have to suss around which callbacks to actually use, as I don't think on_did_open_buffer
will be called.
Similar could be done with terminals, replacing ^NvimTree_
with ^term://
, or checking buftype
.
ok thanks for the explanation, will try playing around with it.
I'm not sure it helps a lot with sessions, but I ended up making it easier for people to supply their own logic for does_own_window
and does_own_buffer
. When supplied they're used alongside the existing logic, not in place of it.
And supplying only does_own_buffer
should be enough, that's called in does_own_window
.
How well does this plugin interact with vim session files? E.g., if I create an nvim-tree in a drawer and then save the session, will it re-open to any extent when reloading the session? Is there anything special that needs to be done with the nvim-drawer API to make it work (or work better) with sessions?