This repository has been archived on 2024-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
neovim/modules/nvim-tree-lua.nix

55 lines
1.3 KiB
Nix

{ nix2lua, vim, ... }:
let
defaultKeymaps = [
{ mode = "n"; bind = "<leader>nt"; command = "<CMD>NvimTreeToggle<CR>"; }
{ mode = "n"; bind = "<leader>nf"; command = "<CMD>NvimTreeFindFile<CR>"; }
];
in
{ configs ? { }
, keymaps ? defaultKeymaps
, extraKeymaps ? [ ]
}:
with nix2lua.lib;
let isEmptyVar = name: eq "" (var name); in
{
nvim-web-devicons = true;
nvim-tree-lua = (
[
(pipe1 (require "nvim-tree") (call "setup" configs))
(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"
(eq 1 (vim.fn.isdirectory "data.file"))
))
(if' (not (and (var "isNoNameBuffer") (var "isDirectory")))
return_void
)
# change to the directory
(if' (var "isDirectory")
(vim.cmd.cd "data.file")
)
# open the tree
(pipe1 (require "nvim-tree.api") (call0 "tree.open"))
]))
(vim.api.nvim_create_autocmd [ "VimEnter" ] { callback = var "open_nvim_tree"; })
]
++ map vim.keymap.set (keymaps ++ extraKeymaps)
);
}