mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-26 18:59:00 +02:00
refactor(config): moved loading of options, keymaps and autocmds to lazyvim.config
This commit is contained in:
parent
7b943822db
commit
dcf520f3a7
4 changed files with 38 additions and 34 deletions
|
@ -71,6 +71,16 @@ function M.setup(opts)
|
||||||
{ title = "LazyVim" }
|
{ title = "LazyVim" }
|
||||||
)
|
)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
---@param range? string
|
---@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")
|
return Semver.range(range or M.lazy_version):matches(require("lazy.core.config").version or "0.0.0")
|
||||||
end
|
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, {
|
setmetatable(M, {
|
||||||
__index = function(_, key)
|
__index = function(_, key)
|
||||||
if options == nil then
|
if options == nil then
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
local function 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
|
|
||||||
|
|
||||||
-- load options here, before lazy init while sourcing plugin modules
|
|
||||||
-- this is needed to make sure options will be correctly applied
|
|
||||||
-- after installing missing plugins
|
|
||||||
load("options")
|
|
||||||
|
|
||||||
-- autocmds and keymaps can wait to load
|
|
||||||
vim.api.nvim_create_autocmd("User", {
|
|
||||||
pattern = "VeryLazy",
|
|
||||||
callback = function()
|
|
||||||
load("autocmds")
|
|
||||||
load("keymaps")
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
return {}
|
|
|
@ -5,7 +5,9 @@ local specs = {
|
||||||
|
|
||||||
-- only add for >=9.0.1, since there's an endless loop in earlier versions
|
-- only add for >=9.0.1, since there's an endless loop in earlier versions
|
||||||
if require("lazyvim.config").has(">=9.1.0") then
|
if require("lazyvim.config").has(">=9.1.0") then
|
||||||
specs[#specs + 1] = { "LazyVim/LazyVim", priority = 10000, lazy = true }
|
specs[#specs + 1] = { "LazyVim/LazyVim", priority = 10000, lazy = false, config = true }
|
||||||
|
else
|
||||||
|
require("lazyvim.config").setup()
|
||||||
end
|
end
|
||||||
|
|
||||||
return specs
|
return specs
|
||||||
|
|
6
lua/lazyvim/plugins/init.lua
Normal file
6
lua/lazyvim/plugins/init.lua
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
-- load options here, before lazy init while sourcing plugin modules
|
||||||
|
-- this is needed to make sure options will be correctly applied
|
||||||
|
-- after installing missing plugins
|
||||||
|
require("lazyvim.config").load("options")
|
||||||
|
|
||||||
|
return {}
|
Loading…
Add table
Add a link
Reference in a new issue