aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/vimhelp.lua
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-09-08 21:05:35 +0800
committerGitHub <noreply@github.com>2023-09-08 21:05:35 +0800
commitd0d4160dd13fad952338b8582e2db8838172bbf1 (patch)
tree9ffe95bd28498db413fa45dad61ccb16d09cef5a /runtime/lua/vim/vimhelp.lua
parentcc3df63c3ba954962fc1b9ce0503a5379ef0c7d0 (diff)
downloadrneovim-d0d4160dd13fad952338b8582e2db8838172bbf1.tar.gz
rneovim-d0d4160dd13fad952338b8582e2db8838172bbf1.tar.bz2
rneovim-d0d4160dd13fad952338b8582e2db8838172bbf1.zip
feat(runtime): highlight hl groups in syntax.txt (#25050)
- Add runtime/lua/vim/vimhelp.lua, which is a translation of Vim's runtime/import/dist/vimhelp.vim. - Unlike Vim, run the highlighting from an ftplugin file instead of a syntax file, so that it is run even if using treesitter.
Diffstat (limited to 'runtime/lua/vim/vimhelp.lua')
-rw-r--r--runtime/lua/vim/vimhelp.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/runtime/lua/vim/vimhelp.lua b/runtime/lua/vim/vimhelp.lua
new file mode 100644
index 0000000000..a4d6a50b12
--- /dev/null
+++ b/runtime/lua/vim/vimhelp.lua
@@ -0,0 +1,31 @@
+-- Extra functionality for displaying Vim help.
+
+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
+
+ 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 })
+ end
+ end
+
+ vim.fn.setpos('.', save_cursor)
+end
+
+return M