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)
if package.loaded[name] then
return true
else
for _, searcher in ipairs(package.searchers or package.loaders) do
local loader = searcher(name)
if type(loader) == 'function' then
package.preload[name] = loader
return true
if package.loaded[name] then
return true
else
for _, searcher in ipairs(package.searchers or package.loaders) do
local loader = searcher(name)
if type(loader) == "function" then
package.preload[name] = loader
return true
end
end
end
return false
end
return false
end
end
local loadIfExists = function (module)
if isModuleAvailable(module) then
require(module)
end
local loadIfExists = function(module)
if isModuleAvailable(module) then
require(module)
end
end
loadIfExists('custom')
loadIfExists "custom"

View File

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

View File

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

View File

@ -269,7 +269,7 @@ end]]
local fn = base_fn:gsub("_node", node)
-- return the function created from the string base_fn
return loadstring(fn)()(table1, table2)
end
end
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