Skip to content

Commit

Permalink
fix!: use new-style autocmds
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 19, 2023
1 parent 1825940 commit ec8f2ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extra themes for Kitty, Alacritty, iTerm and Fish.
### 🍭 Extras

<!-- extras:start -->

- [Alacritty](https://github.com/alacritty/alacritty) ([alacritty](extras/alacritty))
- [Delta](https://github.com/dandavison/delta) ([delta](extras/delta))
- [Dunst](https://dunst-project.org/) ([dunst](extras/dunst))
Expand All @@ -54,7 +55,7 @@ extra themes for Kitty, Alacritty, iTerm and Fish.

## ⚡️ Requirements

- Neovim >= 0.6.0
- Neovim >= 0.7.2

## 📦 Installation

Expand Down
44 changes: 27 additions & 17 deletions lua/tokyonight/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()]])

vim.cmd(
[[ autocmd FileType ]]
.. table.concat(config.sidebars, ",")
.. [[ setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB]]
)
local group = vim.api.nvim_create_augroup("tokyonight", { clear = true })

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.cmd([[ autocmd TermOpen * setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB]])
vim.api.nvim_create_autocmd("TermOpen", {
group = group,
callback = set_whl,
})
end
vim.cmd([[augroup end]])
end

-- Simple string interpolation.
Expand Down

0 comments on commit ec8f2ef

Please sign in to comment.