Compare commits

..

3 commits

Author SHA1 Message Date
Ching Pei Yang
f057ed34f1
Merge 590cd886f4 into b6785f8218 2024-11-19 00:33:02 +00:00
Ching Pei Yang
590cd886f4
nvimtree: move beforeAll to pluginRC 2024-11-19 01:32:56 +01:00
Ching Pei Yang
c9f5dd1e22
neo-tree: move beforeAll to pluginRC 2024-11-19 01:32:53 +01:00
2 changed files with 87 additions and 86 deletions

View file

@ -4,7 +4,7 @@
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.strings) optionalString;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.filetree.neo-tree;
in {
@ -22,30 +22,31 @@ in {
setupModule = "neo-tree";
inherit (cfg) setupOpts;
beforeAll =
optionalString (cfg.setupOpts.filesystem.hijack_netrw_behavior != "disabled")
# from https://github.com/nvim-neo-tree/neo-tree.nvim/discussions/1326
''
vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("load_neo_tree", {}),
desc = "Loads neo-tree when openning a directory",
callback = function(args)
local stats = vim.uv.fs_stat(args.file)
if not stats or stats.type ~= "directory" then
return
end
require("lz.n").trigger_load("neo-tree-nvim")
return true
end,
})
'';
cmd = ["Neotree"];
event = [];
};
pluginRC = mkIf (cfg.setupOpts.filesystem.hijack_netrw_behavior != "disabled" && config.vim.lazy.enable) {
# from https://github.com/nvim-neo-tree/neo-tree.nvim/discussions/1326
neo-tree = entryAnywhere ''
vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("load_neo_tree", {}),
desc = "Loads neo-tree when openning a directory",
callback = function(args)
local stats = vim.uv.fs_stat(args.file)
if not stats or stats.type ~= "directory" then
return
end
require("lz.n").trigger_load("neo-tree-nvim")
return true
end,
})
'';
};
visuals.nvim-web-devicons.enable = true;
};
};

View file

@ -32,76 +32,76 @@ in {
(mkLznBinding ["n"] cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description)
(mkLznBinding ["n"] cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description)
];
};
beforeAll = ''
${
optionalString cfg.setupOpts.disable_netrw ''
-- disable netrew completely
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
''
}
pluginRC.nvim-tree = entryAnywhere ''
${
optionalString cfg.setupOpts.disable_netrw ''
-- disable netrew completely
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
''
}
${optionalString (cfg.setupOpts.hijack_netrw && !cfg.openOnSetup) ''
vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("load_nvim_tree", {}),
desc = "Loads nvim-tree when openning a directory",
callback = function(args)
local stats = vim.uv.fs_stat(args.file)
${optionalString (config.vim.lazy.enable && cfg.setupOpts.hijack_netrw && !cfg.openOnSetup) ''
vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("load_nvim_tree", {}),
desc = "Loads nvim-tree when openning a directory",
callback = function(args)
local stats = vim.uv.fs_stat(args.file)
if not stats or stats.type ~= "directory" then
return
end
require("lz.n").trigger_load("nvim-tree-lua")
return true
end,
})
''}
${
optionalString cfg.openOnSetup ''
${optionalString config.vim.lazy.enable ''require('lz.n').trigger_load("nvim-tree-lua")''}
-- autostart behaviour
-- Open on startup has been deprecated
-- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup
-- use a nix eval to dynamically insert the open on startup function
local function open_nvim_tree(data)
local IGNORED_FT = {
"markdown",
}
-- buffer is a real file on the disk
local real_file = vim.fn.filereadable(data.file) == 1
-- buffer is a [No Name]
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
-- &ft
local filetype = vim.bo[data.buf].ft
-- only files please
if not real_file and not no_name then
return
end
-- skip ignored filetypes
if vim.tbl_contains(IGNORED_FT, filetype) then
return
end
-- open the tree but don't focus it
require("nvim-tree.api").tree.toggle({ focus = false })
if not stats or stats.type ~= "directory" then
return
end
-- function to automatically open the tree on VimEnter
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
''
}
'';
};
require("lz.n").trigger_load("nvim-tree-lua")
return true
end,
})
''}
${
optionalString cfg.openOnSetup ''
${optionalString config.vim.lazy.enable ''require('lz.n').trigger_load("nvim-tree-lua")''}
-- autostart behaviour
-- Open on startup has been deprecated
-- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup
-- use a nix eval to dynamically insert the open on startup function
local function open_nvim_tree(data)
local IGNORED_FT = {
"markdown",
}
-- buffer is a real file on the disk
local real_file = vim.fn.filereadable(data.file) == 1
-- buffer is a [No Name]
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
-- &ft
local filetype = vim.bo[data.buf].ft
-- only files please
if not real_file and not no_name then
return
end
-- skip ignored filetypes
if vim.tbl_contains(IGNORED_FT, filetype) then
return
end
-- open the tree but don't focus it
require("nvim-tree.api").tree.toggle({ focus = false })
end
-- function to automatically open the tree on VimEnter
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
''
}
'';
};
};
}