Home Explore Blog CI



neovim

28th chunk of `runtime/doc/lua.txt`
4989ed8f16e5eb576a36347b394cf0aa3df33a0e262117d50000000100000fce
 Parameters: ~
      • {f}  (`any`) Any object

    Return: ~
        (`boolean`) `true` if `f` is callable, else `false`

vim.isarray({t})                                               *vim.isarray()*
    Tests if `t` is an "array": a table indexed only by integers (potentially
    non-contiguous).

    If the indexes start from 1 and are contiguous then the array is also a
    list. |vim.islist()|

    Empty table `{}` is an array, unless it was created by |vim.empty_dict()|
    or returned as a dict-like |API| or Vimscript result, for example from
    |rpcrequest()| or |vim.fn|.

    Parameters: ~
      • {t}  (`table?`)

    Return: ~
        (`boolean`) `true` if array-like table, else `false`.

    See also: ~
      • https://github.com/openresty/luajit2#tableisarray

vim.islist({t})                                                 *vim.islist()*
    Tests if `t` is a "list": a table indexed only by contiguous integers
    starting from 1 (what |lua-length| calls a "regular array").

    Empty table `{}` is a list, unless it was created by |vim.empty_dict()| or
    returned as a dict-like |API| or Vimscript result, for example from
    |rpcrequest()| or |vim.fn|.

    Parameters: ~
      • {t}  (`table?`)

    Return: ~
        (`boolean`) `true` if list-like table, else `false`.

    See also: ~
      • |vim.isarray()|

vim.list_contains({t}, {value})                          *vim.list_contains()*
    Checks if a list-like table (integer keys without gaps) contains `value`.

    Parameters: ~
      • {t}      (`table`) Table to check (must be list-like, not validated)
      • {value}  (`any`) Value to compare

    Return: ~
        (`boolean`) `true` if `t` contains `value`

    See also: ~
      • |vim.tbl_contains()| for checking values in general tables

vim.list_extend({dst}, {src}, {start}, {finish})           *vim.list_extend()*
    Extends a list-like table with the values of another list-like table.

    NOTE: This mutates dst!

    Parameters: ~
      • {dst}     (`table`) List which will be modified and appended to
      • {src}     (`table`) List from which values will be inserted
      • {start}   (`integer?`) Start index on src. Defaults to 1
      • {finish}  (`integer?`) Final index on src. Defaults to `#src`

    Return: ~
        (`table`) dst

    See also: ~
      • |vim.tbl_extend()|

vim.list_slice({list}, {start}, {finish})                   *vim.list_slice()*
    Creates a copy of a table containing only elements from start to end
    (inclusive)

    Parameters: ~
      • {list}    (`any[]`) Table
      • {start}   (`integer?`) Start range of slice
      • {finish}  (`integer?`) End range of slice

    Return: ~
        (`any[]`) Copy of table sliced from start to finish (inclusive)

vim.pesc({s})                                                     *vim.pesc()*
    Escapes magic chars in |lua-pattern|s.

    Parameters: ~
      • {s}  (`string`) String to escape

    Return: ~
        (`string`) %-escaped pattern string

    See also: ~
      • https://github.com/rxi/lume

vim.ringbuf({size})                                            *vim.ringbuf()*
    Create a ring buffer limited to a maximal number of items. Once the buffer
    is full, adding a new entry overrides the oldest entry. >lua
        local ringbuf = vim.ringbuf(4)
        ringbuf:push("a")
        ringbuf:push("b")
        ringbuf:push("c")
        ringbuf:push("d")
        ringbuf:push("e")    -- overrides "a"
        print(ringbuf:pop()) -- returns "b"
        print(ringbuf:pop()) -- returns "c"

        -- Can be used as iterator. Pops remaining items:
        for val in ringbuf do
          print(val)
        end
<

    Returns a Ringbuf instance with the following methods:
    • |Ringbuf:push()|
    • |Ringbuf:pop()|
    • |Ringbuf:peek()|
    • |Ringbuf:clear()|

    Parameters: ~
      • {size}  (`integer`)

    Return: ~
        (`vim.Ringbuf`) ringbuf See |vim.Ringbuf|.

vim.spairs({t})                                     

Title: Lua API: vim.islist(), vim.list_contains(), vim.list_extend(), vim.list_slice(), vim.pesc(), vim.ringbuf(), vim.spairs()
Summary
This section covers several more functions within the Neovim Lua API. These include `vim.islist()` for checking if a table is a list; `vim.list_contains()` which checks if a list-like table contains a specific value; `vim.list_extend()` to extend a list with values from another list; `vim.list_slice()` which creates a copy of a table with elements within a specified range; `vim.pesc()` which escapes magic characters in Lua patterns; and `vim.ringbuf()` to create a ring buffer with a limited size. The last function, `vim.spairs()`, is not described in the provided text.