olimorris / persisted.nvim

💾 Simple session management for Neovim with git branching, autoloading and Telescope support
MIT License
418 stars 24 forks source link

feat: add config option autosave_when_session_exists #99

Closed MasouShizuka closed 6 months ago

MasouShizuka commented 7 months ago

As discussed #95.

olimorris commented 7 months ago

Thanks for this.

Quick glance and looks good. I added a global variable a couple of days ago vim.g.persisted_exists...could that be utilised in the should_autosave callback? Or, could we pass the current session to the callback?

I think that would accomplish your ask, take up less lines of code and always bring more possibilities to the callback.

MasouShizuka commented 7 months ago

It's possible, but this requires changing session_exists() or vim.g.persisted_exists.

Specifically, put the session called by write() in save() into session_exists() instead of just determining whether the session file in the current working directory exists.

vim.g.persisted_exists also needs to be changed based on conditions, such as the working directory changing when follow_cwd=true. I personally think that this global variable can be completely replaced by session_exists().

To do this, user need to put the session_exists() API into the should_autosave function.