Skip to content

Commit

Permalink
Remove vim.schedule when loading session (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rowashere authored May 5, 2024
1 parent d8e1ba3 commit 892c55f
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions lua/session_manager/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,22 @@ function utils.load_session(filename, discard_current)
end
end

-- Scedule buffers cleanup to avoid callback issues and source the session.
vim.schedule(function()
-- Delete all buffers first except the current one to avoid entering buffers scheduled for deletion.
local current_buffer = vim.api.nvim_get_current_buf()
for _, buffer in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_valid(buffer) and buffer ~= current_buffer then
vim.api.nvim_buf_delete(buffer, { force = true })
end
-- Delete all buffers first except the current one to avoid entering buffers scheduled for deletion.
local current_buffer = vim.api.nvim_get_current_buf()
for _, buffer in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_valid(buffer) and buffer ~= current_buffer then
vim.api.nvim_buf_delete(buffer, { force = true })
end
vim.api.nvim_buf_delete(current_buffer, { force = true })

local swapfile = vim.o.swapfile
vim.o.swapfile = false
utils.is_session = true
vim.api.nvim_exec_autocmds('User', { pattern = 'SessionLoadPre' })
vim.api.nvim_command('silent source ' .. filename)
vim.api.nvim_exec_autocmds('User', { pattern = 'SessionLoadPost' })
vim.o.swapfile = swapfile
end)
end
vim.api.nvim_buf_delete(current_buffer, { force = true })

local swapfile = vim.o.swapfile
vim.o.swapfile = false
utils.is_session = true
vim.api.nvim_exec_autocmds('User', { pattern = 'SessionLoadPre' })
vim.api.nvim_command('silent source ' .. filename)
vim.api.nvim_exec_autocmds('User', { pattern = 'SessionLoadPost' })
vim.o.swapfile = swapfile
end

---@param filename string
Expand Down

0 comments on commit 892c55f

Please sign in to comment.