try to fix nvim hanging when it exits

main
Bryan 2024-11-11 00:19:28 -06:00
parent 1934279d0b
commit cf4c944b21
1 changed files with 22 additions and 22 deletions

View File

@ -113,29 +113,29 @@ end
---Save the session
---@param opts? { force?: boolean, session?: string }
function M.save(opts)
opts = opts or {}
-- Do not save the session if should_save evals to false...unless it's forced
if type(config.should_save) == "function" and not config.should_save() and not opts.force then
M.fire("SavePost")
return
end
vim.api.nvim_create_autocmd("SessionWritePost", {
callback = function()
if type(config.save_post) == "function" then
config.save_post()
end
M.fire("SavePost")
return true -- returning true deletes autocmd after fired
end,
})
M.fire("SavePre")
if type(config.save_pre) == "function" then
config.save_pre()
end
vim.schedule(function()
opts = opts or {}
-- Do not save the session if should_save evals to false...unless it's forced
if type(config.should_save) == "function" and not config.should_save() and not opts.force then
M.fire("SavePost")
return
end
vim.api.nvim_create_autocmd("SessionWritePost", {
callback = function()
if type(config.save_post) == "function" then
config.save_post()
end
M.fire("SavePost")
return true -- returning true deletes autocmd after fired
end,
})
M.fire("SavePre")
if type(config.save_pre) == "function" then
config.save_pre()
end
vim.api.nvim_command("wa")
vim.api.nvim_command("mksession! " .. e(opts.session or vim.g.persisting_session or M.current()))
end)