feat: #11 after_source callback

main
olimorris 2022-05-05 11:41:57 +01:00
parent 13dacbc880
commit b778a4ebc4
3 changed files with 15 additions and 2 deletions

View File

@ -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!!**

View File

@ -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

View File

@ -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