2022-06-18 04:27:17 +00:00
|
|
|
local M = {}
|
2022-06-24 13:54:59 +00:00
|
|
|
local autocmd = vim.api.nvim_create_autocmd
|
2022-06-18 04:27:17 +00:00
|
|
|
|
2022-07-25 13:49:33 +00:00
|
|
|
-- require("packer").loader(tb.plugins)
|
2022-07-15 04:07:12 +00:00
|
|
|
-- This must be used for plugins that need to be loaded just after a file
|
|
|
|
-- ex : treesitter, lspconfig etc
|
2022-06-18 04:27:17 +00:00
|
|
|
M.lazy_load = function(tb)
|
2022-08-15 10:42:27 +00:00
|
|
|
autocmd(tb.events, {
|
|
|
|
group = vim.api.nvim_create_augroup(tb.augroup_name, {}),
|
|
|
|
callback = function()
|
|
|
|
if tb.condition() then
|
|
|
|
vim.api.nvim_del_augroup_by_name(tb.augroup_name)
|
2022-06-14 12:06:27 +00:00
|
|
|
|
2022-08-15 10:42:27 +00:00
|
|
|
-- dont defer for treesitter as it will show slow highlighting
|
|
|
|
-- This deferring only happens only when we do "nvim filename"
|
|
|
|
if tb.plugin ~= "nvim-treesitter" then
|
|
|
|
vim.defer_fn(function()
|
|
|
|
require("packer").loader(tb.plugin)
|
|
|
|
if tb.plugin == "nvim-lspconfig" then
|
|
|
|
vim.cmd "silent! do FileType"
|
|
|
|
end
|
|
|
|
end, 0)
|
|
|
|
else
|
|
|
|
require("packer").loader(tb.plugin)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
2022-06-14 12:06:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- load certain plugins only when there's a file opened in the buffer
|
2022-06-18 04:27:17 +00:00
|
|
|
-- if "nvim filename" is executed -> load the plugin after nvim gui loads
|
2022-06-14 12:06:27 +00:00
|
|
|
-- This gives an instant preview of nvim with the file opened
|
|
|
|
|
2022-06-18 04:27:17 +00:00
|
|
|
M.on_file_open = function(plugin_name)
|
2022-08-15 10:42:27 +00:00
|
|
|
M.lazy_load {
|
|
|
|
events = { "BufRead", "BufWinEnter", "BufNewFile" },
|
|
|
|
augroup_name = "BeLazyOnFileOpen" .. plugin_name,
|
|
|
|
plugin = plugin_name,
|
|
|
|
condition = function()
|
|
|
|
local file = vim.fn.expand "%"
|
|
|
|
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
|
|
|
|
end,
|
|
|
|
}
|
2022-06-14 12:06:27 +00:00
|
|
|
end
|
|
|
|
|
2022-08-07 07:28:16 +00:00
|
|
|
M.packer_cmds = {
|
2022-08-15 10:42:27 +00:00
|
|
|
"PackerSnapshot",
|
|
|
|
"PackerSnapshotRollback",
|
|
|
|
"PackerSnapshotDelete",
|
|
|
|
"PackerInstall",
|
|
|
|
"PackerUpdate",
|
|
|
|
"PackerSync",
|
|
|
|
"PackerClean",
|
|
|
|
"PackerCompile",
|
|
|
|
"PackerStatus",
|
|
|
|
"PackerProfile",
|
|
|
|
"PackerLoad",
|
2022-08-07 07:28:16 +00:00
|
|
|
}
|
|
|
|
|
2022-09-30 04:23:47 +00:00
|
|
|
M.treesitter_cmds = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSEnable", "TSDisable", "TSModuleInfo" }
|
|
|
|
M.mason_cmds = { "Mason", "MasonInstall", "MasonInstallAll", "MasonUninstall", "MasonUninstallAll", "MasonLog" }
|
2022-07-25 13:49:33 +00:00
|
|
|
|
2022-06-14 12:06:27 +00:00
|
|
|
M.gitsigns = function()
|
2022-08-15 10:42:27 +00:00
|
|
|
autocmd({ "BufRead" }, {
|
2022-09-08 11:49:47 +00:00
|
|
|
group = vim.api.nvim_create_augroup("GitSignsLazyLoad", { clear = true }),
|
2022-08-15 10:42:27 +00:00
|
|
|
callback = function()
|
2022-08-24 02:47:40 +00:00
|
|
|
vim.fn.system("git rev-parse " .. vim.fn.expand "%:p:h")
|
2022-08-15 10:42:27 +00:00
|
|
|
if vim.v.shell_error == 0 then
|
2022-09-08 11:49:47 +00:00
|
|
|
vim.api.nvim_del_augroup_by_name "GitSignsLazyLoad"
|
2022-08-15 10:42:27 +00:00
|
|
|
vim.schedule(function()
|
|
|
|
require("packer").loader "gitsigns.nvim"
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
2022-06-14 12:06:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|