I want to discuss a new module system, and how we can use it for better plugin integration, and especially to make better integration between different plugins.
Today I’ve submitted my new plugin langmap.kak that uses module system to make Kakoune load faster, but also to allow integration with my another plugin powerline.kak. I’ve added a new langmap
powerline module, but this time, it isn’t defined within the powerline.kak plugin, but within the langmap.kak plugin.
To be able to load these plugins in any order, I’ve wrapped the langmap powerline module into provide module langmap_powerline
. But in order to require this module only when powerline.kak
was actually loaded, I’ve added a new option to the end of powerline.kak: declare-option bool powerline_loaded true
, and set up the hook hook -once global WinSetOption powerline_loaded=true %{ require-module langmap_powerline };
. This way I can source langmap.kak before powerline.kak, and the langmap powerline module will be loaded after successful load of powerline.kak
Earlier I’ve proposed to provide this kind of a variable to allow lazy loading, but new provides requires model still can benefit from such approach.
My another plugin fzf.kak (this post isn’t an advertisement, trust me!), provides a module for a plugin called yank-ring.kak by @alexherbo2. It was introduced before the provides requires model were merged into Kakoune, so it’s using another approach. It tries to set the hidden yank_ring_history
option, and if it faild, then module isn’t declared, but if it can do this, the module is provided. This is a cumbersome way to handle this, and I want to know @alexherbo2 what do you think about adding yank_ring_loaded
option to the end of your script, so other plugins could declare their modules only after your plugin actually loaded by adding simple hook as I showed above.
What I want to say, is that I think that every script should provide a variable to identify if it was loaded or not. It is a common practice in Vim plugins, and Emacs packages, so I think if we want Kakoune plugins to integrate well, we should similar (yet appropriate for Kakoune) approach.