Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vim Session Support #7

Open
no-more-secrets opened this issue Sep 1, 2024 · 5 comments
Open

Vim Session Support #7

no-more-secrets opened this issue Sep 1, 2024 · 5 comments

Comments

@no-more-secrets
Copy link

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?

@mikew
Copy link
Owner

mikew commented Sep 1, 2024

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.

@no-more-secrets
Copy link
Author

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.

@mikew
Copy link
Owner

mikew commented Sep 1, 2024

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.

  • Floating drawers: They're not saved at all
  • Split drawers: They are saved and restored, but nvim-drawer isn't aware of them.

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.

@no-more-secrets
Copy link
Author

ok thanks for the explanation, will try playing around with it.

@mikew
Copy link
Owner

mikew commented Sep 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants