refactor: add utils to the global scope

This commit is contained in:
Arman.H 2022-05-10 18:13:48 +04:30 committed by siduck
parent 8571787d70
commit 5a1240be82
19 changed files with 41 additions and 45 deletions

View File

@ -1,7 +1,7 @@
-- example file i.e lua/custom/init.lua
-- MAPPINGS
local map = require("core.utils").map
local map = nvchad.map
map("n", "<leader>cc", ":Telescope <CR>")
map("n", "<leader>q", ":q <CR>")

View File

@ -5,6 +5,7 @@ if present then
end
local core_modules = {
"core.utils",
"core.options",
"core.autocmds",
"core.mappings",

View File

@ -1,6 +1,4 @@
local utils = require "core.utils"
local map = utils.map
local map = nvchad.map
local cmd = vim.cmd
local user_cmd = vim.api.nvim_create_user_command
@ -40,7 +38,7 @@ map("n", "<C-k>", "<C-w>k")
map("n", "<C-j>", "<C-w>j")
map("n", "<leader>x", function()
require("core.utils").close_buffer()
nvchad.close_buffer()
end)
map("n", "<C-c>", "<cmd> :%y+ <CR>") -- copy whole file content
@ -92,7 +90,7 @@ cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()"
map("n", "<leader>uu", "<cmd> :NvChadUpdate <CR>")
-- load overriden misc mappings
require("core.utils").load_config().mappings.misc()
nvchad.load_config().mappings.misc()
local M = {}

View File

@ -84,4 +84,4 @@ vim.schedule(function()
end)
-- load user options if the file exists
require("core.utils").load_config().options.user()
nvchad.load_config().options.user()

View File

@ -1,6 +1,6 @@
local M = {}
_G.nvchad = {}
M.close_buffer = function(force)
nvchad.close_buffer = function(force)
if vim.bo.buftype == "terminal" then
vim.api.nvim_win_hide(0)
return
@ -22,7 +22,7 @@ M.close_buffer = function(force)
vim.cmd(close_cmd)
end
M.load_config = function()
nvchad.load_config = function()
local conf = require "core.default_config"
-- attempt to load and merge a user config
@ -40,7 +40,7 @@ M.load_config = function()
return conf
end
M.map = function(mode, keys, command, opt)
nvchad.map = function(mode, keys, command, opt)
local options = { silent = true }
if opt then
@ -49,7 +49,7 @@ M.map = function(mode, keys, command, opt)
if type(keys) == "table" then
for _, keymap in ipairs(keys) do
M.map(mode, keymap, command, opt)
nvchad.map(mode, keymap, command, opt)
end
return
end
@ -58,7 +58,7 @@ M.map = function(mode, keys, command, opt)
end
-- load plugin after entering vim ui
M.packer_lazy_load = function(plugin, timer)
nvchad.packer_lazy_load = function(plugin, timer)
if plugin then
timer = timer or 0
vim.defer_fn(function()
@ -68,8 +68,8 @@ M.packer_lazy_load = function(plugin, timer)
end
-- remove plugins defined in chadrc
M.remove_default_plugins = function(plugins)
local removals = require("core.utils").load_config().plugins.remove or {}
nvchad.remove_default_plugins = function(plugins)
local removals = nvchad.load_config().plugins.remove or {}
if not vim.tbl_isempty(removals) then
for _, plugin in pairs(removals) do
plugins[plugin] = nil
@ -79,8 +79,8 @@ M.remove_default_plugins = function(plugins)
end
-- merge default/user plugin tables
M.plugin_list = function(default_plugins)
local user_plugins = require("core.utils").load_config().plugins.user
nvchad.plugin_list = function(default_plugins)
local user_plugins = nvchad.load_config().plugins.user
-- require if string is present
local ok
@ -106,8 +106,8 @@ M.plugin_list = function(default_plugins)
return final_table
end
M.load_override = function(default_table, plugin_name)
local user_table = require("core.utils").load_config().plugins.override[plugin_name]
nvchad.load_override = function(default_table, plugin_name)
local user_table = nvchad.load_config().plugins.override[plugin_name]
if type(user_table) == "table" then
default_table = vim.tbl_deep_extend("force", default_table, user_table)
else
@ -115,5 +115,3 @@ M.load_override = function(default_table, plugin_name)
end
return default_table
end
return M

View File

@ -72,7 +72,7 @@ options.buttons = {
},
}
options = require("core.utils").load_override(options, "goolord/alpha-nvim")
options = nvchad.load_override(options, "goolord/alpha-nvim")
-- dynamic header padding
local fn = vim.fn

View File

@ -65,6 +65,6 @@ local options = {
}
-- check for any override
options = require("core.utils").load_override(options, "akinsho/bufferline.nvim")
options = nvchad.load_override(options, "akinsho/bufferline.nvim")
bufferline.setup(options)

View File

@ -93,6 +93,6 @@ local options = {
}
-- check for any override
options = require("core.utils").load_override(options, "hrsh7th/nvim-cmp")
options = nvchad.load_override(options, "hrsh7th/nvim-cmp")
cmp.setup(options)

View File

@ -118,6 +118,6 @@ local options = {
}
-- check for any override
options = require("core.utils").load_override(options, "kyazdani42/nvim-web-devicons")
options = nvchad.load_override(options, "kyazdani42/nvim-web-devicons")
devicons.setup(options)

View File

@ -31,6 +31,6 @@ local options = {
max_concurrent_installers = 20,
}
options = require("core.utils").load_override(options, "williamboman/nvim-lsp-installer")
options = nvchad.load_override(options, "williamboman/nvim-lsp-installer")
lsp_installer.setup(options)

View File

@ -54,7 +54,7 @@ lspconfig.sumneko_lua.setup {
}
-- requires a file containing user's lspconfigs
local addlsp_confs = require("core.utils").load_config().plugins.options.lspconfig.setup_lspconf
local addlsp_confs = nvchad.load_config().plugins.options.lspconfig.setup_lspconf
if #addlsp_confs ~= 0 then
require(addlsp_confs).setup_lsp(M.on_attach, capabilities)

View File

@ -80,6 +80,6 @@ local options = {
}
-- check for any override
options = require("core.utils").load_override(options, "kyazdani42/nvim-tree.lua")
options = nvchad.load_override(options, "kyazdani42/nvim-tree.lua")
nvimtree.setup(options)

View File

@ -38,6 +38,6 @@ local options = {
enable_new_mappings = true,
}
options = require("core.utils").load_override(options, "NvChad/nvterm")
options = nvchad.load_override(options, "NvChad/nvterm")
nvterm.setup(options)

View File

@ -32,7 +32,7 @@ M.better_escape = function()
keys = "<Esc>",
}
options = require("core.utils").load_override(options, "max397574/better-escape.nvim")
options = nvchad.load_override(options, "max397574/better-escape.nvim")
escape.setup(options)
end
@ -63,7 +63,7 @@ M.blankline = function()
show_first_indent_level = false,
}
options = require("core.utils").load_override(options, "lukas-reineke/indent-blankline.nvim")
options = nvchad.load_override(options, "lukas-reineke/indent-blankline.nvim")
blankline.setup(options)
end
@ -93,7 +93,7 @@ M.colorizer = function()
},
}
options = require("core.utils").load_override(options, "NvChad/nvim-colorizer.lua")
options = nvchad.load_override(options, "NvChad/nvim-colorizer.lua")
colorizer.setup(options["filetypes"], options["user_default_options"])
vim.cmd "ColorizerReloadAllBuffers"
@ -149,7 +149,7 @@ M.signature = function()
padding = "", -- character to pad on left and right of signature can be ' ', or '|' etc
}
options = require("core.utils").load_override(options, "ray-x/lsp_signature.nvim")
options = nvchad.load_override(options, "ray-x/lsp_signature.nvim")
lsp_signature.setup(options)
end

