Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Gazareth opened this issue Jan 14, 2024 · 4 comments
Open

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

Gazareth opened this issue Jan 14, 2024 · 4 comments

Comments

@Gazareth
Copy link

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
Copy link
Owner

jedrzejboczar commented Jan 15, 2024

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. 4665cee, or specifically related to storing tab names: acc5e8e.

@Gazareth
Copy link
Author

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
Copy link
Owner

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:

  • You have repo my_plugin and create my_plugin/lua/possession/plugins/my_plugin.lua
  • User passes plugin setting via possession.setup { plugins = { my_plugin = true --[[ or table of settings ]] } }
  • There would need to be a way to define plugins order. I would probably remove the plugins table and allow plugins to return their priorities? Not sure about this one

What do you think?

@Gazareth
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants