feat(loader): automatically lazy-load colorschemes

This commit is contained in:
Folke Lemaitre 2022-12-22 13:49:00 +01:00
parent 210d1703ec
commit 07b467738d
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 26 additions and 0 deletions

View file

@ -37,6 +37,12 @@ function M.setup()
M.disabled_rtp_plugins[file] = true
end
vim.api.nvim_create_autocmd("ColorSchemePre", {
callback = function(event)
M.colorscheme(event.match)
end,
})
-- autoload opt plugins
table.insert(package.loaders, M.autoload)
end
@ -191,6 +197,22 @@ function M.source(path)
Util.track()
end
function M.colorscheme(name)
if vim.tbl_contains(vim.fn.getcompletion("", "color"), name) then
return
end
for _, plugin in pairs(Config.plugins) do
if not plugin._.loaded then
for _, ext in ipairs({ "lua", "vim" }) do
local path = plugin.dir .. "/colors/" .. name .. "." .. ext
if vim.loop.fs_stat(path) then
return M.load(plugin, { colorscheme = name })
end
end
end
end
end
-- This loader is added as the very last one.
-- This only hits when the modname is not cached and
-- even then only once per plugin. So pretty much never.