View File

@ -51,8 +51,7 @@ options.icon_styles = {
},
}
options.separator_style =
options.icon_styles[require("core.utils").load_config().plugins.options.statusline.separator_style]
options.separator_style = options.icon_styles[nvchad.load_config().plugins.options.statusline.separator_style]
options.main_icon = {
provider = options.separator_style.main_icon,
@ -345,7 +344,7 @@ options.current_line = {
},
}
options = require("core.utils").load_override(options, "feline-nvim/feline.nvim")
options = nvchad.load_override(options, "feline-nvim/feline.nvim")
local function add_table(tbl, inject)
if inject then

View File

@ -57,7 +57,7 @@ local options = {
}
-- check for any override
options = require("core.utils").load_override(options, "nvim-telescope/telescope.nvim")
options = nvchad.load_override(options, "nvim-telescope/telescope.nvim")
telescope.setup(options)
-- load extensions

View File

@ -16,6 +16,6 @@ local options = {
}
-- check for any override
options = require("core.utils").load_override(options, "nvim-treesitter/nvim-treesitter")
options = nvchad.load_override(options, "nvim-treesitter/nvim-treesitter")
treesitter.setup(options)

View File

@ -1,4 +1,4 @@
local plugin_settings = require("core.utils").load_config().plugins
local plugin_settings = nvchad.load_config().plugins
local present, packer = pcall(require, plugin_settings.options.packer.init_file)
if not present then
@ -87,7 +87,7 @@ local plugins = {
require("plugins.configs.others").gitsigns()
end,
setup = function()
require("core.utils").packer_lazy_load "gitsigns.nvim"
nvchad.packer_lazy_load "gitsigns.nvim"
end,
},
@ -96,7 +96,7 @@ local plugins = {
["williamboman/nvim-lsp-installer"] = {
opt = true,
setup = function()
require("core.utils").packer_lazy_load "nvim-lsp-installer"
nvchad.packer_lazy_load "nvim-lsp-installer"
-- reload the current file so lsp actually starts for it
vim.defer_fn(function()
vim.cmd 'if &ft == "packer" | echo "" | else | silent! e %'
@ -123,7 +123,7 @@ local plugins = {
["andymass/vim-matchup"] = {
opt = true,
setup = function()
require("core.utils").packer_lazy_load "vim-matchup"
nvchad.packer_lazy_load "vim-matchup"
end,
},
@ -229,9 +229,9 @@ local plugins = {
},
}
plugins = require("core.utils").remove_default_plugins(plugins)
plugins = nvchad.remove_default_plugins(plugins)
-- merge user plugin table & default plugin table
plugins = require("core.utils").plugin_list(plugins)
plugins = nvchad.plugin_list(plugins)
return packer.startup(function(use)
for _, v in pairs(plugins) do

View File

@ -27,7 +27,7 @@ if not present then
end
end
local user_snapshot = require("core.utils").load_config().snapshot
local user_snapshot = nvchad.load_config().snapshot
packer.init {
display = {