A way to let other plugins know if a plugin exists in user configuration

I think that this should be discussed. I’ve written my plugins in a modular way, so another users could create their own modules, and plugin developers could integrate their plugins with my plugins by adding a module that is only used when both plugins are loaded.

For example I have a plugin called powerline.kak that consists of separate sub-modules for each modeline part. For example, my another plugin smarttab.kak could display which tab mode is currently used. Builtin kakoune modeline has this capabilities, since we can add any variable inside it. So does powerline.kak, but currently for this module to be loaded smarttab,kak plugin needs to know if powerline.kak is installed.

In Vim plugins can communicate with variables, in official guide it is stated that a plugin should define a load guard to prevent double loading. Since this isn’t directly possible in Kakoune, and all plugins are loaded when kakoune starts (I’m working for the solution of this within the plug.kak so it could load plugins per filetype, but unloading isn’t possible unfortunately) so plug.kak keeps track not to load plugins twice. It is perfectly safe to place several identical plug commands, or reload your configuration any time you want.

But I think it is plugin’s response to let other plugins know if it installed. So my proposal is to define an option with this format:

declare-option bool <plugin_name>_installed true

In every plugin. So a modular plugin like fzf.kak or powerline.kak could know if it can load extra modules in it’s configuration. This will allow the same level of integration between plugins as in Vim, where a plugin called vim-airline can detect loaded plugins and display their information accordingly. For example I could add a kak-lsp module for powerline.kak or fzf.kak, and it would be active only if user has both plugins by a simple test:

[ -n "$kak_opt_kak_lsp_installed" ] && $load_kak_lsp_module=true

This would also mean that any other plugin developer who would like to add a poweline or fzf module to their plugins would not need to send a PR to my plugins directly, since they could have a way of knowing if fzf.kak is installed.

I thought about a similar thing a while ago : https://github.com/mawww/kakoune/pull/1448

With your approach you need a consensus of all plugins author to add the

declare-option bool <plugin_name>_installed true

line in their plugins.

With the Source hook, a user could build a comprehensive list of all plugins loaded and react accordingly. Something like that (in pseudo code):

hook global Source fzf.kak %{
  declare-option bool fzf_installed true
}

Well, yes. This could go with the #2402, but I know that there’s not many people who support this actually.