fix!: use new-style autocmds
This commit is contained in:
@@ -69,27 +69,37 @@ function M.highlight(group, hl)
|
||||
vim.api.nvim_set_hl(0, group, hl)
|
||||
end
|
||||
|
||||
--- Delete the autocmds when the theme changes to something else
|
||||
function M.onColorScheme()
|
||||
vim.cmd([[autocmd! TokyoNight]])
|
||||
vim.cmd([[augroup! TokyoNight]])
|
||||
end
|
||||
|
||||
---@param config Config
|
||||
function M.autocmds(config)
|
||||
vim.cmd([[augroup TokyoNight]])
|
||||
vim.cmd([[ autocmd!]])
|
||||
vim.cmd([[ autocmd ColorSchemePre * lua require("tokyonight.util").onColorScheme()]])
|
||||
local group = vim.api.nvim_create_augroup("tokyonight", { clear = true })
|
||||
|
||||
vim.cmd(
|
||||
[[ autocmd FileType ]]
|
||||
.. table.concat(config.sidebars, ",")
|
||||
.. [[ setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB]]
|
||||
)
|
||||
if vim.tbl_contains(config.sidebars, "terminal") then
|
||||
vim.cmd([[ autocmd TermOpen * setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB]])
|
||||
vim.api.nvim_create_autocmd("ColorSchemePre", {
|
||||
group = group,
|
||||
callback = function()
|
||||
vim.api.nvim_del_augroup_by_id(group)
|
||||
end,
|
||||
})
|
||||
local function set_whl()
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
local whl = vim.split(vim.wo[win].winhighlight, ",")
|
||||
vim.list_extend(whl, { "Normal:NormalSB", "SignColumn:SignColumnSB" })
|
||||
whl = vim.tbl_filter(function(hl)
|
||||
return hl ~= ""
|
||||
end, whl)
|
||||
vim.opt_local.winhighlight = table.concat(whl, ",")
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = group,
|
||||
pattern = table.concat(config.sidebars, ","),
|
||||
callback = set_whl,
|
||||
})
|
||||
if vim.tbl_contains(config.sidebars, "terminal") then
|
||||
vim.api.nvim_create_autocmd("TermOpen", {
|
||||
group = group,
|
||||
callback = set_whl,
|
||||
})
|
||||
end
|
||||
vim.cmd([[augroup end]])
|
||||
end
|
||||
|
||||
-- Simple string interpolation.
|
||||
|
||||
Reference in New Issue
Block a user