aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_meta/api.lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/_meta/api.lua')
-rw-r--r--runtime/lua/vim/_meta/api.lua121
1 files changed, 84 insertions, 37 deletions
diff --git a/runtime/lua/vim/_meta/api.lua b/runtime/lua/vim/_meta/api.lua
index dd67fdb38b..6573c68493 100644
--- a/runtime/lua/vim/_meta/api.lua
+++ b/runtime/lua/vim/_meta/api.lua
@@ -7,6 +7,13 @@ vim.api = {}
--- @private
--- @param buffer integer
+--- @param keys boolean
+--- @param dot boolean
+--- @return string
+function vim.api.nvim__buf_debug_extmarks(buffer, keys, dot) end
+
+--- @private
+--- @param buffer integer
--- @param first integer
--- @param last integer
function vim.api.nvim__buf_redraw_range(buffer, first, last) end
@@ -120,11 +127,16 @@ function vim.api.nvim__unpack(str) end
function vim.api.nvim_buf_add_highlight(buffer, ns_id, hl_group, line, col_start, col_end) end
--- Activates buffer-update events on a channel, or as Lua callbacks.
---- Example (Lua): capture buffer updates in a global `events` variable (use "vim.print(events)" to see its contents):
+--- Example (Lua): capture buffer updates in a global `events` variable (use
+--- "vim.print(events)" to see its contents):
+---
--- ```lua
---- events = {}
---- vim.api.nvim_buf_attach(0, false, {
---- on_lines=function(...) table.insert(events, {...}) end})
+--- events = {}
+--- vim.api.nvim_buf_attach(0, false, {
+--- on_lines = function(...)
+--- table.insert(events, {...})
+--- end,
+--- })
--- ```
---
--- @param buffer integer Buffer handle, or 0 for current buffer
@@ -307,26 +319,32 @@ function vim.api.nvim_buf_get_extmark_by_id(buffer, ns_id, id, opts) end
--- Region can be given as (row,col) tuples, or valid extmark ids (whose
--- positions define the bounds). 0 and -1 are understood as (0,0) and (-1,-1)
--- respectively, thus the following are equivalent:
+---
--- ```lua
---- vim.api.nvim_buf_get_extmarks(0, my_ns, 0, -1, {})
---- vim.api.nvim_buf_get_extmarks(0, my_ns, {0,0}, {-1,-1}, {})
+--- vim.api.nvim_buf_get_extmarks(0, my_ns, 0, -1, {})
+--- vim.api.nvim_buf_get_extmarks(0, my_ns, {0,0}, {-1,-1}, {})
--- ```
+---
--- If `end` is less than `start`, traversal works backwards. (Useful with
--- `limit`, to get the first marks prior to a given position.)
+--- Note: when using extmark ranges (marks with a end_row/end_col position)
+--- the `overlap` option might be useful. Otherwise only the start position of
+--- an extmark will be considered.
--- Example:
+---
--- ```lua
---- local api = vim.api
---- local pos = api.nvim_win_get_cursor(0)
---- local ns = api.nvim_create_namespace('my-plugin')
---- -- Create new extmark at line 1, column 1.
---- local m1 = api.nvim_buf_set_extmark(0, ns, 0, 0, {})
---- -- Create new extmark at line 3, column 1.
---- local m2 = api.nvim_buf_set_extmark(0, ns, 2, 0, {})
---- -- Get extmarks only from line 3.
---- local ms = api.nvim_buf_get_extmarks(0, ns, {2,0}, {2,0}, {})
---- -- Get all marks in this buffer + namespace.
---- local all = api.nvim_buf_get_extmarks(0, ns, 0, -1, {})
---- vim.print(ms)
+--- local api = vim.api
+--- local pos = api.nvim_win_get_cursor(0)
+--- local ns = api.nvim_create_namespace('my-plugin')
+--- -- Create new extmark at line 1, column 1.
+--- local m1 = api.nvim_buf_set_extmark(0, ns, 0, 0, {})
+--- -- Create new extmark at line 3, column 1.
+--- local m2 = api.nvim_buf_set_extmark(0, ns, 2, 0, {})
+--- -- Get extmarks only from line 3.
+--- local ms = api.nvim_buf_get_extmarks(0, ns, {2,0}, {2,0}, {})
+--- -- Get all marks in this buffer + namespace.
+--- local all = api.nvim_buf_get_extmarks(0, ns, 0, -1, {})
+--- vim.print(ms)
--- ```
---
--- @param buffer integer Buffer handle, or 0 for current buffer
@@ -337,11 +355,13 @@ function vim.api.nvim_buf_get_extmark_by_id(buffer, ns_id, id, opts) end
--- @param end_ any End of range (inclusive): a 0-indexed (row, col) or valid
--- extmark id (whose position defines the bound).
--- `api-indexing`
---- @param opts table<string,any> Optional parameters. Keys:
+--- @param opts vim.api.keyset.get_extmarks Optional parameters. Keys:
--- • limit: Maximum number of marks to return
--- • details: Whether to include the details dict
--- • hl_name: Whether to include highlight group name instead
--- of id, true if omitted
+--- • overlap: Also include marks which overlap the range, even
+--- if their start position is less than `start`
--- • type: Filter marks by type: "highlight", "sign",
--- "virt_text" and "virt_lines"
--- @return any[]
@@ -457,6 +477,10 @@ function vim.api.nvim_buf_line_count(buffer) end
--- waiting for the return value.)
--- Using the optional arguments, it is possible to use this to highlight a
--- range of text, and also to associate virtual text to the mark.
+--- If present, the position defined by `end_col` and `end_row` should be
+--- after the start position in order for the extmark to cover a range. An
+--- earlier end position is not an error, but then it behaves like an empty
+--- range (no highlighting).
---
--- @param buffer integer Buffer handle, or 0 for current buffer
--- @param ns_id integer Namespace id from `nvim_create_namespace()`
@@ -621,6 +645,7 @@ function vim.api.nvim_buf_set_option(buffer, name, value) end
--- range, use `replacement = {}`.
--- Prefer `nvim_buf_set_lines()` if you are only adding or deleting entire
--- lines.
+--- Prefer `nvim_put()` if you want to insert text at the cursor position.
---
--- @param buffer integer Buffer handle, or 0 for current buffer
--- @param start_row integer First line index
@@ -758,6 +783,7 @@ function vim.api.nvim_command_output(command) end
--- Create or get an autocommand group `autocmd-groups`.
--- To get an existing group id, do:
+---
--- ```lua
--- local id = vim.api.nvim_create_augroup("MyGroup", {
--- clear = false
@@ -773,6 +799,7 @@ function vim.api.nvim_create_augroup(name, opts) end
--- Creates an `autocommand` event handler, defined by `callback` (Lua function or Vimscript function name string) or `command` (Ex command string).
--- Example using Lua callback:
+---
--- ```lua
--- vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
--- pattern = {"*.c", "*.h"},
@@ -781,17 +808,21 @@ function vim.api.nvim_create_augroup(name, opts) end
--- end
--- })
--- ```
+---
--- Example using an Ex command as the handler:
+---
--- ```lua
--- vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
--- pattern = {"*.c", "*.h"},
--- command = "echo 'Entering a C or C++ file'",
--- })
--- ```
---- Note: `pattern` is NOT automatically expanded (unlike with `:autocmd`), thus names like
---- "$HOME" and "~" must be expanded explicitly:
+---
+--- Note: `pattern` is NOT automatically expanded (unlike with `:autocmd`),
+--- thus names like "$HOME" and "~" must be expanded explicitly:
+---
--- ```lua
---- pattern = vim.fn.expand("~") .. "/some/path/*.py"
+--- pattern = vim.fn.expand("~") .. "/some/path/*.py"
--- ```
---
--- @param event any (string|array) Event(s) that will trigger the handler
@@ -853,10 +884,11 @@ function vim.api.nvim_create_namespace(name) end
--- Creates a global `user-commands` command.
--- For Lua usage see `lua-guide-commands-create`.
--- Example:
+---
--- ```vim
---- :call nvim_create_user_command('SayHello', 'echo "Hello world!"', {'bang': v:true})
---- :SayHello
---- Hello world!
+--- :call nvim_create_user_command('SayHello', 'echo "Hello world!"', {'bang': v:true})
+--- :SayHello
+--- Hello world!
--- ```
---
--- @param name string Name of the new user command. Must begin with an uppercase
@@ -1067,6 +1099,7 @@ function vim.api.nvim_execute_lua(code, args) end
--- with escape_ks=false) to replace `keycodes`, then pass the result to
--- nvim_feedkeys().
--- Example:
+---
--- ```vim
--- :let key = nvim_replace_termcodes("<C-o>", v:true, v:false, v:true)
--- :call nvim_feedkeys(key, 'n', v:false)
@@ -1094,19 +1127,21 @@ function vim.api.nvim_get_api_info() end
--- Get all autocommands that match the corresponding {opts}.
--- These examples will get autocommands matching ALL the given criteria:
+---
--- ```lua
---- -- Matches all criteria
---- autocommands = vim.api.nvim_get_autocmds({
---- group = "MyGroup",
---- event = {"BufEnter", "BufWinEnter"},
---- pattern = {"*.c", "*.h"}
---- })
----
---- -- All commands from one group
---- autocommands = vim.api.nvim_get_autocmds({
---- group = "MyGroup",
---- })
+--- -- Matches all criteria
+--- autocommands = vim.api.nvim_get_autocmds({
+--- group = "MyGroup",
+--- event = {"BufEnter", "BufWinEnter"},
+--- pattern = {"*.c", "*.h"}
+--- })
+---
+--- -- All commands from one group
+--- autocommands = vim.api.nvim_get_autocmds({
+--- group = "MyGroup",
+--- })
--- ```
+---
--- NOTE: When multiple patterns or events are provided, it will find all the
--- autocommands that match any combination of them.
---
@@ -1132,6 +1167,7 @@ function vim.api.nvim_get_chan_info(chan) end
--- Returns the 24-bit RGB value of a `nvim_get_color_map()` color name or
--- "#rrggbb" hexadecimal string.
--- Example:
+---
--- ```vim
--- :echo nvim_get_color_by_name("Pink")
--- :echo nvim_get_color_by_name("#cbcbcb")
@@ -1193,6 +1229,8 @@ function vim.api.nvim_get_current_win() end
--- • id: (integer) Get a highlight definition by id.
--- • link: (boolean, default true) Show linked group name
--- instead of effective definition `:hi-link`.
+--- • create: (boolean, default true) When highlight group
+--- doesn't exist create it.
--- @return table<string,any>
function vim.api.nvim_get_hl(ns_id, opts) end
@@ -1452,14 +1490,18 @@ function vim.api.nvim_open_term(buffer, opts) end
--- could let floats hover outside of the main window like a tooltip, but this
--- should not be used to specify arbitrary WM screen positions.
--- Example (Lua): window-relative float
+---
--- ```lua
--- vim.api.nvim_open_win(0, false,
--- {relative='win', row=3, col=3, width=12, height=3})
--- ```
+---
--- Example (Lua): buffer-relative float (travels as buffer is scrolled)
+---
--- ```lua
--- vim.api.nvim_open_win(0, false,
--- {relative='win', width=12, height=3, bufpos={100,10}})
+--- })
--- ```
---
--- @param buffer integer Buffer to display, or 0 for current buffer
@@ -1774,7 +1816,9 @@ function vim.api.nvim_set_current_win(window) end
--- • on_buf: called for each buffer being redrawn (before window
--- callbacks) ["buf", bufnr, tick]
--- • on_win: called when starting to redraw a specific window.
---- ["win", winid, bufnr, topline, botline_guess]
+--- botline_guess is an approximation that does not exceed the
+--- last line number. ["win", winid, bufnr, topline,
+--- botline_guess]
--- • on_line: called for each buffer line being redrawn. (The
--- interaction with fold lines is subject to change) ["win",
--- winid, bufnr, row]
@@ -1835,10 +1879,13 @@ function vim.api.nvim_set_hl_ns_fast(ns_id) end
--- Unlike `:map`, leading/trailing whitespace is accepted as part of the
--- {lhs} or {rhs}. Empty {rhs} is `<Nop>`. `keycodes` are replaced as usual.
--- Example:
+---
--- ```vim
--- call nvim_set_keymap('n', ' <NL>', '', {'nowait': v:true})
--- ```
+---
--- is equivalent to:
+---
--- ```vim
--- nmap <nowait> <Space><NL> <Nop>
--- ```