refactor(config): moved loading of options, keymaps and autocmds to lazyvim.config

This commit is contained in:
Folke Lemaitre 2023-01-10 10:20:28 +01:00
parent 7b943822db
commit dcf520f3a7
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
4 changed files with 38 additions and 34 deletions

View file

@ -71,6 +71,16 @@ function M.setup(opts)
{ title = "LazyVim" }
)
end
-- autocmds and keymaps can wait to load
vim.api.nvim_create_autocmd("User", {
group = vim.api.nvim_create_augroup("LazyVim", { clear = true }),
pattern = "VeryLazy",
callback = function()
M.load("autocmds")
M.load("keymaps")
end,
})
end
---@param range? string
@ -79,6 +89,25 @@ function M.has(range)
return Semver.range(range or M.lazy_version):matches(require("lazy.core.config").version or "0.0.0")
end
---@param name "autocmds" | "options" | "keymaps"
function M.load(name)
local Util = require("lazy.core.util")
-- always load lazyvim, then user file
for _, mod in ipairs({ "lazyvim.config." .. name, "config." .. name }) do
Util.try(function()
require(mod)
end, {
msg = "Failed loading " .. mod,
on_error = function(msg)
local modpath = require("lazy.core.cache").find(mod)
if modpath then
Util.error(msg)
end
end,
})
end
end
setmetatable(M, {
__index = function(_, key)
if options == nil then