Giter Club home page Giter Club logo

Comments (4)

andreyorst avatar andreyorst commented on May 25, 2024

But plug already has a mechanism to noload. Should the module autoload itself (e.g. add a KakBegin hook that require-module's), so that users can just add to their kakrc this and avoid two layers of optional loading?

noload is a hack to support plugins that require their kakscript code by themselves somehow. kak-lsp did this, and I needed a way to tell plug.kak about itself without loading it twice, and hardcoding certain names, like plug.kak into the core. It works, but this is still a hack, and should be avoided as much as possible. Besides, by not requiring something immediatelly you would not gain much, as you would need to do it eventually,

By adding a KakBegin hook into your .kak script, you basically force people to delay loading it after KakBegin is executed if they don't want to enable your plugin immediately. This is a bad design IMO. Explicit is always better than implicit.

Plugins support module system, which is a solution to this problem, and plug.kak tries to make it really easy to use and configure modules with defer and demand keywords.

So for example, if you're writing a plugin, that is split up to different modules inside, and you need to provide a single entry point that will require all modules in the needed order, you should use provide-module and require-module commands. Sadly I don't know a best practice to handle this. You can take a look at how powerline.kak or fzf.kak do this, but I think this is not the best architecture. Fzf.kak tries to be lazy, only requiring modes when you invoke a specific keybinding, while powerline.kak loads everything needed.


A comprehensive manual on how to write plugins would be a good thing, but I'm a bit out of the loop, as I'm no longer write new plugins for Kakoune, only maintain the existing ones I already wrote, because they have userbase, so I'm in no position to write one. Paired with the fact that I think that most of my plugins are overengineered in their architecture is really not making me not really an expert in the area :)

Kakoune actually has a bit of its own docs on writing plugins: https://github.com/mawww/kakoune/blob/master/doc/writing_scripts.asciidoc but it's rather an overview of the basic architecture, and doesn't go into great detail of how to use module system for example.

from plug.kak.

mralusw avatar mralusw commented on May 25, 2024

OK, so you're suggesting that inside the autoload part of the plugin I add

provide-module mod1 %{}
provide-module mod2 %{}
provide-module entry %{}

require-module entry

and have users add plug <URL>://myplugin to their kakrc? I also have some configuration options that users should change before require-module, so I think

plug <URL>://myplugin %{
  set global myplugin_work_dir '/tmp/myplugin'
} demand entry %{}

is more flexible (I noticed the final %{} is required even if empty, not sure if that's intended, but there's #89 for that)

from plug.kak.

andreyorst avatar andreyorst commented on May 25, 2024

OK, so you're suggesting that inside the autoload part of the plugin I add

provide-module mod1 %{}
provide-module mod2 %{}
provide-module entry %{}

require-module entry

By adding require-module entry to your kakscript you've essentially disabled the ability to load this modules lazily. So no, instead I'm suggesting this:

provide-module mod1 %{}
provide-module mod2 %{}
provide-module entry %{
    require-module mod1
    require-module mod2
    ...
}

Then you can suggest users of your plugin to require it by requiring the entry module, which will do all setups it need automatically on demand.

and have users add plug <URL>://myplugin to their kakrc? I also have some configuration options that users should change before require-module, so I think

Then you simply don't put those into modules:

declare-option str option-one ""
provide-module mod1 %{}
provide-module mod2 %{}
provide-module entry %{
    require-module mod1
    require-module mod2
    declare-option str option-two ""
    ...
}

Which can then be set up as follows:

plug <URL>://myplugin %{
  set global option-one "foo"
} demand entry %{
  set global option-one "bar"
}

from plug.kak.

mralusw avatar mralusw commented on May 25, 2024

OK, I agree, that's what I thought would work best as well (and what I'm currently using for my mru-files.kak plugin).

from plug.kak.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.