diff --git a/README.md b/README.md index c8e56c1..15e5b2a 100644 --- a/README.md +++ b/README.md @@ -208,13 +208,25 @@ require("persisted").setup({ pcall(vim.cmd, "bw minimap") end, after_save = function() - -- Do something + print("Session was saved!") end, }) ``` > **Note:** The author uses a *before* callback to ensure that [minimap.vim](https://github.com/wfxr/minimap.vim) is not written into the session. Its presence prevents the exact buffer and cursor position from being restored when loading a session +The plugin allows for an *after* callback to be executed in relation to a session being sourced: + +```lua +require("persisted").setup({ + after_source = function() + -- Reload the LSP servers + vim.lsp.stop_client(vim.lsp.get_active_clients()) + vim.cmd("edit") + end +}) +``` + ### Telescope extension > **This feature is still in beta!!** diff --git a/lua/persisted/config.lua b/lua/persisted/config.lua index 9c2ee2e..6bb0f33 100644 --- a/lua/persisted/config.lua +++ b/lua/persisted/config.lua @@ -11,6 +11,7 @@ local defaults = { ignored_dirs = nil, -- table of dirs that are ignored for auto-saving and auto-loading before_save = function() end, -- function to run before the session is saved to disk after_save = function() end, -- function to run after the session is saved to disk + after_source = function() end, -- function to run after the session is sourced telescope = { -- options for the telescope extension before_source = function(session) end, -- function to run before the session is sourced via telescope after_source = function(session) end, -- function to run after the session is sourced via telescope diff --git a/lua/persisted/init.lua b/lua/persisted/init.lua index 5b40c61..e729535 100644 --- a/lua/persisted/init.lua +++ b/lua/persisted/init.lua @@ -110,7 +110,7 @@ function M.load(opt) if not ok then return utils.echoerr("Error loading the session! ", result) end - vim.cmd("silent! e %") + config.options.after_source() end if config.options.autosave and (allow_dir() and not ignore_dir()) then