aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/vimhelp.lua
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-12-18 16:49:44 +0100
committerChristian Clason <c.clason@uni-graz.at>2023-12-20 18:58:40 +0100
commitcc6a257c8cad8051b6f7e9287249293ab0a929d9 (patch)
treecfdebdcd4b040be345cf035f13a242114db4747b /runtime/lua/vim/vimhelp.lua
parentdb4b0aeb928461a058e59969e07df886cbd990c1 (diff)
downloadrneovim-cc6a257c8cad8051b6f7e9287249293ab0a929d9.tar.gz
rneovim-cc6a257c8cad8051b6f7e9287249293ab0a929d9.tar.bz2
rneovim-cc6a257c8cad8051b6f7e9287249293ab0a929d9.zip
docs: apply current colorscheme to default highlight groups
Problem: Not all default highlight groups show their actual colors. Solution: Refactor `vimhelp.lua` and apply it to all relevant lists (UI groups, syntax groups, treesitter groups, LSP groups, diagnostic groups).
Diffstat (limited to 'runtime/lua/vim/vimhelp.lua')
-rw-r--r--runtime/lua/vim/vimhelp.lua36
1 files changed, 19 insertions, 17 deletions
diff --git a/runtime/lua/vim/vimhelp.lua b/runtime/lua/vim/vimhelp.lua
index a4d6a50b12..4af6866d48 100644
--- a/runtime/lua/vim/vimhelp.lua
+++ b/runtime/lua/vim/vimhelp.lua
@@ -2,26 +2,28 @@
local M = {}
--- Called when editing the doc/syntax.txt file
-function M.highlight_groups()
- local save_cursor = vim.fn.getcurpos()
-
- local start_lnum = vim.fn.search([[\*highlight-groups\*]], 'c')
- if start_lnum == 0 then
- return
- end
- local end_lnum = vim.fn.search('^======')
- if end_lnum == 0 then
- return
- end
-
+--- Apply current colorscheme to lists of default highlight groups
+---
+--- Note: {patterns} is assumed to be sorted by occurrence in the file.
+--- @param patterns {start:string,stop:string,match:string}[]
+function M.highlight_groups(patterns)
local ns = vim.api.nvim_create_namespace('vimhelp')
vim.api.nvim_buf_clear_namespace(0, ns, 0, -1)
- for lnum = start_lnum, end_lnum do
- local word = vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, true)[1]:match('^(%w+)\t')
- if vim.fn.hlexists(word) ~= 0 then
- vim.api.nvim_buf_set_extmark(0, ns, lnum - 1, 0, { end_col = #word, hl_group = word })
+ local save_cursor = vim.fn.getcurpos()
+
+ for _, pat in pairs(patterns) do
+ local start_lnum = vim.fn.search(pat.start, 'c')
+ local end_lnum = vim.fn.search(pat.stop)
+ if start_lnum == 0 or end_lnum == 0 then
+ break
+ end
+
+ for lnum = start_lnum, end_lnum do
+ local word = vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, true)[1]:match(pat.match)
+ if vim.fn.hlexists(word) ~= 0 then
+ vim.api.nvim_buf_set_extmark(0, ns, lnum - 1, 0, { end_col = #word, hl_group = word })
+ end
end
end