Skip to content

Commit

Permalink
fix: #342 don't close terminal windows
Browse files Browse the repository at this point in the history
Also make window closing more resilient if a window closes unexpectedly
(I've seen it happen with Neogit where closing the Neogit window will
close other windows, e.g. Oil)
  • Loading branch information
cameronr committed Aug 5, 2024
1 parent b75f8c6 commit ba30ea9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lua/auto-session/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,19 @@ function Lib.close_unsupported_windows()
if vim.fn.tabpagenr "$" == 1 and vim.fn.winnr "$" == 1 then
return
end
local buffer = vim.api.nvim_win_get_buf(window)
local file_name = vim.api.nvim_buf_get_name(buffer)
if vim.fn.filereadable(file_name) == 0 then
vim.api.nvim_win_close(window, true)
-- Sometimes closing one window can affect another so wrap in pcall
local success, buffer = pcall(vim.api.nvim_win_get_buf, window)
if success then
local file_name = vim.api.nvim_buf_get_name(buffer)
local buf_type = vim.api.nvim_get_option_value("buftype", { buf = buffer })
-- Lib.logger.debug("file_name: " .. file_name .. " buf_type: " .. buf_type)
if vim.fn.filereadable(file_name) == 0 and buf_type ~= "terminal" then
Lib.logger.debug("closing window: " .. window .. " file_name: " .. file_name .. " buf_type: " .. buf_type)

vim.api.nvim_win_close(window, true)
end
else
Lib.logger.debug("Windows: " .. vim.inspect(windows) .. " window is no longer valid: " .. window)
end
end
end
Expand Down

0 comments on commit ba30ea9

Please sign in to comment.