Skip to main content
Module

x/denops_std/function/vim/mod.ts>state

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

Return a string which contains characters indicating the current state. Mostly useful in callbacks that want to do work that may not always be safe. Roughly this works like:

  • callback uses state() to check if work is safe to do. Yes: then do it right away. No: add to work queue and add a SafeState and/or SafeStateAgain autocommand (SafeState triggers at toplevel, SafeStateAgain triggers after handling messages and callbacks).
  • When SafeState or SafeStateAgain is triggered and executes your autocommand, check with state() if the work can be done now, and if yes remove it from the queue and execute. Remove the autocommand if the queue is now empty. Also see mode().

When {what} is given only characters in this string will be added. E.g, this checks if the screen has scrolled:

if state('s') == ''
   " screen has not scrolled

These characters indicate the state, generally indicating that something is busy: m halfway a mapping, :normal command, feedkeys() or stuffed command o operator pending, e.g. after d a Insert mode autocomplete active x executing an autocommand w blocked on waiting, e.g. ch_evalexpr(), ch_read() and ch_readraw() when reading json S not triggering SafeState or SafeStateAgain, e.g. after f or a count c callback invoked, including timer (repeats for recursiveness up to "ccc") s screen has scrolled for messages

Parameters

denops: Denops
optional
what: unknown

Returns

Promise<string>