fix(#2658): change SpellCap groups to reduce confusion: ExecFile->Question, ImageFile->Question, SpecialFile->Title, Symlink->Underlined; add all other highlight groups to :NvimTreeHiTest (#2732)
* fix(#2658): add all highlight groups to :NvimTreeHiTest * fix(#2658): add all highlight groups to :NvimTreeHiTest * fix(#2658): change SpellCap groups: ExecFile->Question, ImageFile->Question, SpecialFile->Title, Symlink->Underlined
This commit is contained in:
parent
308f2fcec2
commit
0aca0920f4
@ -1,5 +1,8 @@
|
|||||||
local appearance = require "nvim-tree.appearance"
|
local appearance = require "nvim-tree.appearance"
|
||||||
|
|
||||||
|
-- others with name and links less than this arbitrary value are short
|
||||||
|
local SHORT_LEN = 50
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@class HighlightDisplay for :NvimTreeHiTest
|
---@class HighlightDisplay for :NvimTreeHiTest
|
||||||
@ -8,7 +11,7 @@ local M = {}
|
|||||||
---@field def string :hi concrete definition after following any links
|
---@field def string :hi concrete definition after following any links
|
||||||
local HighlightDisplay = {}
|
local HighlightDisplay = {}
|
||||||
|
|
||||||
---@param group string nvim-tree highlight group
|
---@param group string nvim-tree highlight group name
|
||||||
---@return HighlightDisplay
|
---@return HighlightDisplay
|
||||||
function HighlightDisplay:new(group)
|
function HighlightDisplay:new(group)
|
||||||
local o = {}
|
local o = {}
|
||||||
@ -39,38 +42,91 @@ function HighlightDisplay:new(group)
|
|||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Render one group.
|
||||||
|
---@param bufnr number to render in
|
||||||
|
---@param fmt string format string for group, links, def
|
||||||
|
---@param l number line number to render at
|
||||||
|
---@return number l next line number
|
||||||
function HighlightDisplay:render(bufnr, fmt, l)
|
function HighlightDisplay:render(bufnr, fmt, l)
|
||||||
local text = string.format(fmt, self.group, self.links, self.def)
|
local text = string.format(fmt, self.group, self.links, self.def)
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { text })
|
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { text })
|
||||||
vim.api.nvim_buf_add_highlight(bufnr, -1, self.group, l, 0, #self.group)
|
vim.api.nvim_buf_add_highlight(bufnr, -1, self.group, l, 0, #self.group)
|
||||||
|
|
||||||
|
return l + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
---Run a test similar to :so $VIMRUNTIME/syntax/hitest.vim
|
---Render many groups.
|
||||||
---Display all nvim-tree highlight groups, their link chain and actual definition
|
---@param header string before with underline line
|
||||||
function M.hi_test()
|
---@param displays HighlightDisplay[] highlight group
|
||||||
local displays = {}
|
---@param bufnr number to render in
|
||||||
|
---@param l number line number to start at
|
||||||
|
---@return number l next line number
|
||||||
|
local function render_displays(header, displays, bufnr, l)
|
||||||
local max_group_len = 0
|
local max_group_len = 0
|
||||||
local max_links_len = 0
|
local max_links_len = 0
|
||||||
|
|
||||||
-- build all highlight groups, name only
|
-- build all highlight groups, using name only
|
||||||
for _, highlight_group in ipairs(appearance.HIGHLIGHT_GROUPS) do
|
for _, display in ipairs(displays) do
|
||||||
local display = HighlightDisplay:new(highlight_group.group)
|
|
||||||
table.insert(displays, display)
|
|
||||||
max_group_len = math.max(max_group_len, #display.group)
|
max_group_len = math.max(max_group_len, #display.group)
|
||||||
max_links_len = math.max(max_links_len, #display.links)
|
max_links_len = math.max(max_links_len, #display.links)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- header
|
||||||
|
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { header, (header:gsub(".", "-")) })
|
||||||
|
l = l + 2
|
||||||
|
|
||||||
|
-- render and highlight
|
||||||
|
local fmt = string.format("%%-%d.%ds %%-%d.%ds %%s", max_group_len, max_group_len, max_links_len, max_links_len)
|
||||||
|
for _, display in ipairs(displays) do
|
||||||
|
l = display:render(bufnr, fmt, l)
|
||||||
|
end
|
||||||
|
|
||||||
|
return l
|
||||||
|
end
|
||||||
|
|
||||||
|
---Run a test similar to :so $VIMRUNTIME/syntax/hitest.vim
|
||||||
|
---Display all nvim-tree and neovim highlight groups, their link chain and actual definition
|
||||||
|
function M.hi_test()
|
||||||
-- create a buffer
|
-- create a buffer
|
||||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
|
|
||||||
-- render and highlight
|
|
||||||
local l = 0
|
local l = 0
|
||||||
local fmt = string.format("%%-%d.%ds %%-%d.%ds %%s", max_group_len, max_group_len, max_links_len, max_links_len)
|
|
||||||
for _, display in ipairs(displays) do
|
-- nvim-tree groups, ordered
|
||||||
display:render(bufnr, fmt, l)
|
local displays = {}
|
||||||
l = l + 1
|
for _, highlight_group in ipairs(appearance.HIGHLIGHT_GROUPS) do
|
||||||
|
local display = HighlightDisplay:new(highlight_group.group)
|
||||||
|
table.insert(displays, display)
|
||||||
end
|
end
|
||||||
|
l = render_displays("nvim-tree", displays, bufnr, l)
|
||||||
|
|
||||||
|
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { "" })
|
||||||
|
l = l + 1
|
||||||
|
|
||||||
|
-- built in groups, ordered opaquely by nvim
|
||||||
|
local displays_short, displays_long = {}, {}
|
||||||
|
local ok, out = pcall(vim.api.nvim_cmd, { cmd = "highlight" }, { output = true })
|
||||||
|
if ok then
|
||||||
|
for group in string.gmatch(out, "(%w*)%s+xxx") do
|
||||||
|
if group:find("NvimTree", 1, true) ~= 1 then
|
||||||
|
local display = HighlightDisplay:new(group)
|
||||||
|
if #display.group + #display.links > SHORT_LEN then
|
||||||
|
table.insert(displays_long, display)
|
||||||
|
else
|
||||||
|
table.insert(displays_short, display)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- short ones first
|
||||||
|
l = render_displays("other, short", displays_short, bufnr, l)
|
||||||
|
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { "" })
|
||||||
|
l = l + 1
|
||||||
|
|
||||||
|
-- long
|
||||||
|
render_displays("other, long", displays_long, bufnr, l)
|
||||||
|
|
||||||
-- finalise and focus the buffer
|
-- finalise and focus the buffer
|
||||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
|
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
|
||||||
|
|||||||
@ -1,5 +1,11 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
---@class HighlightGroup
|
||||||
|
---@field group string
|
||||||
|
---@field link string|nil
|
||||||
|
---@field def string|nil
|
||||||
|
|
||||||
|
---@type HighlightGroup[]
|
||||||
-- All highlight groups: linked or directly defined.
|
-- All highlight groups: linked or directly defined.
|
||||||
-- Please add new groups to help and preserve order.
|
-- Please add new groups to help and preserve order.
|
||||||
-- Please avoid directly defined groups to preserve accessibility for TUI.
|
-- Please avoid directly defined groups to preserve accessibility for TUI.
|
||||||
@ -24,10 +30,10 @@ M.HIGHLIGHT_GROUPS = {
|
|||||||
{ group = "NvimTreeStatusLineNC", link = "StatusLineNC" },
|
{ group = "NvimTreeStatusLineNC", link = "StatusLineNC" },
|
||||||
|
|
||||||
-- File Text
|
-- File Text
|
||||||
{ group = "NvimTreeExecFile", link = "SpellCap" },
|
{ group = "NvimTreeExecFile", link = "Question" },
|
||||||
{ group = "NvimTreeImageFile", link = "SpellCap" },
|
{ group = "NvimTreeImageFile", link = "Question" },
|
||||||
{ group = "NvimTreeSpecialFile", link = "SpellCap" },
|
{ group = "NvimTreeSpecialFile", link = "Title" },
|
||||||
{ group = "NvimTreeSymlink", link = "SpellCap" },
|
{ group = "NvimTreeSymlink", link = "Underlined" },
|
||||||
|
|
||||||
-- Folder Text
|
-- Folder Text
|
||||||
{ group = "NvimTreeRootFolder", link = "Title" },
|
{ group = "NvimTreeRootFolder", link = "Title" },
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user