possession.nvim icon indicating copy to clipboard operation
possession.nvim copied to clipboard

Automatic session save/restore

Open jedrzejboczar opened this issue 3 years ago • 4 comments

As noted in https://github.com/jedrzejboczar/possession.nvim/issues/2, it would be nice to have this kind of functionality built-in.

Currently one could use the provided API to do this in their config: list avaliable sessions and compare sessions[X].cwd to current working directory to select the session we want.

Adding this feature to the plugin would require some configuration options like:

  • should be enabled by a config option (disabled by default)
  • do we want to match CWD exactly, or if opening Vim in /dir/a/b session with cwd /dir/a should be used?
  • or should we actually load the previously open session and not care about cwd whatsoever?
  • when to auto-save the session?
  • config option for enabling this could be a boolean or a user function that returns a boolean - this can offload some more logic to users

jedrzejboczar avatar Apr 04 '22 10:04 jedrzejboczar

+1 for this functionality.

Regarding the cwd, I think matching exactly is the least surprising behavior.

If you decide to just open the previous session, make sure that cwd is set.

dsully avatar Apr 06 '22 15:04 dsully

I agree with exact matching

RaafatTurki avatar Apr 09 '22 04:04 RaafatTurki

or should we actually load the previously open session and not care about cwd whatsoever?

I think it would be nice to indeed check cwd

Even now, when doing PossessionLoad without passing a name, I would intuitively expect it to load the session according to cwd and not the last general session.

jemag avatar Apr 19 '22 13:04 jemag

With https://github.com/jedrzejboczar/possession.nvim/pull/7 by @wasden already merged, automatic save functionality should work without issues. As for auto restore, I hope I will implement it somewhere soon.

Even now, when doing PossessionLoad without passing a name, I would intuitively expect it to load the session according to cwd and not the last general session.

Yeah, I already noticed that the last general session is problematic, especially when opening two Neovim instances, because they will be overwriting the last session of each other. This is especially annoying for PossessionSave, so I think I will change the behavior (at the very least for save) when I find time to work on the restore function.

jedrzejboczar avatar May 23 '22 09:05 jedrzejboczar

Any updates on this?

aaditeynair avatar Mar 16 '23 10:03 aaditeynair

@aaditeynair Not really, I didn't have time to work on this and auto-restore is not something I would personally need. If anyone is willing to give it a try then I'd be happy to merge :)

jedrzejboczar avatar Mar 20 '23 08:03 jedrzejboczar

I'll try to do when I get some free time.

aaditeynair avatar Mar 21 '23 10:03 aaditeynair

Partially resolved, continued in https://github.com/jedrzejboczar/possession.nvim/issues/45#issuecomment-1817597856

jedrzejboczar avatar Nov 18 '23 19:11 jedrzejboczar