diff --git a/lua/lualine/utils/loader.lua b/lua/lualine/utils/loader.lua index 6220006..77ecf09 100644 --- a/lua/lualine/utils/loader.lua +++ b/lua/lualine/utils/loader.lua @@ -8,7 +8,7 @@ local modules = lualine_require.lazy_require{ } local is_valid_filename = lualine_require.is_valid_filename -local sep = package.config:sub(1,1) +local sep = lualine_require.sep local component_types = { luaf = function(component) @@ -132,20 +132,11 @@ local function load_all(config) load_extensions(config) end -local function rtp_searcher(file) - local ret = {} - for dir in vim.gsplit(vim.api.nvim_get_option('rtp'), ',') do - local path = dir .. sep .. file - if vim.loop.fs_stat(path) then ret[#ret+1] = path end - end - return ret -end - local function load_theme(theme_name) assert(is_valid_filename(theme_name), "Invalid filename") local retval local path = table.concat({'lua', 'lualine', 'themes', theme_name}, sep)..'.lua' - local files = rtp_searcher(path) + local files = lualine_require.rtp_searcher(path) local n_files = #files if n_files == 0 then -- No match found diff --git a/lua/lualine_require.lua b/lua/lualine_require.lua index b5468c8..a3159c9 100644 --- a/lua/lualine_require.lua +++ b/lua/lualine_require.lua @@ -18,8 +18,9 @@ end function M.require(module) if package.loaded[module] then return package.loaded[module] end + local pattern = module:gsub('%.', M.sep) .. '.lua' if M.plugin_dir then - local path = M.plugin_dir .. module:gsub('%.', M.sep) .. '.lua' + local path = M.plugin_dir .. pattern assert(M.is_valid_filename(module), "Invalid filename") if vim.loop.fs_stat(path) then local mod_result = dofile(path) @@ -27,9 +28,29 @@ function M.require(module) return mod_result end end + + local paths = M.rtp_searcher('lua'..M.sep..pattern, true) + if #paths > 0 then + local mod_result = dofile(paths[1]) + package.loaded[module] = mod_result + return mod_result + end + return require(module) end +function M.rtp_searcher(file, once) + local ret = {} + for dir in vim.gsplit(vim.api.nvim_get_option('rtp'), ',') do + local path = dir .. M.sep .. file + if vim.loop.fs_stat(path) then + ret[#ret+1] = path + if once then break end + end + end + return ret +end + function M.lazy_require(modules) return setmetatable({}, { __index = function(self, key)