@@ -8,11 +8,31 @@ local M = {}
8
8
9
9
--- @class UserConfig
10
10
--- @field public query ? Query
11
+ --- @field public render_modes ? string[]
11
12
--- @field public bullets ? string[]
12
13
--- @field public highlights ? Highlights
13
14
14
15
--- @param opts UserConfig | nil
15
16
function M .setup (opts )
17
+ --[[
18
+ Reference for pre-defined highlight groups and colors
19
+ ColorColumn bg = 1f1d2e (dark gray / purple)
20
+ PmenuExtra bg = 1f1d2e (dark gray / purple) fg = 6e6a86 (light purple)
21
+ CursorColumn bg = 26233a (more purple version of 1f1d2e)
22
+ PmenuSel bg = 26233a (more purple version of 1f1d2e) fg = e0def4 (white / pink)
23
+ CurSearch bg = f6c177 (light orange) fg = 191724 (dark gray)
24
+ DiffAdd bg = 333c48 (gray / little bit blue)
25
+ DiffChange bg = 433842 (pink / gray)
26
+ DiffDelete bg = 43293a (darker version of 433842)
27
+ Visual bg = 403d52 (lighter version of 1f1d2e)
28
+ MatchParen bg = 1f2e3f (deep blue) fg = 31748f (teel)
29
+ ]]
30
+
31
+ -- Some attempts to handle nested lists
32
+ -- (list_item) @item1
33
+ -- (list_item (list_item (list_item))) @item3
34
+ -- (list) @item1
35
+
16
36
--- @type Config
17
37
local default_config = {
18
38
query = vim .treesitter .query .parse (
@@ -30,17 +50,21 @@ function M.setup(opts)
30
50
(fenced_code_block) @code
31
51
]]
32
52
),
53
+ render_modes = { ' n' , ' c' },
33
54
bullets = { ' ◉' , ' ○' , ' ✸' , ' ✿' },
34
55
highlights = {
35
- heading = ' @comment.hint ' ,
56
+ headings = { ' DiffAdd ' , ' DiffChange ' , ' DiffDelete ' } ,
36
57
code = ' ColorColumn' ,
37
58
},
38
59
}
39
60
state .config = vim .tbl_deep_extend (' force' , default_config , opts or {})
40
61
62
+ -- Call immediately to re-render on LazyReload
63
+ M .refresh ()
64
+
41
65
vim .api .nvim_create_autocmd ({
42
66
' FileChangedShellPost' ,
43
- ' InsertLeave ' ,
67
+ ' ModeChanged ' ,
44
68
' Syntax' ,
45
69
' TextChanged' ,
46
70
' WinResized' ,
@@ -62,6 +86,10 @@ M.refresh = function()
62
86
-- Remove existing highlights / virtual text
63
87
vim .api .nvim_buf_clear_namespace (0 , M .namespace , 0 , - 1 )
64
88
89
+ if not vim .tbl_contains (state .config .render_modes , vim .fn .mode ()) then
90
+ return
91
+ end
92
+
65
93
local parser = vim .treesitter .get_parser (0 , ' markdown' )
66
94
local root = parser :parse ()[1 ]:root ()
67
95
@@ -74,15 +102,11 @@ M.refresh = function()
74
102
75
103
if capture == ' heading' then
76
104
local level = # vim .treesitter .get_node_text (node , 0 )
77
- local bullet = state . config . bullets [((level - 1 ) % # state . config . bullets ) + 1 ]
105
+ local highlight = highlights . headings [((level - 1 ) % # highlights . headings ) + 1 ]
78
106
vim .api .nvim_buf_set_extmark (0 , M .namespace , start_row , 0 , {
79
107
end_row = end_row + 1 ,
80
108
end_col = 0 ,
81
- hl_group = highlights .heading ,
82
- -- This is done to exactly cover over the heading hashtags
83
- virt_text = { { string.rep (' ' , level - 1 ) .. bullet , highlights .heading } },
84
- virt_text_pos = ' overlay' ,
85
- hl_eol = true ,
109
+ hl_group = highlight ,
86
110
})
87
111
elseif capture == ' code' then
88
112
vim .api .nvim_buf_set_extmark (0 , M .namespace , start_row , 0 , {
@@ -91,6 +115,9 @@ M.refresh = function()
91
115
hl_group = highlights .code ,
92
116
hl_eol = true ,
93
117
})
118
+ else
119
+ vim .print (' Unknown capture: ' .. capture )
120
+ vim .print (vim .treesitter .get_node_text (node , 0 ))
94
121
end
95
122
end
96
123
end
0 commit comments