Update to actually work

This commit is contained in:
Ryan Hughes
2025-09-19 22:55:55 -04:00
parent 2197fdc216
commit 86653b52d9

View File

@@ -1,12 +1,14 @@
return { return {
{ {
name = "omarchy-theme-hotreload", name = "theme-hotreload",
dir = vim.fn.stdpath("config"), dir = vim.fn.stdpath("config"),
lazy = false, lazy = false,
priority = 1000, priority = 1000,
config = function() config = function()
local function reload_theme() vim.api.nvim_create_autocmd("User", {
-- Clear the module cache pattern = "LazyReload",
callback = function()
-- Clear the theme module cache
package.loaded["plugins.theme"] = nil package.loaded["plugins.theme"] = nil
local ok, theme_spec = pcall(require, "plugins.theme") local ok, theme_spec = pcall(require, "plugins.theme")
@@ -14,27 +16,23 @@ return {
for _, spec in ipairs(theme_spec) do for _, spec in ipairs(theme_spec) do
if spec[1] == "LazyVim/LazyVim" and spec.opts and spec.opts.colorscheme then if spec[1] == "LazyVim/LazyVim" and spec.opts and spec.opts.colorscheme then
local colorscheme = spec.opts.colorscheme local colorscheme = spec.opts.colorscheme
-- Defer to next tick to escape the autocmd context
vim.defer_fn(function()
require("lazy.core.loader").colorscheme(colorscheme)
vim.schedule(function() pcall(vim.cmd.colorscheme, colorscheme)
pcall(vim.cmd, "colorscheme " .. colorscheme)
vim.notify("Theme reloaded: " .. colorscheme, vim.log.levels.INFO)
-- Reapply transparency if it exists local transparency_file = vim.fn.stdpath("config")
local transparency_file = vim.fn.stdpath("config") .. "/plugin/after/transparency.lua" .. "/plugin/after/transparency.lua"
if vim.fn.filereadable(transparency_file) == 1 then if vim.fn.filereadable(transparency_file) == 1 then
vim.cmd("source " .. transparency_file) vim.cmd.source(transparency_file)
end end
end) end, 0)
break break
end end
end end
end end
end end,
-- Listen to Lazy's reload event
vim.api.nvim_create_autocmd("User", {
pattern = "LazyReload",
callback = reload_theme,
}) })
end, end,
}, },