rm un-needed lazyload function
This commit is contained in:
parent
936131c00a
commit
08453985ca
@ -1,79 +0,0 @@
|
|||||||
local M = {}
|
|
||||||
local autocmd = vim.api.nvim_create_autocmd
|
|
||||||
|
|
||||||
-- require("packer").loader(tb.plugins)
|
|
||||||
-- This must be used for plugins that need to be loaded just after a file
|
|
||||||
-- ex : treesitter, lspconfig etc
|
|
||||||
M.lazy_load = function(tb)
|
|
||||||
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)
|
|
||||||
|
|
||||||
-- 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,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
-- load certain plugins only when there's a file opened in the buffer
|
|
||||||
-- if "nvim filename" is executed -> load the plugin after nvim gui loads
|
|
||||||
-- This gives an instant preview of nvim with the file opened
|
|
||||||
|
|
||||||
M.on_file_open = function(plugin_name)
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
M.packer_cmds = {
|
|
||||||
"PackerSnapshot",
|
|
||||||
"PackerSnapshotRollback",
|
|
||||||
"PackerSnapshotDelete",
|
|
||||||
"PackerInstall",
|
|
||||||
"PackerUpdate",
|
|
||||||
"PackerSync",
|
|
||||||
"PackerClean",
|
|
||||||
"PackerCompile",
|
|
||||||
"PackerStatus",
|
|
||||||
"PackerProfile",
|
|
||||||
"PackerLoad",
|
|
||||||
}
|
|
||||||
|
|
||||||
M.treesitter_cmds = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSEnable", "TSDisable", "TSModuleInfo" }
|
|
||||||
M.mason_cmds = { "Mason", "MasonInstall", "MasonInstallAll", "MasonUninstall", "MasonUninstallAll", "MasonLog" }
|
|
||||||
|
|
||||||
M.gitsigns = function()
|
|
||||||
autocmd({ "BufRead" }, {
|
|
||||||
group = vim.api.nvim_create_augroup("GitSignsLazyLoad", { clear = true }),
|
|
||||||
callback = function()
|
|
||||||
vim.fn.system("git -C " .. vim.fn.expand "%:p:h" .. " rev-parse")
|
|
||||||
if vim.v.shell_error == 0 then
|
|
||||||
vim.api.nvim_del_augroup_by_name "GitSignsLazyLoad"
|
|
||||||
vim.schedule(function()
|
|
||||||
require("packer").loader "gitsigns.nvim"
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
@ -155,4 +155,31 @@ M.packer_sync = function(...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.lazy_load = function(plugin)
|
||||||
|
vim.api.nvim_create_autocmd({ "BufRead", "BufWinEnter", "BufNewFile" }, {
|
||||||
|
group = vim.api.nvim_create_augroup("BeLazyOnFileOpen" .. plugin, {}),
|
||||||
|
callback = function()
|
||||||
|
local file = vim.fn.expand "%"
|
||||||
|
local condition = file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
|
||||||
|
|
||||||
|
if condition then
|
||||||
|
vim.api.nvim_del_augroup_by_name("BeLazyOnFileOpen" .. plugin)
|
||||||
|
|
||||||
|
-- dont defer for treesitter as it will show slow highlighting
|
||||||
|
-- This deferring only happens only when we do "nvim filename"
|
||||||
|
if plugin ~= "nvim-treesitter" then
|
||||||
|
vim.defer_fn(function()
|
||||||
|
require("packer").loader(plugin)
|
||||||
|
if plugin == "nvim-lspconfig" then
|
||||||
|
vim.cmd "silent! do FileType"
|
||||||
|
end
|
||||||
|
end, 0)
|
||||||
|
else
|
||||||
|
require("packer").loader(plugin)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
-- List of all default plugins & their definitions
|
||||||
local plugins = {
|
local plugins = {
|
||||||
|
|
||||||
["nvim-lua/plenary.nvim"] = { module = "plenary" },
|
["nvim-lua/plenary.nvim"] = { module = "plenary" },
|
||||||
@ -5,7 +6,19 @@ local plugins = {
|
|||||||
["lewis6991/impatient.nvim"] = {},
|
["lewis6991/impatient.nvim"] = {},
|
||||||
|
|
||||||
["wbthomason/packer.nvim"] = {
|
["wbthomason/packer.nvim"] = {
|
||||||
cmd = require("core.lazy_load").packer_cmds,
|
cmd = {
|
||||||
|
"PackerSnapshot",
|
||||||
|
"PackerSnapshotRollback",
|
||||||
|
"PackerSnapshotDelete",
|
||||||
|
"PackerInstall",
|
||||||
|
"PackerUpdate",
|
||||||
|
"PackerSync",
|
||||||
|
"PackerClean",
|
||||||
|
"PackerCompile",
|
||||||
|
"PackerStatus",
|
||||||
|
"PackerProfile",
|
||||||
|
"PackerLoad",
|
||||||
|
},
|
||||||
config = function()
|
config = function()
|
||||||
require "plugins"
|
require "plugins"
|
||||||
end,
|
end,
|
||||||
@ -57,7 +70,7 @@ local plugins = {
|
|||||||
["lukas-reineke/indent-blankline.nvim"] = {
|
["lukas-reineke/indent-blankline.nvim"] = {
|
||||||
opt = true,
|
opt = true,
|
||||||
setup = function()
|
setup = function()
|
||||||
require("core.lazy_load").on_file_open "indent-blankline.nvim"
|
require("core.utils").lazy_load "indent-blankline.nvim"
|
||||||
require("core.utils").load_mappings "blankline"
|
require("core.utils").load_mappings "blankline"
|
||||||
end,
|
end,
|
||||||
config = function()
|
config = function()
|
||||||
@ -68,7 +81,7 @@ local plugins = {
|
|||||||
["NvChad/nvim-colorizer.lua"] = {
|
["NvChad/nvim-colorizer.lua"] = {
|
||||||
opt = true,
|
opt = true,
|
||||||
setup = function()
|
setup = function()
|
||||||
require("core.lazy_load").on_file_open "nvim-colorizer.lua"
|
require("core.utils").lazy_load "nvim-colorizer.lua"
|
||||||
end,
|
end,
|
||||||
config = function()
|
config = function()
|
||||||
require("plugins.configs.others").colorizer()
|
require("plugins.configs.others").colorizer()
|
||||||
@ -78,9 +91,10 @@ local plugins = {
|
|||||||
["nvim-treesitter/nvim-treesitter"] = {
|
["nvim-treesitter/nvim-treesitter"] = {
|
||||||
module = "nvim-treesitter",
|
module = "nvim-treesitter",
|
||||||
setup = function()
|
setup = function()
|
||||||
require("core.lazy_load").on_file_open "nvim-treesitter"
|
require("core.utils").lazy_load "nvim-treesitter"
|
||||||
end,
|
end,
|
||||||
cmd = require("core.lazy_load").treesitter_cmds,
|
cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSEnable", "TSDisable", "TSModuleInfo" },
|
||||||
|
|
||||||
run = ":TSUpdate",
|
run = ":TSUpdate",
|
||||||
config = function()
|
config = function()
|
||||||
require "plugins.configs.treesitter"
|
require "plugins.configs.treesitter"
|
||||||
@ -91,7 +105,19 @@ local plugins = {
|
|||||||
["lewis6991/gitsigns.nvim"] = {
|
["lewis6991/gitsigns.nvim"] = {
|
||||||
ft = "gitcommit",
|
ft = "gitcommit",
|
||||||
setup = function()
|
setup = function()
|
||||||
require("core.lazy_load").gitsigns()
|
-- load gitsigns only when a git file is opened
|
||||||
|
vim.api.nvim_create_autocmd({ "BufRead" }, {
|
||||||
|
group = vim.api.nvim_create_augroup("GitSignsLazyLoad", { clear = true }),
|
||||||
|
callback = function()
|
||||||
|
vim.fn.system("git -C " .. vim.fn.expand "%:p:h" .. " rev-parse")
|
||||||
|
if vim.v.shell_error == 0 then
|
||||||
|
vim.api.nvim_del_augroup_by_name "GitSignsLazyLoad"
|
||||||
|
vim.schedule(function()
|
||||||
|
require("packer").loader "gitsigns.nvim"
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
config = function()
|
config = function()
|
||||||
require("plugins.configs.others").gitsigns()
|
require("plugins.configs.others").gitsigns()
|
||||||
@ -100,7 +126,7 @@ local plugins = {
|
|||||||
|
|
||||||
-- lsp stuff
|
-- lsp stuff
|
||||||
["williamboman/mason.nvim"] = {
|
["williamboman/mason.nvim"] = {
|
||||||
cmd = require("core.lazy_load").mason_cmds,
|
cmd = { "Mason", "MasonInstall", "MasonInstallAll", "MasonUninstall", "MasonUninstallAll", "MasonLog" },
|
||||||
config = function()
|
config = function()
|
||||||
require "plugins.configs.mason"
|
require "plugins.configs.mason"
|
||||||
end,
|
end,
|
||||||
@ -109,7 +135,7 @@ local plugins = {
|
|||||||
["neovim/nvim-lspconfig"] = {
|
["neovim/nvim-lspconfig"] = {
|
||||||
opt = true,
|
opt = true,
|
||||||
setup = function()
|
setup = function()
|
||||||
require("core.lazy_load").on_file_open "nvim-lspconfig"
|
require("core.utils").lazy_load "nvim-lspconfig"
|
||||||
end,
|
end,
|
||||||
config = function()
|
config = function()
|
||||||
require "plugins.configs.lspconfig"
|
require "plugins.configs.lspconfig"
|
||||||
@ -198,7 +224,6 @@ local plugins = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Load all plugins
|
|
||||||
local present, packer = pcall(require, "packer")
|
local present, packer = pcall(require, "packer")
|
||||||
|
|
||||||
if present then
|
if present then
|
||||||
|
Loading…
Reference in New Issue
Block a user