summaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-06-24 20:57:15 +0200
committerThomas Vanbesien <tvanbesi@proton.me>2026-06-24 20:57:15 +0200
commit49622e90708ae0987153a6e2beed967217ff2721 (patch)
tree1d2870f169c34a53b9c28d8601fed931f3ed253e /lua
parentb393c59ad0e3d85616eeb5be3a12042d6f3dbe63 (diff)
downloadnvim-config-49622e90708ae0987153a6e2beed967217ff2721.tar.gz
nvim-config-49622e90708ae0987153a6e2beed967217ff2721.zip
refactor(nvim): rewrite highlight (now color) plugin
Diffstat (limited to 'lua')
-rw-r--r--lua/dotfiles/color.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/lua/dotfiles/color.lua b/lua/dotfiles/color.lua
new file mode 100644
index 0000000..6672ac0
--- /dev/null
+++ b/lua/dotfiles/color.lua
@@ -0,0 +1,52 @@
+-- Theme-reaction engine. Features register a function that (re)applies their highlight settings;
+-- the engine runs every registered applier whenever the active theme changes — a new colorscheme or
+-- a light/dark 'background' flip — and once after startup. Appliers are wired up in
+-- plugin/50-color.lua.
+--
+-- API:
+-- register(apply) — `apply` (re)applies a feature's highlights; the engine calls it on the
+-- theme-change events above and in the post-startup pass
+
+local M = {}
+
+-- Registered appliers, run in registration order.
+M.appliers = {}
+
+-- Run every registered applier.
+local function apply_all()
+ for _, apply in ipairs(M.appliers) do
+ apply()
+ end
+end
+
+-- Register a highlight applier. Called immediately on the next theme-change event and in the
+-- post-startup pass, so registration order is the apply order.
+function M.register(apply)
+ assert(type(apply) == "function", "color.register: apply must be a function")
+ M.appliers[#M.appliers + 1] = apply
+end
+
+-- Re-apply on a colorscheme change and on a light/dark 'background' flip.
+vim.api.nvim_create_autocmd("ColorScheme", {
+ desc = "Re-apply registered highlights after a colorscheme change",
+ group = vim.g.dotfiles.augroup,
+ callback = apply_all,
+})
+vim.api.nvim_create_autocmd("OptionSet", {
+ desc = "Re-apply registered highlights after a 'background' change",
+ pattern = "background",
+ group = vim.g.dotfiles.augroup,
+ callback = apply_all,
+})
+
+-- Initial pass. OptionSet does not fire during startup (:help OptionSet), so a 'background' set by
+-- local.lua (sourced from plugin/99-local.lua, i.e. during startup) is missed. Apply once on
+-- VimEnter, after startup has settled 'background' to its final value.
+vim.api.nvim_create_autocmd("VimEnter", {
+ desc = "Apply registered highlights once startup has settled 'background'",
+ group = vim.g.dotfiles.augroup,
+ once = true,
+ callback = apply_all,
+})
+
+return M