From 39e504a97a0a3151c56b993b6f60af6c97a7358c Mon Sep 17 00:00:00 2001 From: NTBBloodbath Date: Fri, 21 May 2021 20:11:15 -0400 Subject: [PATCH] utils: improve custom plugins management --- lua/doom/utils/init.lua | 61 ++--------------------------------------- 1 file changed, 2 insertions(+), 59 deletions(-) diff --git a/lua/doom/utils/init.lua b/lua/doom/utils/init.lua index cb11d8c..e30d273 100644 --- a/lua/doom/utils/init.lua +++ b/lua/doom/utils/init.lua @@ -4,9 +4,6 @@ -- License: MIT -- ---[[---------------------------------------]]--- ---- Require packer so we can use `packer.use` function in `custom_plugins` function -local packer = require('packer') - -------------------- HELPERS -------------------- Api, Cmd, Fn = vim.api, vim.cmd, vim.fn Keymap, Execute, G = Api.nvim_set_keymap, Api.nvim_command, vim.g @@ -84,63 +81,9 @@ end -- A better and less primitive implementation of custom plugins in Doom Nvim function Custom_plugins(plugins) - -- if a plugin have some configs like enabled or requires then we will - -- store them in that table - local plugin_with_configs = {} - - -- Valid fields for the plugin table (not the boolean ones), see - -- https://github.com/wbthomason/packer.nvim#specifying-plugins - local plugin_valid_fields = {'branch', 'requires', 'config', 'run'} - - if type(plugins) ~= 'string' then - for key, val in pairs(plugins) do - -- Create the correct plugin structure to packer - -- use { - -- url, - -- branch, - -- disable, - -- requires, - -- config, - -- run - -- } - - -- Plugin repository - if key == 'repo' then - table.insert(plugin_with_configs, val) - end + local packer = require('packer') - -- Plugin branch, dependencies, config and post-install/update hooks - if Has_value(plugin_valid_fields, key) then - plugin_with_configs[key] = val - end - - -- If the plugin is enabled or not, false by default - if key == 'enabled' then - if val then - plugin_with_configs['disable'] = false - else - plugin_with_configs['disable'] = true - end - end - - -- If the plugin should be skipped in the updates/syncs, - -- false by default - if key == 'lock' then - if val then - plugin_with_configs['lock'] = true - else - plugin_with_configs['lock'] = false - end - end - end - -- Send the configured plugin to packer - packer.use(plugin_with_configs) - else - -- Send the simple plugins, e.G. those who have not declared with configs - -- 'user/repo' ← simple plugin - -- { 'user/repo', opts } ← configured plugin - packer.use(plugins) - end + packer.use(plugins) end -- Get current OS, returns 'Other' if the current OS is not recognized