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 }
|
---@param opts? { last?: boolean, autoload?: boolean, session?: string }
|
||||||
function M.load(opts)
|
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
|
||||||
|
|
@ -73,10 +81,6 @@ function M.load(opts)
|
||||||
config.load_pre()
|
config.load_pre()
|
||||||
end
|
end
|
||||||
vim.cmd("silent! source " .. e(session))
|
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
|
elseif opts.autoload and type(config.on_autoload_no_session) == "function" then
|
||||||
config.on_autoload_no_session()
|
config.on_autoload_no_session()
|
||||||
end
|
end
|
||||||
|
|
@ -116,15 +120,21 @@ function M.save(opts)
|
||||||
return
|
return
|
||||||
end
|
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")
|
M.fire("SavePre")
|
||||||
if type(config.save_pre) == "function" then
|
if type(config.save_pre) == "function" then
|
||||||
config.save_pre()
|
config.save_pre()
|
||||||
end
|
end
|
||||||
vim.cmd("mks! " .. e(opts.session or vim.g.persisting_session or M.current()))
|
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
|
end
|
||||||
|
|
||||||
---Delete the current session
|
---Delete the current session
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,18 @@ end
|
||||||
---Load the selected session
|
---Load the selected session
|
||||||
---@param session table
|
---@param session table
|
||||||
function M.load_session(session)
|
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")
|
fire("TelescopeLoadPre")
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
persisted.load({ session = session.file_path })
|
persisted.load({ session = session.file_path })
|
||||||
end)
|
end)
|
||||||
fire("TelescopeLoadPost")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---Delete the selected session from disk
|
---Delete the selected session from disk
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue