diff --git a/README.md b/README.md index 73b4719..d74e4d5 100644 --- a/README.md +++ b/README.md @@ -220,10 +220,13 @@ require("persisted").setup({ > **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: +The plugin allows for *before* and *after* callbacks to be executed in relation to a session being sourced: ```lua require("persisted").setup({ + before_source = function() + print("Sourcing...") + end, after_source = function() -- Reload the LSP servers vim.lsp.stop_client(vim.lsp.get_active_clients()) diff --git a/lua/persisted/config.lua b/lua/persisted/config.lua index f0e736a..324a01d 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 = nil, -- function to run before the session is saved to disk after_save = nil, -- function to run after the session is saved to disk + before_source = nil, -- function to run before the session is sourced after_source = nil, -- function to run after the session is sourced telescope = { -- options for the telescope extension before_source = nil, -- function to run before the session is sourced via telescope diff --git a/lua/persisted/init.lua b/lua/persisted/init.lua index 26b003d..1f9a2e4 100644 --- a/lua/persisted/init.lua +++ b/lua/persisted/init.lua @@ -103,7 +103,7 @@ function M.load(opt) local session = opt.last and get_last() or get_current() if session and vim.fn.filereadable(session) ~= 0 then - utils.load_session(session, _, config.options.after_source) + utils.load_session(session, config.options.before_source, config.options.after_source) end if config.options.autosave and (allow_dir() and not ignore_dir()) then