Skip to content

Commit

Permalink
Merge pull request #306 from cameronr/close_unsupported
Browse files Browse the repository at this point in the history
Made the changes requested in #230
  • Loading branch information
rmagatti authored Jun 21, 2024
2 parents af2219b + ad8335b commit 92744f5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ require('lualine').setup{
```lua
require("auto-session").setup {
bypass_session_save_file_types = nil, -- table: Bypass auto save when only buffer open is one of these file types
close_unsupported_windows = true, -- boolean: Close windows that aren't backed by normal file
cwd_change_handling = { -- table: Config for handling the DirChangePre and DirChanged autocmds, can be set to nil to disable altogether
restore_upcoming_session = true, -- boolean: restore session for upcoming cwd on cwd change
pre_cwd_changed_hook = nil, -- function: This is called after auto_session code runs for the `DirChangedPre` autocmd
Expand Down
6 changes: 6 additions & 0 deletions lua/auto-session/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ local defaultConf = {
---@class luaOnlyConf
---@field cwd_change_handling CwdChangeHandling
---@field bypass_session_save_file_types? table List of file types to bypass auto save when the only buffer open is one of the file types listed
---@field close_unsupported_windows? boolean Whether to close windows that aren't backed by a real file
---@field silent_restore boolean Whether to restore sessions silently or not
---@field log_level? string|integer "debug", "info", "warn", "error" or vim.log.levels.DEBUG, vim.log.levels.INFO, vim.log.levels.WARN, vim.log.levels.ERROR
local luaOnlyConf = {
bypass_session_save_file_types = nil, -- Bypass auto save when only buffer open is one of these file types
close_unsupported_windows = true, -- Close windows that aren't backed by normal file
---CWD Change Handling Config
---@class CwdChangeHandling
---@field restore_upcoming_session boolean {true} restore session for upcoming cwd on cwd change
Expand Down Expand Up @@ -391,6 +393,10 @@ function AutoSession.AutoSaveSession(sessions_dir)
end
end

if AutoSession.conf.close_unsupported_windows then
Lib.close_unsupported_windows()
end

AutoSession.SaveSession(sessions_dir, true)
end
end
Expand Down
15 changes: 15 additions & 0 deletions lua/auto-session/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,19 @@ function Lib.has_open_buffers()
return result
end

function Lib.close_unsupported_windows()
local tabpages = vim.api.nvim_list_tabpages()
for _, tabpage in ipairs(tabpages) do
local windows = vim.api.nvim_tabpage_list_wins(tabpage)
for _, window in ipairs(windows) do
local buffer = vim.api.nvim_win_get_buf(window)
local file_name = vim.api.nvim_buf_get_name(buffer)
if not Lib.is_readable(file_name) then
vim.api.nvim_win_close(window, true)
break;
end
end
end
end

return Lib

0 comments on commit 92744f5

Please sign in to comment.