diff --git a/README.md b/README.md index e338c4f..cb729a6 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 + 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 72d9fc2..a2e94be 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 + 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 1589857..7d1fd62 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 + 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 760f6b6..db46a3a 100644 --- a/lua/persistence/init.lua +++ b/lua/persistence/init.lua @@ -55,6 +55,10 @@ function M.start() end end + if not Config.options.save_when() then + return + end + M.save() M.fire("SavePost") end,