elihunter173/dirbuf.nvim

Allow setting of `bufhidden` to a different option

yorickpeterse opened this issue ยท 7 comments

dirbuf currenty hardcodes bufhidden to hide:

api.nvim_buf_set_option(buf, "bufhidden", "hide")

I personally prefer the approach dirvish takes where buffers are wiped when closing them. Unfortunately, due to the setting being hardcoded in dirbuf this is proving a challenge to set up. Would it be possible to allow customising this setting somehow?

A workaround would be something like this:

au BufWinEnter * lua if vim.bo.ft == 'dirbuf' then vim.bo.bufhidden = 'wipe' end

Using BufReadPost and the likes doesn't work, as it seems the mentioned setting is set after these events are triggered.

It's definitely technically possible. Is there a reason you prefer to have bufhidden set to wipe? I'm inclined to not add this as a configuration option because it seems to me like a source of potential bugs, although I don't see any right now, and the workaround doesn't seem too difficult.

Also, FWIW BufReadPost doesn't work because dirbuf.edit_dirbuf() is called on BufEnter which in turn runs set_dirbuf_opts. Since BufEnter is called after BufReadPost, any options you set on BufReadPost are overwritten. We call dirbuf.edit_dirbuf() on BufEnter to create and refresh the buffer automatically whenever you :edit or enter a dirbuf, which allows for easy reloading and prevents the dirbuf from drifting out of sync with the filesystem.

@elihunter173 Having bufhidden=wipe or similar means you don't end up with lots of dirbuf buffers piling up over time. Granted I don't use dirvish/dirbuf that often, it's nice not having it pile up. For similar reasons my dotfiles have a hook so that empty unnamed buffers get wiped when closing, so those don't pile either.

That makes sense. I'll play around with having bufhidden=wipe and see if that causes any issues. I don't plan to make it a configuration option because that seems pretty niche and I'd like to avoid configuration options for the reasons I mentioned above. But if it makes sense and doesn't cause any issues, I'll probably set bufhidden=wipe

One feature bufhidden=wipe might make easier is having CTRL-^ work like it does in dirvish where you visit the last non-dirbuf buffer you had open. This idea was suggested in a Reddit comment by u/llourenci

As of commit 7cdcd19, for all directory buffers bufhidden=wipe. So you should be able to remove your workaround @yorickpeterse

Funnily enough, it seemed having bufhidden=hide was actually causing bugs with re-opening previously closed directory buffers! (See #12 (comment)) So my fear of bufhidden=wipe causing bugs was wrong :)

@elihunter173 Thanks! ๐ŸŽ‰ ๐Ÿ‘