From 59542504b41dfddb6f26524fb4ce811e0f22a785 Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Sun, 5 Mar 2023 01:47:30 +0900 Subject: docs(highlight): fix type annotations (#22272) --- runtime/lua/vim/highlight.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'runtime/lua/vim/highlight.lua') diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua index 20ad48dd27..89eae0def5 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -36,12 +36,12 @@ end --- Highlight range between two positions --- ----@param bufnr number of buffer to apply highlighting to ----@param ns namespace to add highlight to ----@param higroup highlight group to use for highlighting ----@param start first position (tuple {line,col}) ----@param finish second position (tuple {line,col}) ----@param opts table with options: +---@param bufnr integer Buffer number to apply highlighting to +---@param ns integer Namespace to add highlight to +---@param higroup string Highlight group to use for highlighting +---@param start { [1]: integer, [2]: integer } Start position {line, col} +---@param finish { [1]: integer, [2]: integer } Finish position {line, col} +---@param opts table|nil Optional parameters -- - regtype type of range (see |setreg()|, default charwise) -- - inclusive boolean indicating whether the range is end-inclusive (default false) -- - priority number indicating priority of highlight (default priorities.user) @@ -84,7 +84,7 @@ local yank_timer --- customize conditions (here: do not highlight a visual selection) via --- au TextYankPost * lua vim.highlight.on_yank {on_visual=false} --- --- @param opts table with options controlling the highlight: +-- @param opts table|nil Optional parameters -- - higroup highlight group for yanked region (default "IncSearch") -- - timeout time in ms before highlight is cleared (default 150) -- - on_macro highlight when executing macro (default false) -- cgit From c2f7f8d61c6436e1de13d921f13760fbdfe1d624 Mon Sep 17 00:00:00 2001 From: nullchilly Date: Sat, 11 Mar 2023 17:23:50 +0700 Subject: refactor(highlight)!: remove deprecated functions vim.highlight.create/link --- runtime/lua/vim/highlight.lua | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'runtime/lua/vim/highlight.lua') diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua index 89eae0def5..d71a806ea8 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -10,30 +10,6 @@ M.priorities = { user = 200, } ----@private -function M.create(higroup, hi_info, default) - vim.deprecate('vim.highlight.create', 'vim.api.nvim_set_hl', '0.9') - local options = {} - -- TODO: Add validation - for k, v in pairs(hi_info) do - table.insert(options, string.format('%s=%s', k, v)) - end - vim.cmd( - string.format( - [[highlight %s %s %s]], - default and 'default' or '', - higroup, - table.concat(options, ' ') - ) - ) -end - ----@private -function M.link(higroup, link_to, force) - vim.deprecate('vim.highlight.link', 'vim.api.nvim_set_hl', '0.9') - vim.cmd(string.format([[highlight%s link %s %s]], force and '!' or ' default', higroup, link_to)) -end - --- Highlight range between two positions --- ---@param bufnr integer Buffer number to apply highlighting to -- cgit From 9e86f473e0f4e21c5f40bf990c53194d593a0f9f Mon Sep 17 00:00:00 2001 From: NAKAI Tsuyoshi <82267684+uga-rosa@users.noreply.github.com> Date: Tue, 11 Apr 2023 23:28:46 +0900 Subject: feat(lua): vim.region accepts getpos() arg (#22635) --- runtime/lua/vim/highlight.lua | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'runtime/lua/vim/highlight.lua') diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua index d71a806ea8..a6cfcb730f 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -15,8 +15,8 @@ M.priorities = { ---@param bufnr integer Buffer number to apply highlighting to ---@param ns integer Namespace to add highlight to ---@param higroup string Highlight group to use for highlighting ----@param start { [1]: integer, [2]: integer } Start position {line, col} ----@param finish { [1]: integer, [2]: integer } Finish position {line, col} +---@param start integer[]|string Start of region as a (line, column) tuple or string accepted by |getpos()| +---@param finish integer[]|string End of region as a (line, column) tuple or string accepted by |getpos()| ---@param opts table|nil Optional parameters -- - regtype type of range (see |setreg()|, default charwise) -- - inclusive boolean indicating whether the range is end-inclusive (default false) @@ -27,11 +27,6 @@ function M.range(bufnr, ns, higroup, start, finish, opts) local inclusive = opts.inclusive or false local priority = opts.priority or M.priorities.user - -- sanity check - if start[2] < 0 or finish[1] < start[1] then - return - end - local region = vim.region(bufnr, start, finish, regtype, inclusive) for linenr, cols in pairs(region) do local end_row @@ -104,18 +99,12 @@ function M.on_yank(opts) yank_timer:close() end - local pos1 = vim.fn.getpos("'[") - local pos2 = vim.fn.getpos("']") - - pos1 = { pos1[2] - 1, pos1[3] - 1 + pos1[4] } - pos2 = { pos2[2] - 1, pos2[3] - 1 + pos2[4] } - M.range( bufnr, yank_ns, higroup, - pos1, - pos2, + "'[", + "']", { regtype = event.regtype, inclusive = event.inclusive, priority = M.priorities.user } ) -- cgit From 9248dd77ac58bd23721dc4e156e43ed5e9ada338 Mon Sep 17 00:00:00 2001 From: marcoSven Date: Sat, 6 May 2023 21:53:36 +0200 Subject: feat(lua): add hl priority opts on yank (#23509) feat(lua): add hl priority opts on_yank Signed-off-by: marcoSven --- runtime/lua/vim/highlight.lua | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'runtime/lua/vim/highlight.lua') diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua index a6cfcb730f..86e1adb49e 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -61,6 +61,7 @@ local yank_timer -- - on_macro highlight when executing macro (default false) -- - on_visual highlight when yanking visual selection (default true) -- - event event structure (default vim.v.event) +-- - priority integer priority (default |vim.highlight.priorities|`.user`) function M.on_yank(opts) vim.validate({ opts = { @@ -99,14 +100,11 @@ function M.on_yank(opts) yank_timer:close() end - M.range( - bufnr, - yank_ns, - higroup, - "'[", - "']", - { regtype = event.regtype, inclusive = event.inclusive, priority = M.priorities.user } - ) + M.range(bufnr, yank_ns, higroup, "'[", "']", { + regtype = event.regtype, + inclusive = event.inclusive, + priority = opts.priority or M.priorities.user, + }) yank_timer = vim.defer_fn(function() yank_timer = nil -- cgit From 0ac3c4d6314df5fe40571a83e157a425ab7ce16d Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 15 Jul 2023 16:55:32 +0100 Subject: docs(lua): move function docs to lua files --- runtime/lua/vim/highlight.lua | 65 ++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 19 deletions(-) (limited to 'runtime/lua/vim/highlight.lua') diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua index 86e1adb49e..97a5a1233f 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -1,3 +1,36 @@ +---@defgroup lua-highlight +--- +---@brief +---Nvim includes a function for highlighting a selection on yank. +--- +---To enable it, add the following to your `init.vim`: +---
vim
+---    au TextYankPost * silent! lua vim.highlight.on_yank()
+---
+--- +---You can customize the highlight group and the duration of +---the highlight via: +---
vim
+---    au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=150}
+---
+--- +---If you want to exclude visual selections from highlighting on yank, use: +---
vim
+---    au TextYankPost * silent! lua vim.highlight.on_yank {on_visual=false}
+---
+--- +---
help
+---vim.highlight.priorities                            *vim.highlight.priorities*
+---
+---    Table with default priorities used for highlighting:
+---        • `syntax`: `50`, used for standard syntax highlighting
+---        • `treesitter`: `100`, used for tree-sitter-based highlighting
+---        • `semantic_tokens`: `125`, used for LSP semantic token highlighting
+---        • `diagnostics`: `150`, used for code analysis such as diagnostics
+---        • `user`: `200`, used for user-triggered highlights such as LSP document
+---          symbols or `on_yank` autocommands
+---
+ local api = vim.api local M = {} @@ -10,7 +43,7 @@ M.priorities = { user = 200, } ---- Highlight range between two positions +--- Apply highlight group to range of text. --- ---@param bufnr integer Buffer number to apply highlighting to ---@param ns integer Namespace to add highlight to @@ -18,9 +51,9 @@ M.priorities = { ---@param start integer[]|string Start of region as a (line, column) tuple or string accepted by |getpos()| ---@param finish integer[]|string End of region as a (line, column) tuple or string accepted by |getpos()| ---@param opts table|nil Optional parameters --- - regtype type of range (see |setreg()|, default charwise) --- - inclusive boolean indicating whether the range is end-inclusive (default false) --- - priority number indicating priority of highlight (default priorities.user) +--- - regtype type of range (see |setreg()|, default charwise) +--- - inclusive boolean indicating whether the range is end-inclusive (default false) +--- - priority number indicating priority of highlight (default priorities.user) function M.range(bufnr, ns, higroup, start, finish, opts) opts = opts or {} local regtype = opts.regtype or 'v' @@ -46,22 +79,16 @@ end local yank_ns = api.nvim_create_namespace('hlyank') local yank_timer ---- Highlight the yanked region ---- ---- use from init.vim via ---- au TextYankPost * lua vim.highlight.on_yank() ---- customize highlight group and timeout via ---- au TextYankPost * lua vim.highlight.on_yank {higroup="IncSearch", timeout=150} ---- customize conditions (here: do not highlight a visual selection) via ---- au TextYankPost * lua vim.highlight.on_yank {on_visual=false} + +--- Highlight the yanked text --- --- @param opts table|nil Optional parameters --- - higroup highlight group for yanked region (default "IncSearch") --- - timeout time in ms before highlight is cleared (default 150) --- - on_macro highlight when executing macro (default false) --- - on_visual highlight when yanking visual selection (default true) --- - event event structure (default vim.v.event) --- - priority integer priority (default |vim.highlight.priorities|`.user`) +--- @param opts table|nil Optional parameters +--- - higroup highlight group for yanked region (default "IncSearch") +--- - timeout time in ms before highlight is cleared (default 150) +--- - on_macro highlight when executing macro (default false) +--- - on_visual highlight when yanking visual selection (default true) +--- - event event structure (default vim.v.event) +--- - priority integer priority (default |vim.highlight.priorities|`.user`) function M.on_yank(opts) vim.validate({ opts = { -- cgit From c2d7c2826ca77b0ca31bec511fdcdf1e4abaf946 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 17 Jul 2023 15:13:54 +0100 Subject: docs(lua): change *lua-foo* -> *vim.foo* --- runtime/lua/vim/highlight.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/highlight.lua') diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua index 97a5a1233f..0eb782339c 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -1,4 +1,4 @@ ----@defgroup lua-highlight +---@defgroup vim.highlight --- ---@brief ---Nvim includes a function for highlighting a selection on yank. -- cgit From be74807eef13ff8c90d55cf8b22b01d6d33b1641 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 18 Jul 2023 15:42:30 +0100 Subject: docs(lua): more improvements (#24387) * docs(lua): teach lua2dox how to table * docs(lua): teach gen_vimdoc.py about local functions No more need to mark local functions with @private * docs(lua): mention @nodoc and @meta in dev-lua-doc * fixup! Co-authored-by: Justin M. Keyes --------- Co-authored-by: Justin M. Keyes --- runtime/lua/vim/highlight.lua | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'runtime/lua/vim/highlight.lua') diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua index 0eb782339c..14b0e71312 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -18,23 +18,18 @@ ---
vim
 ---    au TextYankPost * silent! lua vim.highlight.on_yank {on_visual=false}
 ---
---- ----
help
----vim.highlight.priorities                            *vim.highlight.priorities*
----
----    Table with default priorities used for highlighting:
----        • `syntax`: `50`, used for standard syntax highlighting
----        • `treesitter`: `100`, used for tree-sitter-based highlighting
----        • `semantic_tokens`: `125`, used for LSP semantic token highlighting
----        • `diagnostics`: `150`, used for code analysis such as diagnostics
----        • `user`: `200`, used for user-triggered highlights such as LSP document
----          symbols or `on_yank` autocommands
----
local api = vim.api local M = {} +--- Table with default priorities used for highlighting: +--- - `syntax`: `50`, used for standard syntax highlighting +--- - `treesitter`: `100`, used for tree-sitter-based highlighting +--- - `semantic_tokens`: `125`, used for LSP semantic token highlighting +--- - `diagnostics`: `150`, used for code analysis such as diagnostics +--- - `user`: `200`, used for user-triggered highlights such as LSP document +--- symbols or `on_yank` autocommands M.priorities = { syntax = 50, treesitter = 100, -- cgit From b04286a187d57c50f01cd36cd4668b7a69026579 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 22 Nov 2020 10:10:37 +0100 Subject: feat(extmark): support proper multiline ranges The removes the previous restriction that nvim_buf_set_extmark() could not be used to highlight arbitrary multi-line regions The problem can be summarized as follows: let's assume an extmark with a hl_group is placed covering the region (5,0) to (50,0) Now, consider what happens if nvim needs to redraw a window covering the lines 20-30. It needs to be able to ask the marktree what extmarks cover this region, even if they don't begin or end here. Therefore the marktree needs to be augmented with the information covers a point, not just what marks begin or end there. To do this, we augment each node with a field "intersect" which is a set the ids of the marks which overlap this node, but only if it is not part of the set of any parent. This ensures the number of nodes that need to be explicitly marked grows only logarithmically with the total number of explicitly nodes (and thus the number of of overlapping marks). Thus we can quickly iterate all marks which overlaps any query position by looking up what leaf node contains that position. Then we only need to consider all "start" marks within that leaf node, and the "intersect" set of that node and all its parents. Now, and the major source of complexity is that the tree restructuring operations (to ensure that each node has T-1 <= size <= 2*T-1) also need to update these sets. If a full inner node is split in two, one of the new parents might start to completely overlap some ranges and its ids will need to be moved from its children's sets to its own set. Similarly, if two undersized nodes gets joined into one, it might no longer completely overlap some ranges, and now the children which do needs to have the have the ids in its set instead. And then there are the pivots! Yes the pivot operations when a child gets moved from one parent to another. --- runtime/lua/vim/highlight.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'runtime/lua/vim/highlight.lua') diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua index 14b0e71312..fd4fb54a5b 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -55,6 +55,9 @@ function M.range(bufnr, ns, higroup, start, finish, opts) local inclusive = opts.inclusive or false local priority = opts.priority or M.priorities.user + -- TODO: in case of 'v', 'V' (not block), this should calculate equivalent + -- bounds (row, col, end_row, end_col) as multiline regions are natively + -- supported now local region = vim.region(bufnr, start, finish, regtype, inclusive) for linenr, cols in pairs(region) do local end_row -- cgit From 2e92065686f62851318150a315591c30b8306a4b Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Thu, 14 Sep 2023 08:23:01 -0500 Subject: docs: replace
 with ``` (#25136)

---
 runtime/lua/vim/highlight.lua | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

(limited to 'runtime/lua/vim/highlight.lua')

diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua
index fd4fb54a5b..fc2fd43c97 100644
--- a/runtime/lua/vim/highlight.lua
+++ b/runtime/lua/vim/highlight.lua
@@ -1,23 +1,24 @@
 ---@defgroup vim.highlight
 ---
----@brief
----Nvim includes a function for highlighting a selection on yank.
+--- Nvim includes a function for highlighting a selection on yank.
 ---
----To enable it, add the following to your `init.vim`:
----
vim
----    au TextYankPost * silent! lua vim.highlight.on_yank()
----
+--- To enable it, add the following to your `init.vim`: --- ----You can customize the highlight group and the duration of ----the highlight via: ----
vim
----    au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=150}
----
+--- ```vim +--- au TextYankPost * silent! lua vim.highlight.on_yank() +--- ``` --- ----If you want to exclude visual selections from highlighting on yank, use: ----
vim
----    au TextYankPost * silent! lua vim.highlight.on_yank {on_visual=false}
----
+--- You can customize the highlight group and the duration of the highlight via: +--- +--- ```vim +--- au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=150} +--- ``` +--- +--- If you want to exclude visual selections from highlighting on yank, use: +--- +--- ```vim +--- au TextYankPost * silent! lua vim.highlight.on_yank {on_visual=false} +--- ``` local api = vim.api -- cgit