axkirillov / hbac.nvim

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

Sourcing a session file may generate a "No buffers were wiped out" error #27

Closed cameronr closed 1 month ago

cameronr commented 1 month ago

Only happens if the session contains more than threshold buffers. The error looks like:

vim/_editor.lua:0: nvim_exec2()../Users/cam/.local/share/nvim/sessions/test.vim, line 210: Vim(bwipeout):
E517: No buffers were wiped out: bwipe 3  

The error may not be surfaced to the user (depending on how the session was sourced) but even if it's not shown to the user, the session will not fully restore as a result of the error.

The error happens because nvim may create an empty buffer while restoring the session. It keeps track of that buffer and expects to close it later in the session loading process:

...
" empty buffer may be created here
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
  let s:wipebuf = bufnr('%')
endif
...
<add a bunch of buffers here>
...
" empty buffer, if exists, is cleaned up here
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
  silent exe 'bwipe ' . s:wipebuf
endif

Loading a session sets g:SessionLoad so you could check for that before checking the buffers. I'll throw together a PR if that's helpful.

cameronr commented 1 month ago

If you want to repro, you can either install a session plugin (e.g. (auto-session)[https://github.com/rmagatti/auto-session]) or you can manually create a session:

  1. disable hbac (so you can get more than threshold buffers
  2. open more than threshold buffers
  3. save the session: :mksession ~/test.vim
  4. enable hbac
  5. clear all of your buffers: :%bw so you have just a blank buffer
  6. load the session :source ~/test.vim