nix-community.nixvim/plugins/by-name/nvim-tree/default.nix

157 lines
4.8 KiB
Nix
Raw Normal View History

{
lib,
helpers,
config,
...
}:
2024-05-05 19:39:35 +02:00
let
inherit (lib) mkOption types;
2024-05-05 19:39:35 +02:00
in
lib.nixvim.plugins.mkNeovimPlugin {
name = "nvim-tree";
packPathName = "nvim-tree.lua";
package = "nvim-tree-lua";
maintainers = [ lib.maintainers.saygo-png ];
description = "A file explorer tree for neovim written in lua.";
general: add package options (#127) * barbar: package option * Base16: package option * gruvbox: package option * nord: package option * one: package option * onedark: package option * tokyonight: package option * nvim-cmp: package option * coq: package option * lspkind: package option * helpers: added package option to mkPlugin * fugitive: package option * gitgutter: package option * gitsigns: package option * neogit: package option * ledger: package option * nix: package option * plantuml-syntax: package option * treesitter-context: package option + formatting * treesitter-refactor: package option + formatting * treesitter: package option * zig: package option * null-ls: package option * null-ls/servers: package option * lsp-lines: package option * lspsaga: package option * trouble: package option * luasnip: added description for package option * airline: package option * lightline: package option * lualine: package option * telescope: package option * telescope/frecency: package option * telescope/fzf-native: package option * telescope/media-files: package option * comment-nvim: package option * vim-commentary: package option * dashboard: package option * easyescape: package option * emmet: package option * endwise: package option * floaterm: package option * goyo: package option * intellitab: package option * mark-radar: package option * notify: package option * nvim-autopairs: package option * nvim-tree: package option * project-nvim: package option * specs: package option * startify: package option * surround: package option * undotree: package option
2023-01-19 10:45:15 +00:00
inherit (import ./deprecations.nix lib) optionsRenamedToSettings deprecateExtraOptions imports;
2022-01-09 17:59:07 +00:00
extraOptions = {
2024-05-05 19:39:35 +02:00
openOnSetup = mkOption {
type = types.bool;
default = false;
description = ''
Will automatically open the tree when running setup if startup buffer is a directory, is
empty or is unnamed. nvim-tree window will be focused.
'';
};
2022-01-09 17:59:07 +00:00
2024-05-05 19:39:35 +02:00
openOnSetupFile = mkOption {
type = types.bool;
default = false;
description = ''
Will automatically open the tree when running setup if startup buffer is a file.
File window will be focused.
File will be found if updateFocusedFile is enabled.
'';
};
2022-01-09 17:59:07 +00:00
2024-05-05 19:39:35 +02:00
ignoreBufferOnSetup = mkOption {
type = types.bool;
default = false;
description = ''
Will ignore the buffer, when deciding to open the tree on setup.
'';
};
2022-01-09 17:59:07 +00:00
2024-05-05 19:39:35 +02:00
ignoreFtOnSetup = mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
List of filetypes that will prevent `open_on_setup` to open.
You can use this option if you don't want the tree to open
in some scenarios (eg using vim startify).
'';
};
2022-01-09 17:59:07 +00:00
2024-05-05 19:39:35 +02:00
autoClose = mkOption {
type = types.bool;
default = false;
description = "Automatically close";
};
};
dependencies = [
"git"
];
extraConfig =
cfg:
let
2024-05-05 19:39:35 +02:00
autoOpenEnabled = cfg.openOnSetup or cfg.openOnSetupFile;
2024-05-05 19:39:35 +02:00
openNvimTreeFunction = ''
local function open_nvim_tree(data)
2024-05-05 19:39:35 +02:00
------------------------------------------------------------------------------------------
2024-05-05 19:39:35 +02:00
-- buffer is a directory
local directory = vim.fn.isdirectory(data.file) == 1
2024-05-05 19:39:35 +02:00
-- buffer is a [No Name]
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
2024-05-05 19:39:35 +02:00
-- Will automatically open the tree when running setup if startup buffer is a directory,
-- is empty or is unnamed. nvim-tree window will be focused.
local open_on_setup = ${lib.nixvim.toLuaObject cfg.openOnSetup}
2024-05-05 19:39:35 +02:00
if (directory or no_name) and open_on_setup then
-- change to the directory
if directory then
vim.cmd.cd(data.file)
end
2024-05-05 19:39:35 +02:00
-- open the tree
require("nvim-tree.api").tree.open()
return
end
2024-05-05 19:39:35 +02:00
------------------------------------------------------------------------------------------
2024-05-05 19:39:35 +02:00
-- Will automatically open the tree when running setup if startup buffer is a file.
-- File window will be focused.
-- File will be found if updateFocusedFile is enabled.
local open_on_setup_file = ${lib.nixvim.toLuaObject cfg.openOnSetupFile}
2024-05-05 19:39:35 +02:00
-- buffer is a real file on the disk
local real_file = vim.fn.filereadable(data.file) == 1
2024-05-05 19:39:35 +02:00
if (real_file or no_name) and open_on_setup_file then
2024-05-05 19:39:35 +02:00
-- skip ignored filetypes
local filetype = vim.bo[data.buf].ft
local ignored_filetypes = ${lib.nixvim.toLuaObject cfg.ignoreFtOnSetup}
2024-05-05 19:39:35 +02:00
if not vim.tbl_contains(ignored_filetypes, filetype) then
-- open the tree but don't focus it
require("nvim-tree.api").tree.toggle({ focus = false })
return
end
end
2024-05-05 19:39:35 +02:00
------------------------------------------------------------------------------------------
2024-05-05 19:39:35 +02:00
-- Will ignore the buffer, when deciding to open the tree on setup.
local ignore_buffer_on_setup = ${lib.nixvim.toLuaObject cfg.ignoreBufferOnSetup}
2024-05-05 19:39:35 +02:00
if ignore_buffer_on_setup then
require("nvim-tree.api").tree.open()
end
2024-05-05 19:39:35 +02:00
end
'';
in
{
# TODO: added 2024-09-20 remove after 24.11
plugins.web-devicons = lib.mkIf (
!(
config.plugins.mini.enable
&& config.plugins.mini.modules ? icons
&& config.plugins.mini.mockDevIcons
)
) { enable = lib.mkOverride 1490 true; };
2022-01-09 17:59:07 +00:00
autoCmd =
(lib.optional autoOpenEnabled {
event = "VimEnter";
callback = helpers.mkRaw "open_nvim_tree";
})
++ (lib.optional cfg.autoClose {
event = "BufEnter";
command = "if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif";
nested = true;
});
plugins.nvim-tree.luaConfig.pre = lib.optionalString autoOpenEnabled openNvimTreeFunction;
2022-01-09 17:59:07 +00:00
};
}