From 4e54ee0081babd3138180bb61ea093fcac03fd46 Mon Sep 17 00:00:00 2001 From: siduck Date: Fri, 7 Jan 2022 19:58:05 +0530 Subject: [PATCH] rm hooks --- examples/{example_chadrc.lua => chadrc.lua} | 5 ++-- examples/{example_init.lua => init.lua} | 25 +++++++------------- lua/core/customPlugins.lua | 15 ++++++++++++ lua/core/hooks.lua | 26 --------------------- lua/core/mappings.lua | 2 -- lua/plugins/init.lua | 2 +- 6 files changed, 26 insertions(+), 49 deletions(-) rename examples/{example_chadrc.lua => chadrc.lua} (76%) rename examples/{example_init.lua => init.lua} (50%) create mode 100644 lua/core/customPlugins.lua delete mode 100644 lua/core/hooks.lua diff --git a/examples/example_chadrc.lua b/examples/chadrc.lua similarity index 76% rename from examples/example_chadrc.lua rename to examples/chadrc.lua index e810f1c..6967664 100644 --- a/examples/example_chadrc.lua +++ b/examples/chadrc.lua @@ -1,5 +1,4 @@ --- This is an example chadrc file , its supposed to be placed in /lua/custom dir --- lua/custom/chadrc.lua +-- This is an example chadrc file , its supposed to be placed in /lua/custom/ local M = {} @@ -7,7 +6,7 @@ local M = {} -- example of changing theme: M.ui = { - theme = "gruvchad", + theme = "onedark", } return M diff --git a/examples/example_init.lua b/examples/init.lua similarity index 50% rename from examples/example_init.lua rename to examples/init.lua index 2425cc2..7d6e529 100644 --- a/examples/example_init.lua +++ b/examples/init.lua @@ -1,28 +1,19 @@ --- This is an example init file , its supposed to be placed in /lua/custom dir --- lua/custom/init.lua +-- This is an example init file , its supposed to be placed in /lua/custom/ -- This is where your custom modules and plugins go. -- Please check NvChad docs if you're totally new to nvchad + dont know lua!! -local hooks = require "core.hooks" - -- MAPPINGS --- To add new plugins, use the "setup_mappings" hook, +local map = require("core.utils").map -hooks.add("setup_mappings", function(map) - map("n", "cc", ":Telescope ", opt) - map("n", "q", ":q ", opt) -end) - --- NOTE : opt is a variable there (most likely a table if you want multiple options), --- you can remove it if you dont have any custom options +map("n", "cc", ":Telescope ") +map("n", "q", ":q ") +-- NOTE: the 4th argument in the map function can be a table i.e options but its most likely un-needed so dont worry about it -- Install plugins --- To add new plugins, use the "install_plugins" hook, +local customPlugins = require "core.customPlugins" --- examples below: - -hooks.add("install_plugins", function(use) +customPlugins.add(function(use) use { "max397574/better-escape.nvim", event = "InsertEnter", @@ -34,6 +25,6 @@ hooks.add("install_plugins", function(use) } end) --- NOTE: we heavily suggest using Packer's lazy loading (with the 'event' field) +-- NOTE: we heavily suggest using Packer's lazy loading (with the 'event','cmd' fields) -- see: https://github.com/wbthomason/packer.nvim -- https://nvchad.github.io/config/walkthrough diff --git a/lua/core/customPlugins.lua b/lua/core/customPlugins.lua new file mode 100644 index 0000000..c667936 --- /dev/null +++ b/lua/core/customPlugins.lua @@ -0,0 +1,15 @@ +local M = {} +local plugins = {} + +M.add = function(fn) + table.insert(plugins, fn) +end + +-- load custom plugins in packer startup function +M.run = function(args) + for _, hook in pairs(plugins) do + hook(args) + end +end + +return M diff --git a/lua/core/hooks.lua b/lua/core/hooks.lua deleted file mode 100644 index a4f9be3..0000000 --- a/lua/core/hooks.lua +++ /dev/null @@ -1,26 +0,0 @@ -local hooks, M = {}, {} - -local allowed_hooks = { - ["install_plugins"] = true, - ["setup_mappings"] = true, -} - -M.add = function(name, fn) - if not allowed_hooks[name] then - print("Custom lua uses unallowed hook " .. name) - end - if not hooks[name] then - hooks[name] = {} - end - table.insert(hooks[name], fn) -end - -M.run = function(name, args) - if hooks[name] then - for _, hook in pairs(hooks[name]) do - hook(args) - end - end -end - -return M diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 93f74e1..a8efc95 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -1,5 +1,4 @@ local utils = require "core.utils" -local hooks = require "core.hooks" local config = utils.load_config() local map = utils.map @@ -110,7 +109,6 @@ M.misc = function() non_config_mappings() optional_mappings() required_mappings() - hooks.run("setup_mappings", map) end -- below are all plugin related mappings diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 6709c2b..cea8082 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -223,5 +223,5 @@ return packer.startup(function() end, } -- load user defined plugins - require("core.hooks").run("install_plugins", use) + require("core.customPlugins").run(use) end)