famiu/bufdelete.nvim

Error when deleting buffer with `bufhidden=wipe`

jdrouhard opened this issue · 9 comments

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

Is the issue fixed for you now?

Yes, thank you so much!

This issue seems to have resurfaced.

famiu commented

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

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

@spindensity any thoughts?

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

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

Yep, that did the trick. Thanks again!