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

@ -19,7 +19,7 @@ M.init = function(theme)
package.loaded["colors.highlights" or false] = nil package.loaded["colors.highlights" or false] = nil
-- then load the highlights -- then load the highlights
require "colors.highlights" require "colors.highlights"
end end
end end
-- returns a table of colors for givem or current theme -- returns a table of colors for givem or current theme

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

@ -14,7 +14,7 @@ opt.shiftwidth = options.shiftwidth
opt.smartindent = options.smartindent opt.smartindent = options.smartindent
-- disable tilde on end of buffer: https://github.com/neovim/neovim/pull/8546#issuecomment-643643758 -- disable tilde on end of buffer: https://github.com/neovim/neovim/pull/8546#issuecomment-643643758
opt.fillchars = options.fillchars opt.fillchars = options.fillchars
opt.hidden = options.hidden opt.hidden = options.hidden
opt.ignorecase = options.ignorecase opt.ignorecase = options.ignorecase

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

@ -13,7 +13,7 @@ g.nvim_tree_highlight_opened_files = 0
g.nvim_tree_indent_markers = 1 g.nvim_tree_indent_markers = 1
g.nvim_tree_quit_on_open = 0 -- closes tree when file's opened g.nvim_tree_quit_on_open = 0 -- closes tree when file's opened
g.nvim_tree_root_folder_modifier = table.concat { ":t:gs?$?/..", string.rep(" ", 1000), "?:gs?^??" } g.nvim_tree_root_folder_modifier = table.concat { ":t:gs?$?/..", string.rep(" ", 1000), "?:gs?^??" }
g.nvim_tree_window_picker_exclude = { g.nvim_tree_window_picker_exclude = {
filetype = { "notify", "packer", "qf" }, filetype = { "notify", "packer", "qf" },
buftype = { "terminal" }, buftype = { "terminal" },

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