fix: use initial rtp for rtp plugin after files and use loaded plugins for their after files

This commit is contained in:
Folke Lemaitre 2022-12-15 23:23:18 +01:00
parent 6ca03dcd1a
commit 7134417e89
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 24 additions and 16 deletions

View File

@ -119,6 +119,7 @@ function M.setup(spec, opts)
me,
vim.env.VIMRUNTIME,
vim.fn.stdpath("config"),
vim.fn.stdpath("config") .. "/after",
}
end
vim.opt.rtp:append(M.options.readme.root)

View File

@ -46,9 +46,11 @@ end
function M.startup()
Util.track({ start = "startup" })
-- load plugins from rtp
local rtp = vim.opt.rtp:get()
-- load plugins from rtp, excluding after
Util.track({ start = "rtp plugins" })
for _, path in ipairs(vim.opt.rtp:get()) do
for _, path in ipairs(rtp) do
if not path:find("after/?$") then
M.source_runtime(path, "plugin")
M.ftdetect(path)
@ -56,33 +58,38 @@ function M.startup()
end
Util.track()
-- load start plugin
Util.track({ start = "start" })
for _, plugin in pairs(Config.plugins) do
-- load start plugin
if plugin.lazy == false then
M.load(plugin, { start = "start" })
end
end
Util.track()
Util.track({ start = "init" })
-- load after files
Util.track({ start = "after" })
-- load after files from plugins
for _, plugin in pairs(Config.plugins) do
-- run plugin init
if plugin.init then
Util.track({ plugin = plugin.name, init = "init" })
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
Util.track()
if plugin._.loaded then
M.source_runtime(plugin.dir, "after/plugin")
end
end
-- load after files from rtp plugins
for _, path in ipairs(rtp) do
if path:find("after/?$") then
M.source_runtime(path, "plugin")
end
end
Util.track()
-- load after files
Util.track({ start = "after" })
for _, path in ipairs(vim.opt.rtp:get()) do
if path:find("after/?$") then
M.source_runtime(path, "plugin")
else
M.source_runtime(path, "after/plugin")
-- run plugin init
Util.track({ start = "init" })
for _, plugin in pairs(Config.plugins) do
if plugin.init then
Util.track({ plugin = plugin.name, init = "init" })
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
Util.track()
end
end
Util.track()