From d2d5dc3df5a3fcb0bc38491cdae98940176bb104 Mon Sep 17 00:00:00 2001 From: AndreJesusBrito Date: Sun, 7 Sep 2025 17:38:29 +0100 Subject: [PATCH 1/2] feat(main): add user defined condition before saving session --- README.md | 1 + doc/persistence.nvim.txt | 1 + lua/persistence/config.lua | 1 + lua/persistence/init.lua | 4 ++++ 4 files changed, 7 insertions(+) diff --git a/README.md b/README.md index e338c4f..8e3d46b 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Persistence comes with the following defaults: -- Set to 0 to always save need = 1, branch = true, -- use git branch to save session + condition = function() return true end, -- only save session if user defined function returns true } ``` diff --git a/doc/persistence.nvim.txt b/doc/persistence.nvim.txt index 72d9fc2..d9615c2 100644 --- a/doc/persistence.nvim.txt +++ b/doc/persistence.nvim.txt @@ -58,6 +58,7 @@ Persistence comes with the following defaults: -- Set to 0 to always save need = 1, branch = true, -- use git branch to save session + condition = function() return true end, -- only save session if user defined function returns true } < diff --git a/lua/persistence/config.lua b/lua/persistence/config.lua index 1589857..dadaf2d 100644 --- a/lua/persistence/config.lua +++ b/lua/persistence/config.lua @@ -7,6 +7,7 @@ local defaults = { -- Set to 0 to always save need = 1, branch = true, -- use git branch to save session + condition = function() return true end, -- only save session if user defined function returns true } ---@type Persistence.Config diff --git a/lua/persistence/init.lua b/lua/persistence/init.lua index 760f6b6..b40228f 100644 --- a/lua/persistence/init.lua +++ b/lua/persistence/init.lua @@ -55,6 +55,10 @@ function M.start() end end + if not Config.options.condition() then + return + end + M.save() M.fire("SavePost") end, From 6e79776c34c8e0aecd2636a10d3b043456e380e1 Mon Sep 17 00:00:00 2001 From: AndreJesusBrito Date: Sat, 27 Dec 2025 22:11:29 +0000 Subject: [PATCH 2/2] rename option "condition" to "save_when" --- README.md | 2 +- doc/persistence.nvim.txt | 2 +- lua/persistence/config.lua | 2 +- lua/persistence/init.lua | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8e3d46b..cb729a6 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Persistence comes with the following defaults: -- Set to 0 to always save need = 1, branch = true, -- use git branch to save session - condition = function() return true end, -- only save session if user defined function returns true + save_when = function() return true end, -- only save session if user defined function returns true } ``` diff --git a/doc/persistence.nvim.txt b/doc/persistence.nvim.txt index d9615c2..a2e94be 100644 --- a/doc/persistence.nvim.txt +++ b/doc/persistence.nvim.txt @@ -58,7 +58,7 @@ Persistence comes with the following defaults: -- Set to 0 to always save need = 1, branch = true, -- use git branch to save session - condition = function() return true end, -- only save session if user defined function returns true + save_when = function() return true end, -- only save session if user defined function returns true } < diff --git a/lua/persistence/config.lua b/lua/persistence/config.lua index dadaf2d..7d1fd62 100644 --- a/lua/persistence/config.lua +++ b/lua/persistence/config.lua @@ -7,7 +7,7 @@ local defaults = { -- Set to 0 to always save need = 1, branch = true, -- use git branch to save session - condition = function() return true end, -- only save session if user defined function returns true + save_when = function() return true end, -- only save session if user defined function returns true } ---@type Persistence.Config diff --git a/lua/persistence/init.lua b/lua/persistence/init.lua index b40228f..db46a3a 100644 --- a/lua/persistence/init.lua +++ b/lua/persistence/init.lua @@ -55,7 +55,7 @@ function M.start() end end - if not Config.options.condition() then + if not Config.options.save_when() then return end