Move post load/save event creation back out of setup func

main
Bryan 2024-11-07 11:40:15 -06:00
parent 0f07bade0c
commit 6c83e6ecb3
1 changed files with 20 additions and 21 deletions

View File

@ -52,6 +52,15 @@ function M.load(opts)
opts = opts or {} opts = opts or {}
local session local session
vim.api.nvim_create_autocmd("SessionLoadPost", {
callback = function()
if type(config.load_post) == "function" then
config.load_post()
end
M.fire("LoadPost")
return true -- returning deletes autocmd after fired
end,
})
if opts.last then if opts.last then
session = M.last() session = M.last()
elseif opts.session then elseif opts.session then
@ -111,7 +120,17 @@ function M.save(opts)
return return
end end
M.fire("SavePre") vim.api.nvim_create_autocmd("SessionWritePost", {
callback = function()
if type(config.save_post) == "function" then
config.save_post()
end
M.fire("PersistedSavePost")
return true -- returning deletes autocmd after fired
end,
})
M.fire("PersistedSavePre")
if type(config.save_pre) == "function" then if type(config.save_pre) == "function" then
config.save_pre() config.save_pre()
end end
@ -228,26 +247,6 @@ function M.setup(opts)
vim.fn.mkdir(config.save_dir, "p") vim.fn.mkdir(config.save_dir, "p")
vim.api.nvim_create_autocmd("SessionSavePost", {
callback = function()
if type(config.save_post) == "function" then
config.save_post()
end
M.fire("SavePost")
return true -- returning deletes autocmd after fired
end,
})
vim.api.nvim_create_autocmd("SessionLoadPost", {
callback = function()
if type(config.load_post) == "function" then
config.load_post()
end
M.fire("LoadPost")
return true -- returning deletes autocmd after fired
end,
})
if config.autostart and M.allowed_dir() and vim.g.persisting == nil and not start_args then if config.autostart and M.allowed_dir() and vim.g.persisting == nil and not start_args then
M.start() M.start()
end end