mirror of https://github.com/folke/lazy.nvim.git
feat(loader): automatically lazy-load colorschemes
This commit is contained in:
parent
210d1703ec
commit
07b467738d
|
@ -22,6 +22,7 @@
|
|||
- 🔎 Automatically check for updates
|
||||
- 📋 Commit, branch, tag, version, and full [Semver](https://devhints.io/semver) support
|
||||
- 📈 Statusline component to see the number of pending updates
|
||||
- 🎨 Automatically lazy-loads colorschemes
|
||||
|
||||
## ⚡️ Requirements
|
||||
|
||||
|
@ -112,6 +113,9 @@ module of plugin `A`, then plugin `A` will be loaded on demand as expected.
|
|||
If you don't want this behavior for a certain plugin, you can specify that with `module=false`.
|
||||
You can then manually load the plugin with `:Lazy load foobar.nvim`.
|
||||
|
||||
Colorscheme plugins can be configured with `lazy=true`. The plugin will automagically load
|
||||
when doing `colorscheme foobar`.
|
||||
|
||||
You can configure **lazy.nvim** to lazy-load all plugins by default with `config.defaults.lazy = true`.
|
||||
|
||||
Additionally, you can also lazy-load on **events**, **commands**,
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue