diff --git a/README.md b/README.md index bf1ebd8..f889aec 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/lua/persisted/init.lua b/lua/persisted/init.lua index 81d213e..1fe2804 100644 --- a/lua/persisted/init.lua +++ b/lua/persisted/init.lua @@ -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