2022-06-18 06:27:17 +02:00
|
|
|
local M = {}
|
2022-06-24 15:54:59 +02:00
|
|
|
local autocmd = vim.api.nvim_create_autocmd
|
2022-06-18 06:27:17 +02:00
|
|
|
|
2022-07-25 15:49:33 +02:00
|
|
|
-- require("packer").loader(tb.plugins)
|
2022-07-15 06:07:12 +02:00
|
|
|
-- This must be used for plugins that need to be loaded just after a file
|
|
|
|
-- ex : treesitter, lspconfig etc
|
2022-06-18 06:27:17 +02:00
|
|
|
M.lazy_load = function(tb)
|
2022-07-22 18:00:00 +02: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-08-07 07:26:15 +02:00
|
|
|
require "impatient"
|
2022-06-14 14:06:27 +02:00
|
|
|
|
2022-07-22 18:00:00 +02:00
|
|
|
-- dont defer for treesitter as it will show slow highlighting
|
|
|
|
-- This deferring only happens only when we do "nvim filename"
|
2022-07-25 15:49:33 +02:00
|
|
|
if tb.plugin ~= "nvim-treesitter" then
|
2022-07-22 18:00:00 +02:00
|
|
|
vim.defer_fn(function()
|
2022-07-25 15:49:33 +02:00
|
|
|
require("packer").loader(tb.plugin)
|
|
|
|
if tb.plugin == "nvim-lspconfig" then
|
2022-07-31 16:35:43 +02:00
|
|
|
vim.cmd "silent! do FileType"
|
2022-07-25 15:49:33 +02:00
|
|
|
end
|
2022-07-22 18:00:00 +02:00
|
|
|
end, 0)
|
|
|
|
else
|
2022-07-25 15:49:33 +02:00
|
|
|
require("packer").loader(tb.plugin)
|
2022-07-22 18:00:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
2022-06-14 14:06:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- load certain plugins only when there's a file opened in the buffer
|
2022-06-18 06:27:17 +02:00
|
|
|
-- if "nvim filename" is executed -> load the plugin after nvim gui loads
|
2022-06-14 14:06:27 +02:00
|
|
|
-- This gives an instant preview of nvim with the file opened
|
|
|
|
|
2022-06-18 06:27:17 +02:00
|
|
|
M.on_file_open = function(plugin_name)
|
2022-07-22 18:00:00 +02:00
|
|
|
M.lazy_load {
|
|
|
|
events = { "BufRead", "BufWinEnter", "BufNewFile" },
|
|
|
|
augroup_name = "BeLazyOnFileOpen" .. plugin_name,
|
2022-07-25 15:49:33 +02:00
|
|
|
plugin = plugin_name,
|
2022-07-22 18:00:00 +02:00
|
|
|
condition = function()
|
|
|
|
local file = vim.fn.expand "%"
|
|
|
|
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
|
|
|
|
end,
|
|
|
|
}
|
2022-06-14 14:06:27 +02:00
|
|
|
end
|
|
|
|
|
2022-06-19 10:13:11 +02:00
|
|
|
M.treesitter_cmds = {
|
2022-07-22 18:00:00 +02:00
|
|
|
"TSInstall",
|
|
|
|
"TSBufEnable",
|
|
|
|
"TSBufDisable",
|
|
|
|
"TSEnable",
|
|
|
|
"TSDisable",
|
|
|
|
"TSModuleInfo",
|
2022-06-19 10:13:11 +02:00
|
|
|
}
|
|
|
|
|
2022-07-25 15:49:33 +02:00
|
|
|
M.mason_cmds = {
|
|
|
|
"Mason",
|
|
|
|
"MasonInstall",
|
2022-07-25 16:25:31 +02:00
|
|
|
"MasonInstallAll",
|
2022-07-25 15:49:33 +02:00
|
|
|
"MasonUninstall",
|
|
|
|
"MasonUninstallAll",
|
|
|
|
"MasonLog",
|
|
|
|
}
|
|
|
|
|
2022-06-14 14:06:27 +02:00
|
|
|
M.gitsigns = function()
|
2022-07-22 18:00:00 +02:00
|
|
|
autocmd({ "BufRead" }, {
|
|
|
|
callback = function()
|
2022-08-06 04:49:14 +02:00
|
|
|
if vim.fn.isdirectory ".git" ~= 0 then
|
|
|
|
vim.schedule(function()
|
|
|
|
require("packer").loader "gitsigns.nvim"
|
|
|
|
end)
|
2022-07-22 18:00:00 +02:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
2022-06-14 14:06:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|