[Bug]: Unable to turn off autosaving
ewok opened this issue · 6 comments
Your Persisted.nvim config
{
save_dir = "sessions/",
autoload = false,
autosave = false,
}
Error messages
No response
Describe the bug
What I expect to happen
Not saved session
What actually happens
Session is saved
I did some small research. I guess it is related to the https://github.com/olimorris/persisted.nvim/blob/main/lua/persisted/init.lua#L148-L153 block.
Small test:
local function check(conf)
if (conf.options.autosave and type(conf.options.should_autosave) == "function")
and not conf.options.should_autosave()
then
print("not saving")
else
print("saving")
end
end
-- Works as expected
-- autosave = true and should_autosave = true
local config1 = {}
config1.options = {}
config1.options.autosave = true
config1.options.should_autosave = function()
return true
end
check(config1)
-- output: saving
-- Doesn't work as expected
-- autosave = false and should_autosave = true
local config2 = {}
config2.options = {}
config2.options.autosave = false
config2.options.should_autosave = function()
return true
end
check(config2)
-- output: saving
-- Works as expected
-- autosave = true and should_autosave = false
local config3 = {}
config3.options = {}
config3.options.autosave = true
config3.options.should_autosave = function()
return false
end
check(config3)
-- output: not saving
-- Doesn't work as expected
-- autosave = false and should_autosave = false
local config4 = {}
config4.options = {}
config4.options.autosave = false
config4.options.should_autosave = function()
return false
end
check(config4)
-- output: saving
Reproduce the bug
Setup minimal.lua with my config.
1 Enter vim.
2. Escape vim.
3. ls sessions/ | wc -l
4. in sessions folder is a saved session.
Final checks
- I have made sure this issue exists in the latest version of the plugin
- I have tested with the
minimal.lua
config file above and still get the issue - I have used
SessionSave
to save the session before restarting Neovim and usingSessionLoad
- I have made sure this is not a duplicate issue
yeah, I'm facing the same issue too. I hope we get a fix I love the plugin so much but I am unable to turn off autosaving. please help if there is a fix.
@ewok thanks for raising this.
To confirm my understanding is correct, you expect:
- When
autosave = false
, Persisted should never save a session automatically - Only when
autosave = true
should the plugin call theshould_autosave
function and based on it boolean output, save the session
The above is what the plugin should do and appreciate at the minute it doesn't.
@olimorris Yes that's right. imho autosave = false
should completely turn off the autosaving, but it does't. Thank you!
This should be fixed in PR #56. Can you guys confirm?
EDIT: I've also allowed for :SessionSave
to override the autosave = false
config option. Thoughts being that you may wish to manually save the session
@olimorris confirming! Now works like a charm. Thank you so much 👍🏼
closing