feat: add additional events

main
olimorris 2023-02-23 20:44:47 +00:00
parent 383b5ba6b5
commit 4866194140
2 changed files with 9 additions and 0 deletions

View File

@ -268,6 +268,9 @@ The plugin fires events at various points during its lifecycle which users can h
- `PersistedTelescopeLoadPost` - For _after_ a session is loaded via Telescope
- `PersistedSavePre` - For _before_ a session is saved
- `PersistedSavePost` - For _after_ a session is saved
- `PersistedDeletePre` - For _before_ a session is deleted
- `PersistedDeletePost` - For _after_ a session is deleted
- `PersistedStateChange` - For when a session is _started_ or _stopped_
For example, to ensure that the excellent [minimap](https://github.com/wfxr/minimap.vim) plugin is not saved into a session, an autocommand can be created to hook into the `PersistedSavePre` event:

View File

@ -118,6 +118,7 @@ end
---@return nil
function M.start()
vim.g.persisting = true
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedStateChange" })
end
---Stop recording a session
@ -125,6 +126,7 @@ end
function M.stop()
vim.g.persisting = false
vim.g.persisting_session = nil
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedStateChange" })
end
---Save the session
@ -172,10 +174,14 @@ end
function M.delete()
local session = get_current()
if session and vim.loop.fs_stat(session) ~= 0 then
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedDeletePre" })
vim.schedule(function()
M.stop()
vim.fn.system("rm " .. e(session))
end)
vim.api.nvim_exec_autocmds("User", { pattern = "PersistedDeletePost" })
end
end