axkirillov / hbac.nvim

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

Close edited buffers if threshold is reached #21

Closed ftelnov closed 11 months ago

ftelnov commented 11 months ago

I've set a pretty small threshold(7) so I can always navigate with tabs across buffers. However, when I edit many files in one go, I simply can't open buffers till I close ones. My proposition is to add an option to close edited buffers if they are saved and there is no place for opening a new buffer. I can try implementing the feature, but first say pls, if there is any alternative already presented already..

axkirillov commented 11 months ago

Hi! Thank you for bringing this up. I do see value in this idea, however, I wouldn't use it myself, since I use autosave. Implementing this should be easy. Create an autocommand for the BufWritePost event and call toggle_pin action. I think you will have to also check the state so smth like

state = require("hbac.state")
actions = require("hbac.actions")

if state.is_pinned(buf) then
  actions.toggle_pin(buf)
end
ftelnov commented 11 months ago

Thanks for the proposition! I think you are right, it is possible to do on the client side, and I'm satisfied with the solution!

Resulting autocmd for anyone who is interested, really easy:

autocmd("BufWritePost", {
  callback = function(ev)
    local state = require "hbac.state"
    local actions = require "hbac.command.actions"
    if state.is_pinned(ev.buf) then
      actions.toggle_pin(ev.buf)
    end
  end,
})