Use Session* events to fire post load/save events
parent
d6485bc69f
commit
07fd86682f
|
|
@ -50,9 +50,17 @@ end
|
|||
---@param opts? { last?: boolean, autoload?: boolean, session?: string }
|
||||
function M.load(opts)
|
||||
opts = opts or {}
|
||||
|
||||
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
|
||||
session = M.last()
|
||||
elseif opts.session then
|
||||
|
|
@ -73,10 +81,6 @@ function M.load(opts)
|
|||
config.load_pre()
|
||||
end
|
||||
vim.cmd("silent! source " .. e(session))
|
||||
if type(config.load_post) == "function" then
|
||||
config.load_post()
|
||||
end
|
||||
M.fire("LoadPost")
|
||||
elseif opts.autoload and type(config.on_autoload_no_session) == "function" then
|
||||
config.on_autoload_no_session()
|
||||
end
|
||||
|
|
@ -116,15 +120,21 @@ function M.save(opts)
|
|||
return
|
||||
end
|
||||
|
||||
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,
|
||||
})
|
||||
|
||||
M.fire("SavePre")
|
||||
if type(config.save_pre) == "function" then
|
||||
config.save_pre()
|
||||
end
|
||||
vim.cmd("mks! " .. e(opts.session or vim.g.persisting_session or M.current()))
|
||||
if type(config.save_post) == "function" then
|
||||
config.save_post()
|
||||
end
|
||||
M.fire("SavePost")
|
||||
end
|
||||
|
||||
---Delete the current session
|
||||
|
|
|
|||
|
|
@ -21,11 +21,18 @@ end
|
|||
---Load the selected session
|
||||
---@param session table
|
||||
function M.load_session(session)
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
pattern = "PersistedLoadPost",
|
||||
callback = function()
|
||||
fire("TelescopeLoadPost")
|
||||
return true -- returning deletes autocmd after fired
|
||||
end,
|
||||
})
|
||||
|
||||
fire("TelescopeLoadPre")
|
||||
vim.schedule(function()
|
||||
persisted.load({ session = session.file_path })
|
||||
end)
|
||||
fire("TelescopeLoadPost")
|
||||
end
|
||||
|
||||
---Delete the selected session from disk
|
||||
|
|
|
|||
Loading…
Reference in New Issue