Skip to content

Commit

Permalink
feat(utils): add load_config() to resolve and load user.configs
Browse files Browse the repository at this point in the history
  • Loading branch information
misumisumi committed Aug 12, 2023
1 parent 5722cf1 commit f95d110
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
11 changes: 1 addition & 10 deletions lua/core/pack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ function Lazy:load_plugins()
local append_nativertp = function()
package.path = package.path
.. string.format(";%s;%s", modules_dir .. "/configs/?.lua", modules_dir .. "/configs/?/init.lua")
table.insert(package.loaders, function(modulename)
local modulepath = user_config_dir .. "/configs/" .. modulename:gsub("%.", "/") .. ".lua"
local filename = modulepath:gsub("%?", modulepath)
local file = io.open(filename, "rb")
if file then
return assert(load(assert(file:read("*a")), filename))
end
return string.format("\n\tno file '%s' (checked with custom loader)", filename)
end)
end

local get_plugins_list = function()
Expand Down Expand Up @@ -140,4 +131,4 @@ function Lazy:load_lazy()
require("lazy").setup(self.modules, lazy_settings)
end

Lazy:load_lazy()
Lazy:load_lazy()
9 changes: 8 additions & 1 deletion lua/modules/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ function M.extend_config(config, user_config)
return config
end

---@param modname string @Module name of the config
---@return unknown
---@return unknown @Loader data
M.load_config = function(modname)
return require("user.configs." .. modname)
end

---@param plugin_name string @Module name of the plugin (used to setup itself)
---@param opts nil|table @The default config to be merged with
---@param vim_plugin? boolean @If this plugin is a vimscript one
Expand Down Expand Up @@ -349,4 +356,4 @@ We received a `%s` for plugin <%s>.]],
end
end

return M
return M

0 comments on commit f95d110

Please sign in to comment.