gennaro-tedesco / nvim-possession

📌 the no-nonsense session manager
MIT License
215 stars 7 forks source link

Switch session will clean up buffers from current session? #7

Closed tmpm697 closed 1 year ago

tmpm697 commented 1 year ago

i.e: when you're in a session and you want to switch to other session, clean up current buffers before jumping is more ideal.

I sometime find keep current buffers useful, sometime clean them up before jumping useful, so an option would help.

gennaro-tedesco commented 1 year ago

Also a good suggestion, however it needs to be thought carefully: this is because in many cases users have loaded many other buffers with, say, git status (imagine vim-fugitive), file explorers (nvim-tree/neotree) or similar, and I am not sure cleaning them all up is the expected behaviour (unless one is able to only clean up buffers pertaining to the previous active session).

I will think about it, good idea but probably a bit complicated to implement :)

tmpm697 commented 1 year ago

You can just delete all the buffers currently, nvim will block you from switch session if user still having some modifying buffer by its native function (it will ask user input before doing anything next).

for other integration you just need add support for post_restore_cmds and pre_save_cmds to put them aside.

and if you have auto-save session enabled, switch session and clean all current buffers is safe operation as auto-save will be triggered when switching.

but fast you're probably ended up with this bug as i find as switching did not give a clean vacuum: https://github.com/rmagatti/auto-session/issues/198 , idk but hope this plugin bypass this issue somehow.

gennaro-tedesco commented 1 year ago

I have opened a PR with this feature in here; again it would be great if you would help me test (it should work as expected, but one more pair of eyes are always welcome).

You have to opt-in the feature with

autoswitch = {
    enable = true,
}
gennaro-tedesco commented 1 year ago

Merged to main and released in v0.0.5. You can now upgrade the plugin via your package manager and it should work (by enabling the option).

tmpm697 commented 1 year ago

nice, ty.

agusdmb commented 1 year ago

nice! i was looking for exactly the same... i guess the documentation in the readme could be more clear about what the "autoswitch" does... i thought it would just check the current directory when opening vim to match a session or something like that... specifying that cleans one session before changing to the next would be more appropriate i guess

agusdmb commented 1 year ago

as mentioned, a pre_hook could be helpful, for example to disable the lsp server before switching sessions (in the post hook can be enable again)

gennaro-tedesco commented 1 year ago

I have been considering the idea of a pre_hook at times, however I have not yet come to a compelling example/argument that cannot be implemented via simple autocommands that trigger on, say, BufLeave/BufRead or the like (according to the behaviour that one wishes). I know that some session plugins implement something of the sort, but I am not sure these behaviours should belong to a session manager. It would not be a difficult addition, I am just not convinced it fits conceptually.

I keep the door open though, and may implement it when some specific use cases come along :)