2024-04-20 23:05:33 +03:00
|
|
|
{ nix2lua, vim, ... }:
|
2024-04-17 19:35:34 +03:00
|
|
|
|
2024-04-21 11:46:13 +03:00
|
|
|
let
|
|
|
|
defaultKeymaps = [
|
2024-04-17 19:35:34 +03:00
|
|
|
{ mode = "n"; bind = "<leader>nt"; command = "<CMD>NvimTreeToggle<CR>"; }
|
|
|
|
{ mode = "n"; bind = "<leader>nf"; command = "<CMD>NvimTreeFindFile<CR>"; }
|
2024-04-21 11:46:13 +03:00
|
|
|
];
|
|
|
|
in
|
|
|
|
|
|
|
|
{ configs ? { }
|
|
|
|
, keymaps ? defaultKeymaps
|
|
|
|
, extraKeymaps ? [ ]
|
2024-04-17 19:35:34 +03:00
|
|
|
}:
|
|
|
|
|
|
|
|
with nix2lua.lib;
|
2024-04-20 23:05:33 +03:00
|
|
|
let isEmptyVar = name: eq "" (var name); in
|
2024-04-17 19:35:34 +03:00
|
|
|
{
|
2024-04-18 01:26:40 +03:00
|
|
|
nvim-web-devicons = true;
|
|
|
|
|
2024-04-17 19:35:34 +03:00
|
|
|
nvim-tree-lua = (
|
|
|
|
[
|
2024-04-20 23:05:33 +03:00
|
|
|
(pipe1 (require "nvim-tree") (call "setup" configs))
|
2024-04-17 19:35:34 +03:00
|
|
|
|
|
|
|
(local (func "open_nvim_tree" [ "data" ] [
|
|
|
|
# buffer is a [No Name]
|
|
|
|
(local (set "isNoNameBuffer"
|
|
|
|
(and
|
|
|
|
(isEmptyVar "data.file")
|
|
|
|
(isEmptyVar "vim.bo[data.buf].buftype")
|
|
|
|
)
|
|
|
|
))
|
|
|
|
|
|
|
|
# buffer is a directory
|
|
|
|
(local (set "isDirectory"
|
2024-04-20 23:05:33 +03:00
|
|
|
(eq 1 (vim.fn.isdirectory "data.file"))
|
2024-04-17 19:35:34 +03:00
|
|
|
))
|
|
|
|
|
2024-04-20 23:05:33 +03:00
|
|
|
(if' (not (and (var "isNoNameBuffer") (var "isDirectory")))
|
2024-04-17 19:35:34 +03:00
|
|
|
return_void
|
2024-04-20 23:05:33 +03:00
|
|
|
)
|
2024-04-17 19:35:34 +03:00
|
|
|
|
|
|
|
# change to the directory
|
2024-04-20 23:05:33 +03:00
|
|
|
(if' (var "isDirectory")
|
|
|
|
(vim.cmd.cd "data.file")
|
|
|
|
)
|
2024-04-17 19:35:34 +03:00
|
|
|
|
|
|
|
# open the tree
|
2024-04-20 23:05:33 +03:00
|
|
|
(pipe1 (require "nvim-tree.api") (call0 "tree.open"))
|
2024-04-17 19:35:34 +03:00
|
|
|
]))
|
|
|
|
|
2024-04-20 23:05:33 +03:00
|
|
|
(vim.api.nvim_create_autocmd [ "VimEnter" ] { callback = var "open_nvim_tree"; })
|
2024-04-17 19:35:34 +03:00
|
|
|
]
|
2024-04-21 11:46:13 +03:00
|
|
|
++ map vim.keymap.set (keymaps ++ extraKeymaps)
|
2024-04-17 19:35:34 +03:00
|
|
|
);
|
|
|
|
}
|