From 7cd1f5590dd6859df0594670a3f887adb8b94d27 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Mon, 18 Sep 2023 02:03:29 +0300 Subject: [PATCH] Rework buffer closing logic --- plugin/buffers.lua | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/plugin/buffers.lua b/plugin/buffers.lua index a35530a..e3a13fe 100644 --- a/plugin/buffers.lua +++ b/plugin/buffers.lua @@ -1,4 +1,3 @@ -local neo_tree_command = require('neo-tree.command') local stickybuf = require('stickybuf') local toggleterm = require('toggleterm') @@ -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()