Skip to main content
Module

x/denops_std/popup/mod.ts

📚 Standard module for denops.vim
Go to Latest
import * as denopsStd from "https://deno.land/x/denops_std@v6.4.0/popup/mod.ts";

A module to provide compatibility layer for popup window in Vim and Neovim.

import type { Denops } from "https://deno.land/x/denops_std@v6.4.0/mod.ts";
import * as buffer from "https://deno.land/x/denops_std@v6.4.0/buffer/mod.ts";
import * as fn from "https://deno.land/x/denops_std@v6.4.0/function/mod.ts";
import * as popup from "https://deno.land/x/denops_std@v6.4.0/popup/mod.ts";

export async function main(denops: Denops): Promise<void> {
  // Create a new buffer
  const bufnr = await fn.bufadd(denops, "");
  await fn.bufload(denops, bufnr);

  // Write some text to the buffer
  await buffer.replace(denops, bufnr, ["Hello, world!"]);

  // Open a popup window showing the buffer
  const popupWindow = await popup.open(denops, {
    bufnr,
    relative: "editor",
    width: 20,
    height: 20,
    row: 1,
    col: 1,
  });

  // Config a popup window
  await popup.config(denops, popupWindow.winid, {
    title: "Hello, world!",
  });

  // Wiat 3 seconds
  await new Promise((resolve) => setTimeout(resolve, 3000));

  // Close the popup window
  await popupWindow.close();
}

Or with await using statement:

import type { Denops } from "https://deno.land/x/denops_std@v6.4.0/mod.ts";
import * as buffer from "https://deno.land/x/denops_std@v6.4.0/buffer/mod.ts";
import * as fn from "https://deno.land/x/denops_std@v6.4.0/function/mod.ts";
import * as popup from "https://deno.land/x/denops_std@v6.4.0/popup/mod.ts";

export async function main(denops: Denops): Promise<void> {
  // Create a new buffer
  const bufnr = await fn.bufadd(denops, "");
  await fn.bufload(denops, bufnr);

  // Write some text to the buffer
  await buffer.replace(denops, bufnr, ["Hello, world!"]);

  // Open a popup window showing the buffer
  await using popupWindow = await popup.open(denops, {
    bufnr,
    relative: "editor",
    width: 20,
    height: 20,
    row: 1,
    col: 1,
  });

  // Wiat 3 seconds
  await new Promise((resolve) => setTimeout(resolve, 3000));

  // The popup window is automatically closed, due to `await using` statement
}

Note that this module does NOT work with batch.collect().

Functions

Config a popup window in Vim/Neovim compatible way.

Open a popup window showing the buffer in Vim/Neovim compatible way.