remove usage of globals for util functions

This commit is contained in:
siduck 2022-05-29 16:07:47 +05:30
parent 0f013d4e7b
commit cb97cef2a7
18 changed files with 55 additions and 55 deletions

View file

@ -71,7 +71,7 @@ M.bufferline = {
-- close buffer + hide terminal buffer
["<leader>x"] = {
function()
nvchad.close_buffer()
require("core.utils").close_buffer()
end,
" close buffer",
},

View file

@ -1,7 +1,7 @@
local opt = vim.opt
local g = vim.g
g.nvchad_theme = nvchad.load_config().ui.theme
g.nvchad_theme = require("core.utils").load_config().ui.theme
-- use filetype.lua instead of filetype.vim
g.did_load_filetypes = 0
@ -86,4 +86,4 @@ vim.schedule(function()
end)
-- load user options if the file exists
nvchad.load_config().options.user()
require("core.utils").load_config().options.user()

View file

@ -37,7 +37,7 @@ M.options = {
}
-- merge overrides if there are any
M.options = nvchad.load_override(M.options, "wbthomason/packer.nvim")
M.options = require("core.utils").load_override(M.options, "wbthomason/packer.nvim")
M.run = function(plugins)
local present, packer = pcall(require, "packer")
@ -47,8 +47,8 @@ M.run = function(plugins)
end
-- Override with chadrc values
plugins = nvchad.remove_default_plugins(plugins)
plugins = nvchad.merge_plugins(plugins)
plugins = require("core.utils").remove_default_plugins(plugins)
plugins = require("core.utils").merge_plugins(plugins)
packer.init(M.options)

View file

@ -1,8 +1,8 @@
_G.nvchad = {}
local M = {}
local merge_tb = vim.tbl_deep_extend
nvchad.close_buffer = function(force)
M.close_buffer = function(force)
if vim.bo.buftype == "terminal" then
vim.api.nvim_win_hide(0)
return
@ -24,14 +24,14 @@ nvchad.close_buffer = function(force)
vim.cmd(close_cmd)
end
nvchad.load_config = function()
M.load_config = function()
local config = require "core.default_config"
local chadrc_exists, chadrc = pcall(require, "custom.chadrc")
if chadrc_exists then
-- merge user config if it exists and is a table; otherwise display an error
if type(chadrc) == "table" then
nvchad.remove_default_keys()
M.remove_default_keys()
config = merge_tb("force", config, chadrc)
else
error "chadrc must return a table!"
@ -42,7 +42,7 @@ nvchad.load_config = function()
return config
end
nvchad.remove_default_keys = function()
M.remove_default_keys = function()
local chadrc = require "custom.chadrc"
local user_mappings = chadrc.mappings or {}
local user_keys = {}
@ -73,8 +73,8 @@ nvchad.remove_default_keys = function()
end
end
nvchad.load_mappings = function(mappings, mapping_opt)
mappings = mappings or nvchad.load_config().mappings
M.load_mappings = function(mappings, mapping_opt)
mappings = mappings or M.load_config().mappings
-- set mapping function with/without whichkye
local map_func
@ -114,7 +114,7 @@ nvchad.load_mappings = function(mappings, mapping_opt)
end
-- load plugin after entering vim ui
nvchad.packer_lazy_load = function(plugin, timer)
M.packer_lazy_load = function(plugin, timer)
if plugin then
timer = timer or 0
vim.defer_fn(function()
@ -124,8 +124,8 @@ nvchad.packer_lazy_load = function(plugin, timer)
end
-- remove plugins defined in chadrc
nvchad.remove_default_plugins = function(plugins)
local removals = nvchad.load_config().plugins.remove or {}
M.remove_default_plugins = function(plugins)
local removals = M.load_config().plugins.remove or {}
if not vim.tbl_isempty(removals) then
for _, plugin in pairs(removals) do
@ -137,8 +137,8 @@ nvchad.remove_default_plugins = function(plugins)
end
-- merge default/user plugin tables
nvchad.merge_plugins = function(default_plugins)
local user_plugins = nvchad.load_config().plugins.user
M.merge_plugins = function(default_plugins)
local user_plugins = M.load_config().plugins.user
-- merge default + user plugin table
default_plugins = merge_tb("force", default_plugins, user_plugins)
@ -154,8 +154,8 @@ nvchad.merge_plugins = function(default_plugins)
return final_table
end
nvchad.load_override = function(default_table, plugin_name)
local user_table = nvchad.load_config().plugins.override[plugin_name]
M.load_override = function(default_table, plugin_name)
local user_table = M.load_config().plugins.override[plugin_name]
if type(user_table) == "table" then
default_table = merge_tb("force", default_table, user_table)
@ -165,3 +165,5 @@ nvchad.load_override = function(default_table, plugin_name)
return default_table
end
return M