Skip to main content
Module

x/denops_std/lambda/mod.ts>register

📚 Standard module for denops.vim
Go to Latest
function register
import { register } from "https://deno.land/x/denops_std@v6.0.0/lambda/mod.ts";

Register a lambda function as a denops API and return the identifier.

import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
import * as lambda from "https://deno.land/x/denops_std@v6.0.0/lambda/mod.ts";

export async function main(denops: Denops): Promise<void> {
  // Add lambda function
  const id = lambda.register(
    denops,
    () => {
      // Do what ever you want.
    },
  );

  // Use id to dispatch added function from Deno
  await denops.dispatch(denops.name, id);

  // Or from Vim
  await denops.cmd("call denops#notify(name, id, [])", {
    name: denops.name,
    id,
  });
}

If you need an one-time lambda function, use once option like

import type { Denops } from "https://deno.land/x/denops_std@v6.0.0/mod.ts";
import * as lambda from "https://deno.land/x/denops_std@v6.0.0/lambda/mod.ts";

export async function main(denops: Denops): Promise<void> {
  // Add lambda function
  const id = lambda.register(
    denops,
    () => {
      // Do what ever you want.
    },
    {
      once: true,
    },
  );

  // Use id to dispatch added function from Deno
  await denops.dispatch(denops.name, id);

  // Second call would throw error
  await denops.dispatch(denops.name, id);
}

Parameters

denops: Denops
fn: Fn
optional
options: Options = [UNSUPPORTED]