improved plugin lazy loading

This commit is contained in:
2025-08-06 17:36:23 +03:00
parent 43c0df4271
commit 9372411853
2 changed files with 19 additions and 9 deletions

View File

@@ -26,7 +26,7 @@ mapn("<C-l>", wincmd "l")
mapleader("s", vim.cmd.source)
mapleader("w", vim.cmd.write)
mapleader("f", vim.lsp.buf.format)
mapleader("o", oil().open)
mapleader("pf", pick().builtin.files)
mapleader("pg", pick().builtin.grep_live)
mapleader("ph", pick().builtin.help)
mapleader("o", function() oil.open() end)
mapleader("pf", function() pick.builtin.files() end)
mapleader("pg", function() pick.builtin.grep_live() end)
mapleader("ph", function() pick.builtin.help() end)

View File

@@ -1,18 +1,28 @@
local M = {}
function M.setup(module, opts)
local loaded = false
local instance = nil
return function()
if not loaded then
local function setup()
if instance == nil then
instance = require(module)
if instance.setup then
instance.setup(opts or {})
end
loaded = true
end
return instance
end
return setmetatable({}, {
__index = function(_, key)
setup()
return instance[key]
end,
__call = function(_, ...)
setup()
return instance(...)
end,
})
end
return M