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,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