feat: allow packaged plugin config overrides within chadrc

This commit is contained in:
Galen Rowell 2021-09-14 12:21:35 +10:00 committed by siduck76
parent a5a5a8220c
commit 80c8bf4243
2 changed files with 56 additions and 57 deletions

View File

@ -10,6 +10,17 @@ M.ui, M.options, M.plugin_status, M.mappings, M.custom = {}, {}, {}, {}, {}
-- relativenumber = true,
-- }
-- To change the Packer `config` of a plugin that comes with NvChad,
-- add a table entry below matching the plugin github name
-- '-' -> '_', remove any '.lua', '.nvim' extensions
-- this string will be called in a `require`
-- use "(custom.configs).my_func()" to call a function
-- use "custom.blankline" to call a file
M.custom.default_plugin_overrides = {
-- indent_blankline = "custom.blankline",
}
-- user custom mappings
-- e.g: name = { "mode" , "keys" , "cmd" , "options"}
-- name: can be empty or something unique with repect to other custom mappings

View File

@ -9,6 +9,31 @@ local use = packer.use
return packer.startup(function()
local plugin_status = require("core.utils").load_config().plugin_status
-- local plugin_overrides = require("core.utils").load_config().custom.plugin_overrides
-- FUNCTION: override_req, use `chadrc` plugin config override if present
-- name = name inside `default_config` / `chadrc`
-- default_req = run this if 'name' does not exist in `default_config` / `chadrc`
-- if override or default_req start with `(`, then strip that and assume override calls a function, not a whole file
local override_req = function(name, default_req)
local override = require("core.utils").load_config().custom.default_plugin_overrides[name]
local result
if override == nil then
result = default_req
else
result = override
end
if string.match(result, '^%(') then
result = result:sub(2)
result = result:gsub("%)%.", "').", 1)
return "require('" .. result
else
return "require('" .. result .. "')"
end
end
-- this is arranged on the basis of when a plugin starts
-- this is the nvchad core repo containing utilities for some features like theme swticher, no need to lazy load
@ -36,57 +61,46 @@ return packer.startup(function()
use {
"kyazdani42/nvim-web-devicons",
after = "nvim-base16.lua",
config = function()
require "plugins.configs.icons"
end,
config = override_req("nvim_web_devicons", "plugins.configs.icons"),
}
use {
"famiu/feline.nvim",
disable = not plugin_status.feline,
after = "nvim-web-devicons",
config = function()
require "plugins.configs.statusline"
end,
config = override_req("feline", "plugins.configs.statusline"),
}
use {
"akinsho/bufferline.nvim",
disable = not plugin_status.bufferline,
after = "nvim-web-devicons",
config = function()
require "plugins.configs.bufferline"
end,
config = override_req("bufferline", "plugins.configs.bufferline"),
setup = function()
require("core.mappings").bufferline()
end,
}
use {
"lukas-reineke/indent-blankline.nvim",
disable = not plugin_status.blankline,
event = "BufRead",
config = function()
require("plugins.configs.others").blankline()
end,
config = override_req("indent_blankline", "(plugins.configs.others).blankline()"),
}
use {
"norcalli/nvim-colorizer.lua",
disable = not plugin_status.colorizer,
event = "BufRead",
config = function()
require("plugins.configs.others").colorizer()
end,
config = override_req("nvim_colorizer", "(plugins.configs.others).colorizer()"),
}
use {
"nvim-treesitter/nvim-treesitter",
branch = "0.5-compat",
event = "BufRead",
config = function()
require "plugins.configs.treesitter"
end,
config = override_req("nvim_treesitter", "plugins.configs.treesitter"),
}
-- git stuff
@ -94,9 +108,7 @@ return packer.startup(function()
"lewis6991/gitsigns.nvim",
disable = not plugin_status.gitsigns,
opt = true,
config = function()
require "plugins.configs.gitsigns"
end,
config = override_req("gitsigns", "plugins.configs.gitsigns"),
setup = function()
require("core.utils").packer_lazy_load "gitsigns.nvim"
end,
@ -107,9 +119,7 @@ return packer.startup(function()
"karb94/neoscroll.nvim",
disable = not plugin_status.neoscroll,
opt = true,
config = function()
require("plugins.configs.others").neoscroll()
end,
config = override_req("neoscroll", "(plugins.configs.others).neoscroll()"),
setup = function()
require("core.utils").packer_lazy_load "neoscroll.nvim"
end,
@ -154,9 +164,7 @@ return packer.startup(function()
use {
disable = not plugin_status.autosave,
"Pocco81/AutoSave.nvim",
config = function()
require("plugins.configs.others").autosave()
end,
config = override_req("autosave", "(plugins.configs.others).autosave()"),
cond = function()
return require("core.utils").load_config().options.plugin.autosave == true
end,
@ -166,9 +174,7 @@ return packer.startup(function()
"max397574/better-escape.nvim",
disable = not plugin_status.esc_insertmode,
event = "InsertEnter",
config = function()
require("plugins.configs.others").better_escape()
end,
config = override_req("better_escape", "(plugins.configs.others).better_escape()"),
}
-- load luasnips + cmp related in insert mode only
@ -181,18 +187,14 @@ return packer.startup(function()
use {
"hrsh7th/nvim-cmp",
after = "friendly-snippets",
config = function()
require "plugins.configs.cmp"
end,
config = override_req("nvim_cmp", "plugins.configs.cmp"),
}
use {
"L3MON4D3/LuaSnip",
wants = "friendly-snippets",
after = "nvim-cmp",
config = function()
require("plugins.configs.others").luasnip()
end,
config = override_req("luasnip", "(plugins.configs.others).luasnip()"),
}
use {
@ -219,17 +221,13 @@ return packer.startup(function()
use {
"windwp/nvim-autopairs",
after = "nvim-cmp",
config = function()
require("plugins.configs.others").autopairs()
end,
config = override_req("nvim_autopairs", "(plugins.configs.others).autopairs()"),
}
use {
"glepnir/dashboard-nvim",
disable = not plugin_status.dashboard,
config = function()
require "plugins.configs.dashboard"
end,
config = override_req("dashboard", "plugins.configs.dashboard"),
setup = function()
require("core.mappings").dashboard()
end,
@ -249,9 +247,7 @@ return packer.startup(function()
"terrortylor/nvim-comment",
disable = not plugin_status.comment,
cmd = "CommentToggle",
config = function()
require("plugins.configs.others").comment()
end,
config = override_req("nvim_comment", "(plugins.configs.others).comment()"),
setup = function()
require("core.mappings").comment()
end,
@ -261,9 +257,7 @@ return packer.startup(function()
use {
"kyazdani42/nvim-tree.lua",
cmd = { "NvimTreeToggle", "NvimTreeFocus" },
config = function()
require "plugins.configs.nvimtree"
end,
config = override_req("nvim_tree", "plugins.configs.nvimtree"),
setup = function()
require("core.mappings").nvimtree()
end,
@ -279,9 +273,7 @@ return packer.startup(function()
"sudormrfbin/cheatsheet.nvim",
disable = not plugin_status.cheatsheet,
after = "telescope.nvim",
config = function()
require "plugins.configs.cheatsheet"
end,
config = override_req("cheatsheet", "plugins.configs.cheatsheet"),
setup = function()
require("core.mappings").cheatsheet()
end,
@ -298,9 +290,7 @@ return packer.startup(function()
end,
},
},
config = function()
require "plugins.configs.telescope"
end,
config = override_req("telescope", "plugins.configs.telescope"),
setup = function()
require("core.mappings").telescope()
end,
@ -314,9 +304,7 @@ return packer.startup(function()
"TZMinimalist",
"TZFocus",
},
config = function()
require "plugins.configs.zenmode"
end,
config = override_req("truezen", "plugins.configs.zenmode"),
setup = function()
require("core.mappings").truezen()
end,