famiu / bufdelete.nvim

Delete Neovim buffers without losing window layout
GNU General Public License v3.0
515 stars 16 forks source link

Error when deleting buffer with `bufhidden=wipe` #6

Closed jdrouhard closed 3 years ago

jdrouhard commented 3 years ago

If there are at least two buffers open, and the last buffer has bufhidden=wipe set on it, then using Bdelete errors with the following:

E5108: Error executing lua ...te/pack/packer/opt/bufdelete.nvim/lua/bufdelete/init.lua:60: Vim(bdelete):E516: No buffers were deleted: bd! 6

I could only make this happen if there are at least two normal buffers open and the buffer with the wipe option set on it is the last one. Minimal repro is basically to open three buffers, then (when on the last/most recent), set bufhidden=wipe and Bdelete.

famiu commented 3 years ago

Is the issue fixed for you now?

jdrouhard commented 3 years ago

Yes, thank you so much!

jdrouhard commented 3 years ago

This issue seems to have resurfaced.

famiu commented 3 years ago

If you use the previous commit, does it work as intended?

jdrouhard commented 3 years ago

If you use the previous commit, does it work as intended?

Yes. It seems to be the most recent commit that regressed this behavior.

famiu commented 3 years ago

@spindensity any thoughts?

jdrouhard commented 3 years ago

So it looks like if the buffer has bufhidden=delete then nvim_buf_is_valid(bufnr) returns true even after the buffer is deleted. The check on https://github.com/famiu/bufdelete.nvim/blob/master/lua/bufdelete/init.lua#L61 might need to also check that the buffer is listed as well, like:

    if api.nvim_buf_is_valid(bufnr) and bo[bufnr].buflisted then
        cmd(string.format('%s %d', kill_command, bufnr))
    end

I tested this and it does fix the issue.

famiu commented 3 years ago

I pushed a change that incorporates that. If your issue is fixed now, please close this

jdrouhard commented 3 years ago

Yep, that did the trick. Thanks again!