Home Explore Blog CI



neovim

41th chunk of `runtime/doc/api.txt`
4f87a7e0a10dfeea7e6589552d23582be73421efdea802a70000000100000fbe
                   *nvim_set_decoration_provider()*
nvim_set_decoration_provider({ns_id}, {opts})
    Set or change decoration provider for a |namespace|

    This is a very general purpose interface for having Lua callbacks being
    triggered during the redraw code.

    The expected usage is to set |extmarks| for the currently redrawn buffer.
    |nvim_buf_set_extmark()| can be called to add marks on a per-window or
    per-lines basis. Use the `ephemeral` key to only use the mark for the
    current screen redraw (the callback will be called again for the next
    redraw).

    Note: this function should not be called often. Rather, the callbacks
    themselves can be used to throttle unneeded callbacks. the `on_start`
    callback can return `false` to disable the provider until the next redraw.
    Similarly, return `false` in `on_win` will skip the `on_line` calls for
    that window (but any extmarks set in `on_win` will still be used). A
    plugin managing multiple sources of decoration should ideally only set one
    provider, and merge the sources internally. You can use multiple `ns_id`
    for the extmarks set/modified inside the callback anyway.

    Note: doing anything other than setting extmarks is considered
    experimental. Doing things like changing options are not explicitly
    forbidden, but is likely to have unexpected consequences (such as 100% CPU
    consumption). Doing `vim.rpcnotify` should be OK, but `vim.rpcrequest` is
    quite dubious for the moment.

    Note: It is not allowed to remove or update extmarks in `on_line`
    callbacks.

    Attributes: ~
        Lua |vim.api| only
        Since: 0.5.0

    Parameters: ~
      • {ns_id}  Namespace id from |nvim_create_namespace()|
      • {opts}   Table of callbacks:
                 • on_start: called first on each screen redraw >
                    ["start", tick]
<
                 • on_buf: called for each buffer being redrawn (once per
                   edit, before window callbacks) >
                    ["buf", bufnr, tick]
<
                 • on_win: called when starting to redraw a specific window. >
                    ["win", winid, bufnr, toprow, botrow]
<
                 • on_line: called for each buffer line being redrawn. (The
                   interaction with fold lines is subject to change) >
                    ["line", winid, bufnr, row]
<
                 • on_end: called at the end of a redraw cycle >
                    ["end", tick]
<

nvim__ns_get({ns_id})                                         *nvim__ns_get()*
    EXPERIMENTAL: this API will change in the future.

    Get the properties for namespace

    Parameters: ~
      • {ns_id}  Namespace

    Return: ~
        Map defining the namespace properties, see |nvim__ns_set()|

nvim__ns_set({ns_id}, {opts})                                 *nvim__ns_set()*
    EXPERIMENTAL: this API will change in the future.

    Set some properties for namespace

    Parameters: ~
      • {ns_id}  Namespace
      • {opts}   Optional parameters to set:
                 • wins: a list of windows to be scoped in


==============================================================================
Window Functions                                                  *api-window*

nvim_win_call({window}, {fun})                               *nvim_win_call()*
    Calls a function with window as temporary current window.

    Attributes: ~
        Lua |vim.api| only
        Since: 0.5.0

    Parameters: ~
      • {window}  |window-ID|, or 0 for current window
      • {fun}     Function to call inside the window (currently Lua callable
                  only)

    Return: ~
        Return value of function.

    See also: ~
      • |win_execute()|
      • |nvim_buf_call()|

nvim_win_close({window}, {force})                           *nvim_win_close()*
    Closes the window (like |:close| with a |window-ID|).

    Attributes: ~
        not allowed when |textlock| is active
        Since: 0.4.0

 

Title: nvim_set_decoration_provider Details, Namespace Properties, and Window Functions
Summary
This section delves deeper into `nvim_set_decoration_provider`, elaborating on its Lua callback interface for customizing redraws. It emphasizes using it for setting extmarks with `nvim_buf_set_extmark`, and throttling callbacks for performance. It cautions against using this function for anything other than setting extmarks, as it is experimental and might cause problems. Also, it mentions that it's not allowed to remove or update extmarks in `on_line` callbacks. The description lists the callbacks available in the options table (on_start, on_buf, on_win, on_line, on_end). It also covers experimental functions for getting and setting namespace properties (`nvim__ns_get`, `nvim__ns_set`). Finally, it introduces window functions like `nvim_win_call` for executing functions within a window context and `nvim_win_close` for closing a window.