Skip to main content
Module

x/denops_std/buffer/buffer.ts>ensure

📚 Standard module for denops.vim
Go to Latest
function ensure
import { ensure } from "https://deno.land/x/denops_std@v4.1.4/buffer/buffer.ts";

Ensure the executor is executed under the specified buffer

import { Denops } from "../mod.ts";
import * as option from "../option/mod.ts";
import * as fn from "../function/mod.ts";
import { ensure, open } from "../buffer/mod.ts";

export async function main(denops: Denops): Promise<void> {
  await open(denops, "README.md");
  const bufnr = (await fn.bufnr(denops)) as number;
  // ...
  await ensure(denops, bufnr, async () => {
    await option.buftype.set(denops, "nofile");
    await option.swapfile.set(denops, false);
    await fn.setline(denops, 1, ["Hello", "World"]);
  });
}

Note that it's better to use setbufvar or whatever instead. It's mainly designed to define mappings that is not possible from outside of the buffer.

Parameters

denops: Denops
bufnr: number
executor: () => T

Returns

Promise<T>