From 5b1b765610ae12ebd6400aafd068903569ee441a Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Sun, 28 Jan 2024 20:53:14 -0500 Subject: docs: enforce "treesitter" spelling #27110 It's the "tree-sitter" project, but "treesitter" in our code and docs. --- 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 fc2fd43c97..1d04f95d2d 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -26,7 +26,7 @@ local M = {} --- Table with default priorities used for highlighting: --- - `syntax`: `50`, used for standard syntax highlighting ---- - `treesitter`: `100`, used for tree-sitter-based highlighting +--- - `treesitter`: `100`, used for treesitter-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 -- cgit From e2e63bd045491f36e12c924fddbe76b3ef884b38 Mon Sep 17 00:00:00 2001 From: altermo <107814000+altermo@users.noreply.github.com> Date: Thu, 22 Feb 2024 09:39:32 +0100 Subject: fix(lua): make highlight.on_yank use win-local highlight (#27349) Currently, highlight.on_yank() does buffer-local highlighting, this PR makes it window scoped. Also fix the problem that when yanking in a buffer, moving to another buffer, and yanking before the original buffer highlight disappears, the original buffer highlight won't disappear on timeout. --- runtime/lua/vim/highlight.lua | 22 +++++++++++++++------- 1 file changed, 15 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 1d04f95d2d..b055cce49d 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -55,6 +55,7 @@ function M.range(bufnr, ns, higroup, start, finish, opts) local regtype = opts.regtype or 'v' local inclusive = opts.inclusive or false local priority = opts.priority or M.priorities.user + local scoped = opts._scoped or false -- TODO: in case of 'v', 'V' (not block), this should calculate equivalent -- bounds (row, col, end_row, end_col) as multiline regions are natively @@ -72,12 +73,14 @@ function M.range(bufnr, ns, higroup, start, finish, opts) end_col = cols[2], priority = priority, strict = false, + scoped = scoped, }) end end local yank_ns = api.nvim_create_namespace('hlyank') local yank_timer +local yank_cancel --- Highlight the yanked text --- @@ -120,24 +123,29 @@ function M.on_yank(opts) local higroup = opts.higroup or 'IncSearch' local timeout = opts.timeout or 150 - local bufnr = api.nvim_get_current_buf() - api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1) + local bufnr = vim.api.nvim_get_current_buf() + local winid = vim.api.nvim_get_current_win() if yank_timer then yank_timer:close() + yank_cancel() end M.range(bufnr, yank_ns, higroup, "'[", "']", { regtype = event.regtype, inclusive = event.inclusive, priority = opts.priority or M.priorities.user, + _scoped = true, }) + vim.api.nvim_win_add_ns(winid, yank_ns) - yank_timer = vim.defer_fn(function() + yank_cancel = function() yank_timer = nil - if api.nvim_buf_is_valid(bufnr) then - api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1) - end - end, timeout) + yank_cancel = nil + pcall(vim.api.nvim_buf_clear_namespace, bufnr, yank_ns, 0, -1) + pcall(vim.api.nvim_win_remove_ns, winid, yank_ns) + end + + yank_timer = vim.defer_fn(yank_cancel, timeout) end return M -- cgit From 9beb40a4db5613601fc1a4b828a44e5977eca046 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 15 Feb 2024 17:16:04 +0000 Subject: feat(docs): replace lua2dox.lua Problem: The documentation flow (`gen_vimdoc.py`) has several issues: - it's not very versatile - depends on doxygen - doesn't work well with Lua code as it requires an awkward filter script to convert it into pseudo-C. - The intermediate XML files and filters makes it too much like a rube goldberg machine. Solution: Re-implement the flow using Lua, LPEG and treesitter. - `gen_vimdoc.py` is now replaced with `gen_vimdoc.lua` and replicates a portion of the logic. - `lua2dox.lua` is gone! - No more XML files. - Doxygen is now longer used and instead we now use: - LPEG for comment parsing (see `scripts/luacats_grammar.lua` and `scripts/cdoc_grammar.lua`). - LPEG for C parsing (see `scripts/cdoc_parser.lua`) - Lua patterns for Lua parsing (see `scripts/luacats_parser.lua`). - Treesitter for Markdown parsing (see `scripts/text_utils.lua`). - The generated `runtime/doc/*.mpack` files have been removed. - `scripts/gen_eval_files.lua` now instead uses `scripts/cdoc_parser.lua` directly. - Text wrapping is implemented in `scripts/text_utils.lua` and appears to produce more consistent results (the main contributer to the diff of this change). --- runtime/lua/vim/highlight.lua | 15 ++++++++------- 1 file changed, 8 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 b055cce49d..effe280dee 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -1,4 +1,4 @@ ----@defgroup vim.highlight +---@brief --- --- Nvim includes a function for highlighting a selection on yank. --- @@ -19,18 +19,19 @@ --- ```vim --- au TextYankPost * silent! lua vim.highlight.on_yank {on_visual=false} --- ``` +--- local api = vim.api local M = {} --- Table with default priorities used for highlighting: ---- - `syntax`: `50`, used for standard syntax highlighting ---- - `treesitter`: `100`, used for treesitter-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 +--- - `syntax`: `50`, used for standard syntax highlighting +--- - `treesitter`: `100`, used for treesitter-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