Skip to content

Commit

Permalink
fix: session restore order (closes #31)
Browse files Browse the repository at this point in the history
  • Loading branch information
romgrk committed Nov 7, 2020
1 parent 6012867 commit 7d3858e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
15 changes: 12 additions & 3 deletions autoload/bufferline/bbye.vim
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,27 @@ function! s:str2bufnr(buffer)
endif
endfunction

let s:empty_buffer = v:null

function! s:new(bang)
exe "enew" . a:bang

setl noswapfile
let s:empty_buffer = bufnr()

let b:empty_buffer = v:true

" Regular buftype warns people if they have unsaved text there. Wouldn't
" want to lose someone's data:
setl buftype=
setl noswapfile

" If empty and out of sight, delete it right away:
setl bufhidden=wipe
let buffer_number = bufnr()
exe 'au BufWipeout <buffer> call bufferline#close_direct(' buffer_number ')'

augroup bbye_empty_buffer
au!
au BufWipeout <buffer> call bufferline#close_direct(s:empty_buffer)
augroup END
endfunction

" Using the built-in :echoerr prints a stacktrace, which isn't that nice.
Expand Down
7 changes: 6 additions & 1 deletion lua/bufferline/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ local function render()

-- Store current buffer to open new ones next to this one
if nvim.buf_get_option(current, 'buflisted') then
state.last_current_buffer = current
local ok, is_empty = pcall(api.nvim_buf_get_var, current, 'empty_buffer')
if ok and is_empty then
state.last_current_buffer = nil
else
state.last_current_buffer = current
end
end

local opts = vim.g.bufferline
Expand Down
7 changes: 5 additions & 2 deletions lua/bufferline/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,14 @@ local function open_buffers(new_buffers)
-- Insert the buffers where they go
for i, new_buffer in ipairs(new_buffers) do
if utils.index(m.buffers, new_buffer) == nil then
local actual_index = new_index
-- For special buffers, we add them at the end
if vim.fn.getbufvar(new_buffer, '&buftype') ~= '' then
new_index = len(m.buffers) + 1
actual_index = len(m.buffers) + 1
else
new_index = new_index + 1
end
table.insert(m.buffers, new_index, new_buffer)
table.insert(m.buffers, actual_index, new_buffer)
end
end

Expand Down

0 comments on commit 7d3858e

Please sign in to comment.