chore: format files

This commit is contained in:
Akianonymus 2021-10-02 10:45:50 +05:30 committed by siduck76
parent 317eedd9b2
commit d810cc35a7
4 changed files with 64 additions and 65 deletions

View File

@ -1,22 +1,22 @@
local function isModuleAvailable(name) local function isModuleAvailable(name)
if package.loaded[name] then if package.loaded[name] then
return true return true
else else
for _, searcher in ipairs(package.searchers or package.loaders) do for _, searcher in ipairs(package.searchers or package.loaders) do
local loader = searcher(name) local loader = searcher(name)
if type(loader) == 'function' then if type(loader) == "function" then
package.preload[name] = loader package.preload[name] = loader
return true return true
end
end end
end return false
return false end
end
end end
local loadIfExists = function (module) local loadIfExists = function(module)
if isModuleAvailable(module) then if isModuleAvailable(module) then
require(module) require(module)
end end
end end
loadIfExists('custom') loadIfExists "custom"

View File

@ -1,69 +1,68 @@
local hooks, overrides, M = {}, {}, {}; local hooks, overrides, M = {}, {}, {}
local allowed_hooks = { local allowed_hooks = {
"install_plugins", "install_plugins",
"setup_mappings", "setup_mappings",
"ready", "ready",
} }
local function has_value (tab, val) local function has_value(tab, val)
for _, value in ipairs(tab) do for _, value in ipairs(tab) do
if value == val then if value == val then
return true return true
end end
end end
return false return false
end end
M.add = function(name, fn) M.add = function(name, fn)
if not(has_value(allowed_hooks, name)) then if not (has_value(allowed_hooks, name)) then
error("Custom lua uses unallowed hook " .. name) error("Custom lua uses unallowed hook " .. name)
end end
if hooks[name] == nil then if hooks[name] == nil 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] == nil then
return; return
end end
for _, hook in pairs(hooks[name]) do for _, hook in pairs(hooks[name]) do
hook(args) hook(args)
end end
end end
M.createOverrides = function(module) M.createOverrides = function(module)
local O = {}; local O = {}
O.get = function(name, default) O.get = function(name, default)
local current = default; local current = default
if overrides[module] and overrides[module][name] then if overrides[module] and overrides[module][name] then
if type(overrides[module][name]) == "function" then if type(overrides[module][name]) == "function" then
current = overrides[module][name] current = overrides[module][name]
elseif type(overrides[module][name]) == "table" then elseif type(overrides[module][name]) == "table" then
for _, override in pairs(overrides[module][name]) do for _, override in pairs(overrides[module][name]) do
current = override(current) current = override(current)
end
end end
end end
end return current
return current; end
end
return O; return O
end end
M.override = function(module, name, overwrite) M.override = function(module, name, overwrite)
if overrides[module] == nil then if overrides[module] == nil then
overrides[module] = {}; overrides[module] = {}
end end
if overrides[module][name] == nil then if overrides[module][name] == nil then
overrides[module][name] = {}; overrides[module][name] = {}
end end
table.insert(overrides[module][name], overwrite) table.insert(overrides[module][name], overwrite)
end end
return M
return M;

View File

@ -5,7 +5,7 @@ local core_modules = {
"core.mappings", "core.mappings",
} }
local hooks = require('core.hooks'); local hooks = require "core.hooks"
for _, module in ipairs(core_modules) do for _, module in ipairs(core_modules) do
local ok, err = pcall(require, module) local ok, err = pcall(require, module)
@ -17,4 +17,4 @@ end
-- set all the non plugin mappings -- set all the non plugin mappings
require("core.mappings").misc() require("core.mappings").misc()
hooks.run("ready") hooks.run "ready"

View File

@ -269,7 +269,7 @@ end]]
local fn = base_fn:gsub("_node", node) local fn = base_fn:gsub("_node", node)
-- return the function created from the string base_fn -- return the function created from the string base_fn
return loadstring(fn)()(table1, table2) return loadstring(fn)()(table1, table2)
end end
for _, node in ipairs(nodes_to_replace) do for _, node in ipairs(nodes_to_replace) do
-- pcall() is a poor workaround for if "['mappings']['plugins']['esc_insertmode']" 'plugins' sub-table does not exist -- pcall() is a poor workaround for if "['mappings']['plugins']['esc_insertmode']" 'plugins' sub-table does not exist