jedrzejboczar / possession.nvim

Flexible session management for Neovim.
MIT License
363 stars 20 forks source link

[Question] Custom plugins? (extensions?) #49

Open Gazareth opened 8 months ago

Gazareth commented 8 months ago

I'd like to add my own plugin that uses the hooks and adds its own plugin_data to the session.

For example if you wanted to give open tabs custom names, and store them in the session JSON file.

I've looked through the code and I can't see any way to add to the plugins array?

A better name for this might be 'extensions', similar to telescope.

jedrzejboczar commented 8 months ago

A better name for this might be 'extensions', similar to telescope.

Now I also think that wasn't the best decision as it is a bit confusing, but I think it's too late for it to be worth changing, so let's just stick with "plugins".

Regarding your main question - do you want to add something generic to possession.nvim itself or rather something custom for your nvim config?

If it's the second one, then you can just use the user hooks (require('possession').setup { hooks = { before_save = function ... } } ). Otherwise, you just add a file possession.nvim/lua/possession/plugins/myplugin.lua and add it's name ('myplugin',) to plugins array and add it's configuration to config.lua. You can take a look at commits that add other plugins, e.g. https://github.com/jedrzejboczar/possession.nvim/commit/4665ceec10991e040b7117582e62cc5edd3c964f, or specifically related to storing tab names: https://github.com/jedrzejboczar/possession.nvim/commit/acc5e8e5cbdb1a060f9fa8291166b7b52ee4ce77.

Gazareth commented 8 months ago

I was just wondering if it's possible to create plugins that are distributed externally to this repo.

I am happy to use user hooks for now, but if I wanted to distribute my plugin to other people who use possession.nvim, without merging a PR into the main repo (since it might be something really niche, that doesn't need to be part of the canonical possession distribution)

jedrzejboczar commented 8 months ago

Ok, now I understand. Currently it's not possible, but I guess it could be nice to have such option.

So my initial idea would be as follows:

What do you think?

Gazareth commented 7 months ago

Your idea would work for minimal changes to posession, however I think ultimately it'd be better to have something more akin to telescope's plugin model, where the consumer uses this syntax, e.g.

require('telescope').load_extension('my-plugin')

Since it's more generic, doesn't require knowledge of the architecture within, e.g. plugin ordering, table structure to pass in, etc.