Conversation
Currently plugins have no way to communicate with each other without the user doing the plumbing in their visrc.lua file. By introducing a global namespace vis.plugins each plugin can expose its API or Configuration in its own namespace vis.plugins['plugin-name']. This allows plugins to expose hooks for others to insert data, export utility functions or build extendable "base" plugins.
External completions sources may insert a completion hook to
insert their completions into the complete-word plugin.
A hook is inserted by adding it to the table:
vis.plugin['complete-word'].completion_hooks
Each hook is called with the word prefix to complete and MUST
return a table containing the completion candidates.
table.insert(vis.plugins["complete-word"].candidate_hooks,
function(prefix)
return {prefix.."foo"}
end)
Is there an example of this plumbing that I could take a look at? I'm asking because a few of my plugins do customize each other via hooks, but no action from the user is necessary. The user doesn't even need to know about it. The thing is, my hooks are just functions in the global namespace. On one hand, this runs the risk that another plugin, or the user, defines a symbol with that same name. On the other hand, this keeps everything working even if the user renames the plugins to their liking. Which is not possible if you use per-plugin tables. Another thing - if per-plugin tables are what you want, can't you use |
My local lspc = require('vis-lspc')
local plugin2 = require("plugin2")
plugin2.use_select_impl(lspc.select)
In general I dislike using globals, but for our use case the "C approach" (globals with a safe prefix ( Using a per plugin table under a namespace controlled by the plugin is what I propose.
I did not know about |
Multiple times we needed a way for plugins to communicate with each other.
Currently the user has to do the plumbing in their
visrc.luafile.This proposal simply adds a global table
vis.pluginsas central namespacefor all plugins to expose their APIs.
Each plugin would insert its own table
vis.plugins['plugin-name'].This allows plugins to be easily extended by other plugins without
duplicating a lot of user configuration code.
Usecases:
Questions
vis.plugins=nil?Related
Ctrl+Ncompletions #1332Fixes #1332.