1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-23 23:11:32 +08:00
SpaceVim/bundle/nvim-plug/lua/plug/init.lua

91 lines
2.1 KiB
Lua
Raw Normal View History

--=============================================================================
-- plug.lua
-- Copyright 2025 Eric Wong
-- Author: Eric Wong < wsdjeg@outlook.com >
-- License: GPLv3
--=============================================================================
local M = {}
local all_plugins = {}
local hooks = require('plug.hooks')
local loader = require('plug.loader')
local config = require('plug.config')
function M.setup(opt)
config.setup(opt)
end
--- @param plugins table<PluginSpec>
function M.add(plugins, skip_deps)
for _, plug in ipairs(plugins) do
if plug.depends and not skip_deps then
2025-02-08 20:39:11 +08:00
M.add(plug.depends)
M.add({ plug }, true)
2025-02-08 20:39:11 +08:00
else
loader.parser(plug)
if not plug.enabled then
goto continue
end
all_plugins[plug.name] = plug
if plug.cmds then
hooks.on_cmds(plug.cmds, plug)
end
if plug.events then
hooks.on_events(plug.events, plug)
end
2025-02-08 20:39:11 +08:00
if plug.on_ft then
hooks.on_ft(plug.on_ft, plug)
end
2025-02-04 23:50:08 +08:00
2025-02-08 20:39:11 +08:00
if plug.on_map then
hooks.on_map(plug.on_map, plug)
end
2025-02-05 11:31:31 +08:00
2025-02-08 20:39:11 +08:00
if plug.on_func then
hooks.on_func(plug.on_func, plug)
end
2025-02-07 13:17:29 +08:00
if not config.enable_priority then
if
not plug.events
and not plug.cmds
and not plug.on_ft
and not plug.on_map
and not plug.on_func
then
loader.load(plug)
end
2025-02-08 20:39:11 +08:00
end
::continue::
end
end
end
function M.get()
return all_plugins
end
function M.load()
if config.enable_priority then
local start = {}
for _, v in pairs(all_plugins) do
if not v.events and not v.cmds and not v.on_ft and not v.on_map and not v.on_func then
table.insert(start, v)
end
end
table.sort(start, function(a, b)
local priority_a = a.priority or 50
local priority_b = b.priority or 50
return priority_a > priority_b
end)
for _, v in ipairs(start) do
loader.load(v)
end
end
end
return M