feat(util): set_hl managed

This commit is contained in:
Folke Lemaitre 2024-11-21 22:10:25 +01:00
parent b0da066536
commit 96426953a0
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -15,13 +15,15 @@ vim.api.nvim_create_autocmd("ColorScheme", {
--- Ensures the hl groups are always set, even after a colorscheme change.
---@param groups snacks.util.hl
---@param opts? { prefix?:string, default?:boolean }
---@param opts? { prefix?:string, default?:boolean, managed?:boolean }
function M.set_hl(groups, opts)
for hl_group, hl in pairs(groups) do
hl_group = opts and opts.prefix and opts.prefix .. hl_group or hl_group
hl = type(hl) == "string" and { link = hl } or hl --[[@as vim.api.keyset.highlight]]
hl.default = not (opts and opts.default == false)
hl_groups[hl_group] = hl
if not (opts and opts.managed == false) then
hl_groups[hl_group] = hl
end
vim.api.nvim_set_hl(0, hl_group, hl)
end
end