axkirillov / hbac.nvim

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

Feat. request: higher priority for unnamed (empty) buffers #6

Closed radmen closed 1 year ago

radmen commented 1 year ago

First of all - thank you for the plugin. It will bring sanity to my buffer-apocalypse I sometimes have 🙌

One of my biggest problems (in general) is the unnamed empty buffers. I tend to have a lot of them open because VIM likes to spam them on many occasions (i.e., when going to netrw).

Is it possible to prioritize removing the empty buffers when the threshold is met?

Thank you!

axkirillov commented 1 year ago

Hi! I think this is an interesting idea. We are already doing some sorting, so it should be straightforward to add a feature that closes the empty ones first. The only thing I don't know for sure yet is how to determine if a buffer is empty. Would something like this make sense?

function is_buffer_empty()
  return vim.api.nvim_buf_line_count(bufnr) == 1 and vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)[1] == ''
end

This checks whether the current buffer has only one line and that line is empty

On the other hand we actually ignore unnamed buffers when closing and that is probably because some things like prompts, terminals and popups are also buffers and closing them might result in unexpected behavior. However, maybe it would be fine to just stick to listed buffers and the unnamed part is just an extra precaution that is not necessary? I dunno, need to check.

What do you guys think @al-ce @ditsuke ?

ditsuke commented 1 year ago

On the other hand we actually ignore unnamed buffers when closing and that is probably because some things like prompts, terminals and popups are also buffers and closing them might result in unexpected behavior. However, maybe it would be fine to just stick to listed buffers and the unnamed part is just an extra precaution that is not necessary? I dunno, need to check.

What do you guys think @al-ce @ditsuke ?

Imo it should be safe to include unnamed, listed buffers. These special buffers used for UI are unlisted afaik

axkirillov commented 1 year ago

@radmen try apdating, this should be the default behaviour now

radmen commented 1 year ago

I will check. Thank you!