feat: add before_source callback

main
olimorris 2022-08-13 10:53:59 +01:00
parent 4fe0e3aeab
commit b70eb5317d
3 changed files with 6 additions and 2 deletions

View File

@ -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 > **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 ```lua
require("persisted").setup({ require("persisted").setup({
before_source = function()
print("Sourcing...")
end,
after_source = function() after_source = function()
-- Reload the LSP servers -- Reload the LSP servers
vim.lsp.stop_client(vim.lsp.get_active_clients()) vim.lsp.stop_client(vim.lsp.get_active_clients())

View File

@ -11,6 +11,7 @@ local defaults = {
ignored_dirs = nil, -- table of dirs that are ignored for auto-saving and auto-loading 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 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 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 after_source = nil, -- function to run after the session is sourced
telescope = { -- options for the telescope extension telescope = { -- options for the telescope extension
before_source = nil, -- function to run before the session is sourced via telescope before_source = nil, -- function to run before the session is sourced via telescope

View File

@ -103,7 +103,7 @@ function M.load(opt)
local session = opt.last and get_last() or get_current() local session = opt.last and get_last() or get_current()
if session and vim.fn.filereadable(session) ~= 0 then 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 end
if config.options.autosave and (allow_dir() and not ignore_dir()) then if config.options.autosave and (allow_dir() and not ignore_dir()) then