From f81531df42bf409b8d8b6f2b428e4f9960cc461b Mon Sep 17 00:00:00 2001 From: zbirenbaum Date: Sun, 13 Feb 2022 02:39:07 -0500 Subject: [PATCH] improve method of adding and removing plugins --- lua/core/utils.lua | 36 ++++++++++++++++++++++++------------ lua/plugins/init.lua | 20 +++++++++----------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/lua/core/utils.lua b/lua/core/utils.lua index 855e4eb..6141737 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -280,23 +280,35 @@ M.tbl_override_req = function(name, default_table) return vim.tbl_deep_extend("force", default_table, override) end -M.remove_default_plugins = function(plugin_table) - local removals = require("core.utils").load_config().plugins.default_plugin_remove or {} - local result = {} - - if vim.tbl_isempty(removals) then - return plugin_table +--provide labels to plugins instead of integers +M.label_plugins = function(plugins) + plugins_labeled = {} + for _, plugin in ipairs(plugins) do + plugins_labeled[plugin[1]] = plugin end + return plugins_labeled +end - for _, value in pairs(plugin_table) do - for _, plugin in ipairs(removals) do - if value[1] ~= plugin then - table.insert(result, value) - end +-- remove plugins specified by user from the plugins table +M.remove_default_plugins = function(plugins) + local removals = require("core.utils").load_config().plugins.default_plugin_remove or {} + if not vim.tbl_isempty(removals) then + for _, plugin in pairs(removals) do + plugins[plugin] = nil end end + return plugins +end - return result +-- append user plugins to default plugins +M.add_user_plugins = function(plugins) + local user_Plugins = require("core.utils").load_config().plugins.install or {} + if not vim.tbl_isempty(user_Plugins) then + for _, v in pairs(user_Plugins) do + plugins[v[1]] = v + end + end + return plugins end return M diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index b26c8b1..3716b9a 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -224,18 +224,16 @@ local plugins = { end, }, } + +--label plugins for operational assistance +plugins = require("core.utils").label_plugins(plugins) --remove plugins specified in chadrc plugins = require("core.utils").remove_default_plugins(plugins) +--add plugins specified in chadrc +plugins = require("core.utils").add_user_plugins(plugins) --- append user plugins to default plugins -local user_Plugins = plugin_settings.install - -if type(user_Plugins) == "table" then - if table.maxn(user_Plugins) == 1 then - plugins[#plugins + 1] = user_Plugins[1] - else - plugins[#plugins + 1] = user_Plugins +return packer.startup(function(use) + for _, v in pairs(plugins_labeled) do + use(v) end -end - -return packer.startup { plugins } +end)