don't close tab if there is unsaved buffer in it

This commit is contained in:
2022-02-23 11:58:33 +03:00
parent 1f34fc02f3
commit 86f9cb921c

View File

@@ -3,6 +3,19 @@ local M = {
} }
M.close_tab = function() M.close_tab = function()
local wins = vim.api.nvim_tabpage_list_wins(0)
for _, win in ipairs(wins) do
local bufnr = vim.api.nvim_win_get_buf(win)
local is_modified = vim.api.nvim_buf_get_option(bufnr, "modified")
if is_modified then
local bufname = vim.fn.bufname(bufnr)
print(bufname .. " is not saved")
return
end
end
table.insert(M.history, vim.fn.bufnr("%")) table.insert(M.history, vim.fn.bufnr("%"))
vim.cmd("tabclose") vim.cmd("tabclose")
end end