fix: add after directories to rtp to make after/ftplugin and others work. Fixes #47

This commit is contained in:
Folke Lemaitre 2022-12-20 23:35:06 +01:00
parent b193f96f7b
commit 3606d62918
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 18 additions and 24 deletions

View File

@ -179,7 +179,7 @@ function M.get_rtp()
end
for _, path in ipairs(vim.api.nvim_list_runtime_paths()) do
path = path:gsub("\\", "/")
if not skip[path] then
if not skip[path] and not path:find("after/?$") then
M.rtp[#M.rtp + 1] = path
end
end

View File

@ -46,18 +46,11 @@ end
function M.startup()
Util.track({ start = "startup" })
local rtp = vim.opt.rtp:get()
Util.track({ start = "filetype" })
local ft = vim.env.VIMRUNTIME .. "/filetype.lua"
Util.try(function()
vim.cmd("silent source " .. ft)
end, "Failed to source `" .. ft .. "`")
Util.track()
M.source(vim.env.VIMRUNTIME .. "/filetype.lua")
-- load plugins from rtp, excluding after
Util.track({ start = "rtp plugins" })
for _, path in ipairs(rtp) do
for _, path in ipairs(vim.opt.rtp:get()) do
if not path:find("after/?$") then
M.packadd(path)
end
@ -73,16 +66,9 @@ function M.startup()
end
Util.track()
-- load after files
-- load after plugins
Util.track({ start = "after" })
-- load after files from plugins
for _, plugin in pairs(Config.plugins) do
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
for _, path in ipairs(vim.opt.rtp:get()) do
if path:find("after/?$") then
M.source_runtime(path, "plugin")
end
@ -135,6 +121,10 @@ function M.load(plugins, reason)
Handler.disable(plugin)
vim.opt.runtimepath:prepend(plugin.dir)
local after = plugin.dir .. "/after"
if vim.loop.fs_stat(after) then
vim.opt.runtimepath:append(after)
end
if plugin.dependencies then
M.load(plugin.dependencies, {})
@ -185,12 +175,16 @@ function M.source_runtime(...)
-- plugin files are sourced alphabetically per directory
table.sort(files)
for _, path in ipairs(files) do
M.source(path)
end
end
function M.source(path)
Util.track({ runtime = path })
Util.try(function()
vim.cmd("silent source " .. path)
end, "Failed to source `" .. path .. "`")
Util.track()
end
end
-- This loader is added as the very last one.