Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/denops_std/function/nvim/mod.ts>dictwatcheradd

📚 Standard module for denops.vim
Go to Latest
function dictwatcheradd
import { dictwatcheradd } from "https://deno.land/x/denops_std@v3.6.0/function/nvim/mod.ts";

Adds a watcher to a dictionary. A dictionary watcher is identified by three components:

  • A dictionary({dict});
  • A key pattern({pattern}).
  • A function({callback}). After this is called, every change on {dict} and on keys matching {pattern} will result in {callback} being invoked. For example, to watch all global variables: silent! call dictwatcherdel(g:, '', 'OnDictChanged') function! OnDictChanged(d,k,z) echomsg string(a:k) string(a:z) endfunction call dictwatcheradd(g:, '', 'OnDictChanged') For now {pattern} only accepts very simple patterns that can contain a '' at the end of the string, in which case it will match every key that begins with the substring before the ''. That means if '*' is not the last character of {pattern}, only keys that are exactly equal as {pattern} will be matched. The {callback} receives three arguments:
  • The dictionary being watched.
  • The key which changed.
  • A dictionary containing the new and old values for the key. The type of change can be determined by examining the keys present on the third argument:
  • If contains both old and new, the key was updated.
  • If it contains only new, the key was added.
  • If it contains only old, the key was deleted. This function can be used by plugins to implement options with validation and parsing logic.

Parameters

denops: Denops
dict: unknown
pattern: unknown
callback: unknown

Returns

Promise<unknown>