Kakoune: [Proposal] Provides-Requires Lazy Loading Model

Created on 7 Mar 2019  路  2Comments  路  Source: mawww/kakoune

I wanted to get feedback on this lazy-loading idea before attempting to implementing it.

Requirements given by mawww

  • No central place that knows of all filetype/scripts
  • One way dependencies (sh.kak should not know that kak.kak depends on it)
  • Simple file layout and behaviour, easy to work without a plugin manager
  • Fast

Provides-Requires Model

This model handles lazy-loading by adding two new commands, provides and
requires. The provides command specificies a module that is being provided,
and the commands for that module. The requires command looks up the modules
that have been specified by provides, runs the commands for the given module,
and marks it as loaded. If the module has already been loaded, it returns
immediately. It would fail if the requested module has not been provided. This
method would allow for overriding default modules with a -override switch for
the provides command, which would fail if the module has already been loaded.

Pros

  • Follows kakoune's current file-less structure (excepting sourcing)
  • Easy to override specific highlighters in kakrc

Cons

  • Needs the entire environment to be loaded before requires are guaranteed to work

Example

## sh.kak
hook global BufCreate .*\.(z|ba|c|k|mk)?sh(rc|_profile)? %{
    requires sh
    set-option buffer filetype sh
}

provides sh %{
    # highlighters, etc for sh
}



## kak.kak
hook global BufCreate (.*/)?(kakrc|.*.kak) %{
    requires sh
    requires kak
    set-option buffer filetype kak
}

provides kak %{
    # highlighters, etc for kak
}



## kakrc
provides -override sh %{
    # Overriding sh
}

Most helpful comment

I think this is a promising direction, its simple, fast, and very flexible, in particular I like the fact that it opens the door towards vim-like autoloading with:

provides sh %{ source "%val{runtime}/rc/sh.kak" }

(I dont think we should do that right now, but in case some scripts become so big that reading and keeping them in memory is deemed too slow, we can go this way).

It shares the nice property @maximbaz's solution had that its just a few lines to add to each .kak files (just wrap the specific parts into provides).

Another thing I was wondering is if we can provide fallback: Say we have kakrc.kak in our autoload but not sh.kak, it would be nice to have that work out of the box. That means kakrc.kak should be able to specify that sh can be provided by sourcing %val{runtime}/rc/core/sh.kak.

Something that will work without extra features would be:

try %{ requires sh } catch %{ source "%val{runtime}/rc/core/sh.kak; requires sh }

If this pattern proves really usefull, it could be implemented as a switch to requires:

requires sh -fallback-source "%val{runtime}/rc/core/sh.kak"

Also, we can bikeshed a bit on the provides and requires command names.

All 2 comments

I think this is a promising direction, its simple, fast, and very flexible, in particular I like the fact that it opens the door towards vim-like autoloading with:

provides sh %{ source "%val{runtime}/rc/sh.kak" }

(I dont think we should do that right now, but in case some scripts become so big that reading and keeping them in memory is deemed too slow, we can go this way).

It shares the nice property @maximbaz's solution had that its just a few lines to add to each .kak files (just wrap the specific parts into provides).

Another thing I was wondering is if we can provide fallback: Say we have kakrc.kak in our autoload but not sh.kak, it would be nice to have that work out of the box. That means kakrc.kak should be able to specify that sh can be provided by sourcing %val{runtime}/rc/core/sh.kak.

Something that will work without extra features would be:

try %{ requires sh } catch %{ source "%val{runtime}/rc/core/sh.kak; requires sh }

If this pattern proves really usefull, it could be implemented as a switch to requires:

requires sh -fallback-source "%val{runtime}/rc/core/sh.kak"

Also, we can bikeshed a bit on the provides and requires command names.

Perhaps this can be closed now?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lenormf picture lenormf  路  3Comments

Delapouite picture Delapouite  路  4Comments

akkartik picture akkartik  路  3Comments

dpc picture dpc  路  4Comments

basbebe picture basbebe  路  4Comments