diff --git a/lua/persisted/init.lua b/lua/persisted/init.lua index 1b91ed1..3bd875c 100644 --- a/lua/persisted/init.lua +++ b/lua/persisted/init.lua @@ -130,8 +130,11 @@ function M.stop() end ---Save the session +---@param opt? table ---@return nil -function M.save() +function M.save(opt) + opt = opt or {} + -- If the user has stopped the session, then do not save if vim.g.persisting == false then return @@ -145,10 +148,12 @@ function M.save() vim.api.nvim_exec_autocmds("User", { pattern = "PersistedSavePre" }) - if - (config.options.autosave and type(config.options.should_autosave) == "function") - and not config.options.should_autosave() - then + -- Autosave config option takes priority unless it's overriden + if not config.options.autosave and not opt.override then + return + end + + if type(config.options.should_autosave) == "function" and not config.options.should_autosave() then return end diff --git a/plugin/persisted.lua b/plugin/persisted.lua index 91ab052..e7a327b 100644 --- a/plugin/persisted.lua +++ b/plugin/persisted.lua @@ -7,7 +7,7 @@ local persisted = require("persisted") -- Create the user commands vim.cmd([[command! SessionStart :lua require("persisted").start()]]) vim.cmd([[command! SessionStop :lua require("persisted").stop()]]) -vim.cmd([[command! SessionSave :lua require("persisted").save()]]) +vim.cmd([[command! SessionSave :lua require("persisted").save({ override = true })]]) vim.cmd([[command! SessionLoad :lua require("persisted").load()]]) vim.cmd([[command! SessionLoadLast :lua require("persisted").load({ last = true })]]) vim.cmd([[command! -nargs=1 SessionLoadFromFile :lua require("persisted").load({ session = })]])