gennaro-tedesco / nvim-possession

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

Add auto-restore base on current dir, aware of neo-tree? #4

Closed tmpm697 closed 1 year ago

tmpm697 commented 1 year ago

Hi, i like this plugin, this has potential.

but i use https://github.com/nvim-neo-tree/neo-tree.nvim and i can't call neo-tree when restore session or this plugin does not aware of tree, can you add support for pre_save_cmds and post_restore_cmds in setup() so tree can restore properly?

and can you add auto restore base on current dir, so we don't have to load ourselves

idk but with your plugin, my colorscheme restore correctly when i switch between session --> this huge plus compare to https://github.com/rmagatti/auto-session/issues/198

gennaro-tedesco commented 1 year ago

Good morning and thank you for your suggestions!

i can't call neo-tree when restore session or this plugin does not aware of tree

Could you expand on what this behaviour is? I do not use neo-tree myself, so I do not know what is expected here.

and can you add auto restore base on current dir, so we don't have to load ourselves

Yes, this is planned, though I am still trying to understand what's the best way to implement it. Say for example there are 2-3 different sessions in the current dir, which one would you choose to autoload (or equivalently would you prompt the user all the times to choose, or would you just load up the first in the list)?

tmpm697 commented 1 year ago

Yes, this is planned, though I am still trying to understand what's the best way to implement it. Say for example there are 2-3 different sessions in the current dir, which one would you choose to autoload (or equivalently would you prompt the user all the times to choose, or would you just load up the first in the list)?

I think just load up the last stored version for ease, as user probably assume that they'll have only one session to restore under a folder.

Could you expand on what this behaviour is? I do not use neo-tree myself, so I do not know what is expected here.

say i open neo-tree and other buffers and save that session, this plugin will restore the neo-tree buffer also but it should not be stored with other buffers, instead neo-tree buffer should be closed and open when restore, check this setting:

  config = function()
    require("nvim-possession").setup({
      pre_save_cmds = { "Neotree action=close" },
      post_restore_cmds = { "Neotree action=show" },
    })
  end,

so above setting will instruct nvim-possession close neotree before save and then open it when restore --> this is correct way and what i wanted.

the above code won't work as it's not supported currently.

surprisingly this plugin work out-of-box with https://github.com/noib3/nvim-cokeline :thumbup:

gennaro-tedesco commented 1 year ago

I think just load up the last stored version for ease, as user probably assume that they'll have only one session to restore under a folder.

yes, I agree, this is probably the easiest and most common scenario, hence good for a first proof of concept. I will start working on it later in the day :)

say i open neo-tree and other buffers and save that session, this plugin will restore the neo-tree buffer also but it should not be stored with other buffers, instead neo-tree buffer should be closed and open when restore, check this setting:

I see. This seems to be specific to neo-tree and I would need a bit more time to dig into their code and check how they are implementing the autorestore of their buffers.

For the moment I will focus on auto-load in the current dir (as it is a general case that can be used by everybody) and then look into plugin-specific integrations, if possible.

gennaro-tedesco commented 1 year ago

I have a work-in-progress branch where I started a caveman implementation for autoload: I am having troubles with treesitter syntax parsing though, it doesn't activate the highlight when buffers are automatically loaded and one must invoke it themselves - not sure why it is so.

If you want to try out the branch notice you must explicitly opt-in the autoload configuration, namely

possession.setup({
    autoload = true
})
gennaro-tedesco commented 1 year ago

I have opened a PR where I somewhat managed to workaround the treesitter issue: it would be great if you could help me test if this is the intended behaviour you proposed (you may specify and install the corresponding branch with most package managers).

tmpm697 commented 1 year ago

yes, it worked for me.

tmpm697 commented 1 year ago

for hooks pre_save_cmds, post_restore_cmds, you can check its implementation here: https://github.com/rmagatti/auto-session/blob/main/lua/auto-session.lua#L5 i don't understand it much :(

gennaro-tedesco commented 1 year ago

The change has been merged on main with v0.0.2 and is available if you update the plugin via your plugin manager.