@@ -107,30 +107,58 @@ util.highlight = function(hi_name, hi)
107
107
end
108
108
end
109
109
110
- --- Delete the autocmds when the theme changes to something else
111
- util .on_colorscheme = function ()
112
- if vim .g .colors_name ~= util .colors_name then
113
- vim .cmd (' autocmd! ' .. util .colors_name )
114
- vim .cmd (' augroup!' .. util .colors_name )
115
- end
116
- end
117
-
118
110
--- @param config gt.ConfigSchema
119
111
util .autocmds = function (config )
120
- vim .cmd (string.format (' augroup %s ' , util .colors_name ))
121
- vim .cmd (' autocmd!' )
122
- vim .cmd (' autocmd ColorScheme * lua require("github-theme.util").on_colorscheme()' )
112
+ local group = vim .api .nvim_create_augroup (' github-theme' , { clear = false })
113
+
114
+ -- Delete the github-theme autocmds when the theme changes to something else
115
+ vim .api .nvim_create_autocmd (' ColorScheme' , {
116
+ pattern = ' *' ,
117
+ group = group ,
118
+ callback = function ()
119
+ if vim .g .colors_name ~= util .colors_name then
120
+ vim .api .nvim_del_augroup_by_id (group )
121
+ end
122
+ end ,
123
+ })
124
+
123
125
if config .dev then
124
- vim .cmd (string.format (' autocmd BufWritePost */lua/github-theme/** nested colorscheme %s' , util .colors_name ))
126
+ -- Enables hot-reloading in github-nvim-theme.
127
+ vim .api .nvim_create_autocmd (' BufWritePost' , {
128
+ pattern = ' */lua/github-theme/**' ,
129
+ nested = true ,
130
+ group = group ,
131
+ callback = function ()
132
+ vim .cmd (string.format (' colorscheme %s' , util .colors_name ))
133
+ end ,
134
+ })
135
+ end
136
+
137
+ local func_winhightlight = function ()
138
+ vim .wo .winhighlight = ' Normal:NormalSB,SignColumn:SignColumnSB'
125
139
end
140
+
126
141
for _ , sidebar in ipairs (config .sidebars ) do
127
142
if sidebar == ' terminal' then
128
- vim .cmd (' autocmd TermOpen * setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB' )
143
+ -- Set dark color for terminal background.,
144
+ vim .api .nvim_create_autocmd (' TermOpen' , {
145
+ pattern = ' *' ,
146
+ group = group ,
147
+ callback = function ()
148
+ func_winhightlight ()
149
+ end ,
150
+ })
129
151
else
130
- vim .cmd (string.format (' autocmd FileType %s setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB' , sidebar ))
152
+ -- Set dark color for custom sidebars background.
153
+ vim .api .nvim_create_autocmd (' FileType' , {
154
+ pattern = sidebar ,
155
+ group = group ,
156
+ callback = function ()
157
+ func_winhightlight ()
158
+ end ,
159
+ })
131
160
end
132
161
end
133
- vim .cmd (' augroup end' )
134
162
end
135
163
136
164
--- @param base gt.Highlights.Base
0 commit comments