Skip to main content

declare_plugin

Macro declare_plugin 

Source
macro_rules! declare_plugin {
    (
        name: $name:literal,
        version: $version:literal,
        $(builtins: { $($cmd:literal => $handler:path),+ $(,)? } $(,)?)?
        $(completions: { $($ccmd:literal => $cgen:path),+ $(,)? } $(,)?)?
        $(compfns: { $($cfname:literal => $cfhandler:path),+ $(,)? } $(,)?)?
    ) => { ... };
}
Expand description

Declare a plugin: its identity, the builtins it registers, and the native completions it provides. Expands to the #[no_mangle] extern "C" fn znative_init the host looks for, plus the 'static PluginInfo.

  • builtins: — each "name" => handler registers a command. A handler is fn(&Host, &Args) -> c_int.
  • completions: — each "cmd" => generator wires a native completion into zsh’s completion system (compsys) for command cmd. A generator is also fn(&Host, &Args) -> c_int; it receives $CURRENT (1-based index of the word being completed) followed by every word on the line, and emits candidates with Host::add_match. (Requires compdef — load the plugin after compinit.)

Both sections are optional.

ⓘ
declare_plugin! {
    name: "greet",
    version: "0.1.0",
    builtins:    { "greet" => greet },
    completions: { "greet" => greet_complete },
}