axkirillov / hbac.nvim

Heuristic buffer auto-close
MIT License
197 stars 10 forks source link

feat: Add pin/unpin commands to persist important buffers #1

Closed al-ce closed 1 year ago

al-ce commented 1 year ago

Great idea for a plugin! I saw this comment in the reddit thread and slapped a quick pin/unpin command together to address having to 'poke' important buffers with a quick switch to Insert mode. Don't know if this is something you're interested in or if it's something you'd rather implement yourself from scratch, but I thought I'd share.

The threshold is respected. Say the threshold is 4 and you have four buffers open. You pin the oldest buffer. Open a new buffer, the second oldest buffer gets popped. And so on up until you pin four buffers. Then if you open a new buffer, your four pinned ones persist, and the new one also opens. You pin the fifth and open a new one, five persist, the new one also opens, and so on. Unpinned buffers seem to be removed with respect to their actual age along others that weren't pinned in the first place.

I didn't add completion because I don't know nvim apis well enough to implement it with relatively few lines of code.

axkirillov commented 1 year ago

Hi! Thank you for the PR! Since some people do seem to prefer a mapping instead of i, I find this functionality will be useful. Furthermore the addition of unpinning a buffer is interesting, although I don't know if I would personally use it. Lastly, since you are adding functionality, there need to be updates to the README as well.

axkirillov commented 1 year ago

@al-ce hi, I added a bunch of refactors in the last commit, check them out please, and tell me if you find them sensible. It is mainly about modularization, but there are some improvements to the code also. On the user side I though that I can expose just the toggle command without separate pin unpin actions, tell me if that is ok for you.

al-ce commented 1 year ago

The refactors are great, sorry I misunderstood what you were saying about exposing a single command instead of two. That makes sense. I had considered splitting up the modules but I didn't know how you preferred it. This looks good!

Thanks for working with me on this! I enjoyed the learning experience, you gave great guidance. Btw let me know if you need me to do any commit squashing on my end

axkirillov commented 1 year ago

Thank you as well, I enjoyed this too. Your commit messages are great, I am much more sloppy with them. I find squashing and rebasing a good practice, but I'm also fine with just merging all of it into main. If you are interested in such a thing I can make you a collaborator on this repo. Otherwise I'll just merge it and create a release myself.

al-ce commented 1 year ago

Let's go with best practices and keep the commit history minimal and easy to read. Should I force push the rebase to this branch or can you do it all when you merge?

axkirillov commented 1 year ago

@al-ce Feel free to force push here and tell me when you are ready for me to merge