improved plugin lazy loading
This commit is contained in:
@@ -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)
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user