From d810cc35a7026c4b3723665a2730f7f753f899ea Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Sat, 2 Oct 2021 10:45:50 +0530 Subject: [PATCH] chore: format files --- lua/core/custom.lua | 32 ++++++++-------- lua/core/hooks.lua | 91 ++++++++++++++++++++++----------------------- lua/core/init.lua | 4 +- lua/core/utils.lua | 2 +- 4 files changed, 64 insertions(+), 65 deletions(-) diff --git a/lua/core/custom.lua b/lua/core/custom.lua index 05a7329..c058061 100644 --- a/lua/core/custom.lua +++ b/lua/core/custom.lua @@ -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" diff --git a/lua/core/hooks.lua b/lua/core/hooks.lua index 8c7f351..2602ff7 100644 --- a/lua/core/hooks.lua +++ b/lua/core/hooks.lua @@ -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 diff --git a/lua/core/init.lua b/lua/core/init.lua index 819bc51..dc1198c 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -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" diff --git a/lua/core/utils.lua b/lua/core/utils.lua index 188f6a1..bab04fc 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -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