elihunter173 / dirbuf.nvim

A file manager for Neovim which lets you edit your filesystem like you edit text
GNU Affero General Public License v3.0
423 stars 7 forks source link

Allow setting of `bufhidden` to a different option #8

Closed yorickpeterse closed 2 years ago

yorickpeterse commented 2 years ago

dirbuf currenty hardcodes bufhidden to hide:

https://github.com/elihunter173/dirbuf.nvim/blob/a715e08725a9d18896c9532df34547a0bbebf5ca/lua/dirbuf.lua#L68

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?

yorickpeterse commented 2 years ago

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.

elihunter173 commented 2 years ago

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.

yorickpeterse commented 2 years ago

@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.

elihunter173 commented 2 years ago

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

elihunter173 commented 2 years ago

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

elihunter173 commented 2 years ago

As of commit 7cdcd19324c93b90e7c2bf35e59680c174abac62, 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 https://github.com/elihunter173/dirbuf.nvim/issues/12#issuecomment-1023711292) So my fear of bufhidden=wipe causing bugs was wrong :)

yorickpeterse commented 2 years ago

@elihunter173 Thanks! :tada: :+1: