Roeeeee 3d443bd0a7
feat(persistence): add pre- and post- load hooks (#24)
* Add optional hook typings to config object

* Add optional hooks conditional calls

* Add hooks description to main readme
2024-05-16 19:03:16 +02:00

23 lines
638 B
Lua

local M = {}
---@class PersistenceOptions
---@field pre_save? fun()
---@field post_save? fun()
---@field pre_load? fun()
---@field post_load? fun()
local defaults = {
dir = vim.fn.expand(vim.fn.stdpath("state") .. "/sessions/"), -- directory where session files are saved
options = { "buffers", "curdir", "tabpages", "winsize", "skiprtp" }, -- sessionoptions used for saving
save_empty = false, -- don't save if there are no open file buffers
}
---@type PersistenceOptions
M.options = {}
function M.setup(opts)
M.options = vim.tbl_deep_extend("force", {}, defaults, opts or {})
vim.fn.mkdir(M.options.dir, "p")
end
return M