improved plugin lazy loading
This commit is contained in:
@@ -26,7 +26,7 @@ mapn("<C-l>", wincmd "l")
|
|||||||
mapleader("s", vim.cmd.source)
|
mapleader("s", vim.cmd.source)
|
||||||
mapleader("w", vim.cmd.write)
|
mapleader("w", vim.cmd.write)
|
||||||
mapleader("f", vim.lsp.buf.format)
|
mapleader("f", vim.lsp.buf.format)
|
||||||
mapleader("o", oil().open)
|
mapleader("o", function() oil.open() end)
|
||||||
mapleader("pf", pick().builtin.files)
|
mapleader("pf", function() pick.builtin.files() end)
|
||||||
mapleader("pg", pick().builtin.grep_live)
|
mapleader("pg", function() pick.builtin.grep_live() end)
|
||||||
mapleader("ph", pick().builtin.help)
|
mapleader("ph", function() pick.builtin.help() end)
|
||||||
|
@@ -1,18 +1,28 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M.setup(module, opts)
|
function M.setup(module, opts)
|
||||||
local loaded = false
|
|
||||||
local instance = nil
|
local instance = nil
|
||||||
return function()
|
|
||||||
if not loaded then
|
local function setup()
|
||||||
|
if instance == nil then
|
||||||
instance = require(module)
|
instance = require(module)
|
||||||
if instance.setup then
|
if instance.setup then
|
||||||
instance.setup(opts or {})
|
instance.setup(opts or {})
|
||||||
end
|
end
|
||||||
loaded = true
|
|
||||||
end
|
|
||||||
return instance
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return setmetatable({}, {
|
||||||
|
__index = function(_, key)
|
||||||
|
setup()
|
||||||
|
return instance[key]
|
||||||
|
end,
|
||||||
|
|
||||||
|
__call = function(_, ...)
|
||||||
|
setup()
|
||||||
|
return instance(...)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Reference in New Issue
Block a user