From 3ebc5d77aed824bd016ec745c879218d49dd6939 Mon Sep 17 00:00:00 2001 From: olimorris Date: Sat, 18 Nov 2023 16:07:38 +0000 Subject: [PATCH] refactor: `override` to `force` for SessionSave --- lua/persisted/init.lua | 12 +++++++----- plugin/persisted.lua | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lua/persisted/init.lua b/lua/persisted/init.lua index cf085c9..14542df 100644 --- a/lua/persisted/init.lua +++ b/lua/persisted/init.lua @@ -25,6 +25,7 @@ local function ignore_dir() if ignored_dirs == nil then return false end + return utils.dirs_match(vim.fn.getcwd(), ignored_dirs) end @@ -35,6 +36,7 @@ local function get_last() table.sort(sessions, function(a, b) return vim.loop.fs_stat(a).mtime.sec > vim.loop.fs_stat(b).mtime.sec end) + return sessions[1] end @@ -164,17 +166,17 @@ function M.save(opt) opt = opt or {} if not opt.session then - -- Do not save the session if the user has manually stopped it, but if there's an override, then do it - if (vim.g.persisting == false or vim.g.persisting == nil) and not opt.override then + -- Do not save the session if the user has manually stopped it...unless it's forced + if (vim.g.persisting == false or vim.g.persisting == nil) and not opt.force then return end - -- Do not save the session if autosave is turned off...unless it's overriden - if not config.options.autosave and not opt.override then + -- Do not save the session if autosave is turned off...unless it's forced + if not config.options.autosave and not opt.force then return end - -- Do not save the session if the callback returns false + -- Do not save the session if the callback returns false...unless it's forced 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 e7a327b..fb90415 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({ override = true })]]) +vim.cmd([[command! SessionSave :lua require("persisted").save({ force = 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 = })]])