Skip to content

Commit

Permalink
Rework buffer closing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Sep 17, 2023
1 parent 2f53974 commit 7cd1f55
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions plugin/buffers.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local neo_tree_command = require('neo-tree.command')
local stickybuf = require('stickybuf')
local toggleterm = require('toggleterm')

Expand All @@ -14,37 +13,21 @@ local function close_buffer(command)
return
end

if vim.api.nvim_buf_get_option(buffer, 'buftype') == 'nowrite' then
vim.api.nvim_buf_delete(buffer, { force = true })
return
end

local filetype = vim.api.nvim_buf_get_option(buffer, 'filetype')
if filetype == 'neo-tree' then
neo_tree_command.execute({ action = 'close' })
return
end

if filetype == 'toggleterm' then
-- Never kill toggleterm
if vim.api.nvim_buf_get_option(buffer, 'filetype') == 'toggleterm' then
toggleterm.toggle(1)
return
end

if filetype == 'NeogitCommitMessage' then
vim.api.nvim_buf_delete(buffer, { force = true })
return
end

if stickybuf.should_auto_pin(buffer) then
if vim.api.nvim_buf_get_option(buffer, 'buftype'):len() ~= 0 or stickybuf.should_auto_pin(buffer) then
local winid = vim.fn.bufwinid(buffer)
if stickybuf.is_pinned(winid) then
stickybuf.unpin(winid)
end
vim.api.nvim_buf_delete(buffer, { force = bang })
return
end

if #vim.fn.getcmdwintype() ~= 0 then
vim.cmd.quit()
return
end

if #vim.fn.getbufinfo({ buflisted = 1 }) == 1 then
-- Only one window left, create a new empty window
vim.cmd.enew()
Expand Down

0 comments on commit 7cd1f55

Please sign in to comment.