Cleanup | Format files

* fix some lint warnings
* remove some unneeded code
This commit is contained in:
Akianonymus 2021-12-11 01:49:35 +05:30 committed by siduck
parent 773d25980c
commit 2293b16709
7 changed files with 28 additions and 40 deletions

View File

@ -1,8 +1,5 @@
local userconf = pcall(require, "custom") -- try to call cuatom init
pcall(require, "custom")
if userconf then
require "custom"
end
local core_modules = { local core_modules = {
"core.options", "core.options",

View File

@ -1,31 +1,23 @@
local hooks, M = {}, {} local hooks, M = {}, {}
local allowed_hooks = { local allowed_hooks = {
"install_plugins", ["install_plugins"] = true,
"setup_mappings", ["setup_mappings"] = true,
"ready", ["ready"] = true,
} }
local function has_value(tab, val)
for _, value in ipairs(tab) do
if value == val then
return true
end
end
end
M.add = function(name, fn) M.add = function(name, fn)
if not (has_value(allowed_hooks, name)) then if not allowed_hooks[name] then
print("Custom lua uses unallowed hook " .. name) print("Custom lua uses unallowed hook " .. name)
end end
if hooks[name] == nil then if not hooks[name] then
hooks[name] = {} hooks[name] = {}
end end
table.insert(hooks[name], fn) table.insert(hooks[name], fn)
end end
M.run = function(name, args) M.run = function(name, args)
if hooks[name] ~= nil then if hooks[name] then
for _, hook in pairs(hooks[name]) do for _, hook in pairs(hooks[name]) do
hook(args) hook(args)
end end

View File

@ -1,7 +1,7 @@
local M = {} local M = {}
local cmd = vim.cmd local cmd = vim.cmd
M.close_buffer = function(bufexpr, force) M.close_buffer = function(force)
-- This is a modification of a NeoVim plugin from -- This is a modification of a NeoVim plugin from
-- Author: ojroques - Olivier Roques -- Author: ojroques - Olivier Roques
-- Src: https://github.com/ojroques/nvim-bufdel -- Src: https://github.com/ojroques/nvim-bufdel
@ -63,7 +63,7 @@ M.close_buffer = function(bufexpr, force)
return return
end end
local chad_term, type = pcall(function() local chad_term, _ = pcall(function()
return vim.api.nvim_buf_get_var(buf, "term_type") return vim.api.nvim_buf_get_var(buf, "term_type")
end) end)
@ -140,21 +140,18 @@ end
M.load_config = function() M.load_config = function()
local conf = require "core.default_config" local conf = require "core.default_config"
local chadrcExists, _ = pcall(require, "custom.chadrc") local chadrcExists, change = pcall(require, "custom.chadrc")
-- if chadrc exists , then merge its table into the default config's -- if chadrc exists , then merge its table into the default config's
if chadrcExists then if chadrcExists then
local change = require "custom.chadrc"
conf = vim.tbl_deep_extend("force", conf, change) conf = vim.tbl_deep_extend("force", conf, change)
return conf
end end
-- or load default config
return conf return conf
end end
M.map = function(mode, keys, cmd, opt) M.map = function(mode, keys, command, opt)
local options = { noremap = true, silent = true } local options = { noremap = true, silent = true }
if opt then if opt then
options = vim.tbl_extend("force", options, opt) options = vim.tbl_extend("force", options, opt)
@ -178,28 +175,30 @@ M.map = function(mode, keys, cmd, opt)
-- helper function for M.map -- helper function for M.map
-- can gives multiple modes and keys -- can gives multiple modes and keys
local function map_wrapper(mode, lhs, rhs, options) local function map_wrapper(sub_mode, lhs, rhs, sub_options)
if type(lhs) == "table" then if type(lhs) == "table" then
for _, key in ipairs(lhs) do for _, key in ipairs(lhs) do
map_wrapper(mode, key, rhs, options) map_wrapper(sub_mode, key, rhs, sub_options)
end end
else else
if type(mode) == "table" then if type(sub_mode) == "table" then
for _, m in ipairs(mode) do for _, m in ipairs(sub_mode) do
map_wrapper(m, lhs, rhs, options) map_wrapper(m, lhs, rhs, sub_options)
end end
else else
if valid_modes[mode] and lhs and rhs then if valid_modes[sub_mode] and lhs and rhs then
vim.api.nvim_set_keymap(mode, lhs, rhs, options) vim.api.nvim_set_keymap(sub_mode, lhs, rhs, sub_options)
else else
mode, lhs, rhs = mode or "", lhs or "", rhs or "" sub_mode, lhs, rhs = sub_mode or "", lhs or "", rhs or ""
print("Cannot set mapping [ mode = '" .. mode .. "' | key = '" .. lhs .. "' | cmd = '" .. rhs .. "' ]") print(
"Cannot set mapping [ mode = '" .. sub_mode .. "' | key = '" .. lhs .. "' | cmd = '" .. rhs .. "' ]"
)
end end
end end
end end
end end
map_wrapper(mode, keys, cmd, options) map_wrapper(mode, keys, command, options)
end end
-- load plugin after entering vim ui -- load plugin after entering vim ui

View File

@ -132,7 +132,7 @@ M.lsp_handlers = function()
}) })
-- suppress error messages from lang servers -- suppress error messages from lang servers
vim.notify = function(msg, log_level, _opts) vim.notify = function(msg, log_level)
if msg:match "exit code" then if msg:match "exit code" then
return return
end end