axkirillov / hbac.nvim

Heuristic buffer auto-close
MIT License
200 stars 11 forks source link

Persist pinned buffers #15

Closed serhez closed 4 months ago

serhez commented 1 year ago

Is it possible to persist the list of pinned buffers using a plugin like auto-session?

axkirillov commented 1 year ago

Hello. Honestly I have no idea. Have you tried just installing both and checking? Hbac stores pinned buffers in a lua table, so I assume that it's not part of "the neovim session" (although full disclosure I have no idea, just my intuition). If this is the case, then there is no way we can make this work, unless we rewrite the hbac state module to store everything in the "session". Perhaps a (neo)vim variable? (this is also based on my intuition about how auto-session works and not actual knowledge of the plugin internals, so don't take my word for granted).

I understand that this feature might be desirable. @al-ce what do you think? Do you use any session management solutions?

I personally sometimes have to reload neovim in order to fix weird lsp bugs that I'm having and then I have to repopulate the pinned buffer list. But untill now I found session management to be too complex and too much mental overhead to actually consider it in my setup.

serhez commented 1 year ago

@axkirillov I indeed have both installed and it does not work out-of-the-box. Thanks for the information as well :)

serhez commented 1 year ago

Also, perhaps you could look at how bufferline does it, they have a pinning buffers feature too and they are persisted. It works out-of-the-box with auto-session, possibly with other session plugins as well. My current setup is a command I have created to pin buffers (in a toggle fashion) both in hbac and in bufferline, which achieves this plugin's pinning behavior and also pins the buffer to the beginning of bufferline and shows some pin icon there. The only problem with this setup ATM is that pins are out-of-sync whenever I reload nvim because one plugin persists them and the other one doesn't.

axkirillov commented 1 year ago

So, it does, in fact, use a global variable https://github.com/akinsho/bufferline.nvim/blob/357cc8f8eeb64702e6fcf2995e3b9becee99a5d3/lua/bufferline/groups.lua#L148C14-L148C14

--- Store a list of pinned buffer as a string of ids e.g. "12,10,5"
--- in a vim.g global variable that can be persisted across vim sessions
axkirillov commented 1 year ago

So, I think, this would be easy to implement. The toggle_pin function needs to update a global variable on each toggle. Then the setup function can do a "restore" from said global variable.

Would you be willing to open a PR?