refactor(nvim): improve lazy loading of alpha, treesitter, & neo-tree

This commit is contained in:
Price Hiller 2024-02-19 08:05:22 -06:00
parent a6996bb086
commit 2ac83cc7ad
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB
3 changed files with 19 additions and 11 deletions

View File

@ -2,6 +2,19 @@ return {
{ {
"goolord/alpha-nvim", "goolord/alpha-nvim",
dependencies = { "nvim-tree/nvim-web-devicons" }, dependencies = { "nvim-tree/nvim-web-devicons" },
init = function()
vim.api.nvim_create_autocmd("BufEnter", {
once = true,
callback = function()
local f = vim.fn.expand("%:p")
if vim.fn.isdirectory(f) == 0 then
require("alpha")
return true
end
end,
})
end,
lazy = true,
opts = function() opts = function()
-- Set header -- Set header
local header = { local header = {

View File

@ -15,12 +15,11 @@ return {
-- Correctly hijack netrw, thanks to -- Correctly hijack netrw, thanks to
-- https://github.com/nvim-neo-tree/neo-tree.nvim/issues/1247#issuecomment-1836294271 -- https://github.com/nvim-neo-tree/neo-tree.nvim/issues/1247#issuecomment-1836294271
vim.api.nvim_create_autocmd("BufEnter", { vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("NeoTreeInit", { clear = true }), once = true,
callback = function() callback = function()
local f = vim.fn.expand("%:p") local f = vim.fn.expand("%:p")
if vim.fn.isdirectory(f) ~= 0 then if vim.fn.isdirectory(f) == 1 then
require("neo-tree") require("neo-tree")
-- neo-tree is loaded now, delete the init autocmd
return true return true
end end
end, end,

View File

@ -122,15 +122,11 @@ return {
"RRethy/nvim-treesitter-endwise", "RRethy/nvim-treesitter-endwise",
}, },
init = function() init = function()
vim.api.nvim_create_autocmd("BufEnter", { vim.api.nvim_create_autocmd("FileReadPre", {
group = vim.api.nvim_create_augroup("NeoTreeInit", { clear = true }), once = true,
callback = function() callback = function()
local f = vim.fn.expand("%:p") require("nvim-treesitter")
if vim.fn.isdirectory(f) == 0 then return true
require("neo-tree")
-- neo-tree is loaded now, delete the init autocmd
return true
end
end, end,
}) })
end, end,