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