1
1
local appearance = require " nvim-tree.appearance"
2
2
3
+ -- others with name and links less than this arbitrary value are short
4
+ local SHORT_LEN = 50
5
+
3
6
local M = {}
4
7
5
8
--- @class HighlightDisplay for : NvimTreeHiTest
55
58
56
59
--- Render many groups.
57
60
--- @param header string before with underline line
58
- --- @param groups string [] highlight group names
61
+ --- @param displays HighlightDisplay [] highlight group
59
62
--- @param bufnr number to render in
60
63
--- @param l number line number to start at
61
64
--- @return number l next line number
62
- local function render_groups (header , groups , bufnr , l )
65
+ local function render_displays (header , displays , bufnr , l )
63
66
local max_group_len = 0
64
67
local max_links_len = 0
65
68
66
- --- @type HighlightDisplay[]
67
- local displays = {}
68
-
69
69
-- build all highlight groups, using name only
70
- for _ , group in ipairs (groups ) do
71
- local display = HighlightDisplay :new (group )
72
- table.insert (displays , display )
70
+ for _ , display in ipairs (displays ) do
73
71
max_group_len = math.max (max_group_len , # display .group )
74
72
max_links_len = math.max (max_links_len , # display .links )
75
73
end
@@ -96,26 +94,39 @@ function M.hi_test()
96
94
local l = 0
97
95
98
96
-- nvim-tree groups, ordered
99
- local groups = {}
97
+ local displays = {}
100
98
for _ , highlight_group in ipairs (appearance .HIGHLIGHT_GROUPS ) do
101
- table.insert (groups , highlight_group .group )
99
+ local display = HighlightDisplay :new (highlight_group .group )
100
+ table.insert (displays , display )
102
101
end
103
- l = render_groups (" nvim-tree" , groups , bufnr , l )
102
+ l = render_displays (" nvim-tree" , displays , bufnr , l )
104
103
105
104
vim .api .nvim_buf_set_lines (bufnr , l , - 1 , true , { " " })
106
105
l = l + 1
107
106
108
107
-- built in groups, ordered opaquely by nvim
109
- groups = {}
108
+ local displays_short , displays_long = {}, {}
110
109
local ok , out = pcall (vim .api .nvim_cmd , { cmd = " highlight" }, { output = true })
111
110
if ok then
112
111
for group in string.gmatch (out , " (%w*)%s+xxx" ) do
113
112
if group :find (" NvimTree" , 1 , true ) ~= 1 then
114
- table.insert (groups , group )
113
+ local display = HighlightDisplay :new (group )
114
+ if # display .group + # display .links > SHORT_LEN then
115
+ table.insert (displays_long , display )
116
+ else
117
+ table.insert (displays_short , display )
118
+ end
115
119
end
116
120
end
117
121
end
118
- l = render_groups (" neovim" , groups , bufnr , l )
122
+
123
+ -- short ones first
124
+ l = render_displays (" other, short" , displays_short , bufnr , l )
125
+ vim .api .nvim_buf_set_lines (bufnr , l , - 1 , true , { " " })
126
+ l = l + 1
127
+
128
+ -- long
129
+ l = render_displays (" other, long" , displays_long , bufnr , l )
119
130
120
131
-- finalise and focus the buffer
121
132
vim .api .nvim_buf_set_option (bufnr , " modifiable" , false )
0 commit comments