modules/nvim-tree: add options to set on_attach setting
This commit is contained in:
parent
f3c3646f1c
commit
dfad4a83b2
1 changed files with 34 additions and 4 deletions
|
@ -3,18 +3,18 @@
|
||||||
let cfg = config.plugins.navigation.nvim-tree; in
|
let cfg = config.plugins.navigation.nvim-tree; in
|
||||||
|
|
||||||
{
|
{
|
||||||
options.plugins.navigation.nvim-tree = with lib; with types; {
|
options.plugins.navigation.nvim-tree = with lib; {
|
||||||
enable = mkEnableOption "nvim-tree";
|
enable = mkEnableOption "nvim-tree";
|
||||||
package = mkPackageOption pkgs.vimPlugins "nvim-tree-lua" { };
|
package = mkPackageOption pkgs.vimPlugins "nvim-tree-lua" { };
|
||||||
settings = mkOption {
|
settings = mkOption {
|
||||||
type = attrs;
|
type = types.attrs;
|
||||||
default = { };
|
default = { };
|
||||||
description = ''
|
description = ''
|
||||||
`:help nvim-tree-setup`
|
`:help nvim-tree-setup`
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
disableNetrw = mkOption {
|
disableNetrw = mkOption {
|
||||||
type = bool;
|
type = types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = ''
|
description = ''
|
||||||
Disabling netrw is strongly advised.
|
Disabling netrw is strongly advised.
|
||||||
|
@ -22,14 +22,44 @@ let cfg = config.plugins.navigation.nvim-tree; in
|
||||||
`:help nvim-tree-netrw`
|
`:help nvim-tree-netrw`
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
keymap = {
|
||||||
|
withDefault = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = "attach default mappings";
|
||||||
|
};
|
||||||
|
set = mkOption {
|
||||||
|
type = with types; listOf keymap;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
|
fn.nvim-tree-lua-on-attach = lib.mkIf (cfg.keymap.set != [ ]) {
|
||||||
|
args = [ "bufnr" ];
|
||||||
|
content = { bufnr }: {
|
||||||
|
extra = with lib.nix2lua; lib.mkIf cfg.keymap.withDefault pipe [
|
||||||
|
(require "nvim-tree.api")
|
||||||
|
(var "config")
|
||||||
|
(var "mappings")
|
||||||
|
(call "default_on_attach" bufnr)
|
||||||
|
];
|
||||||
|
|
||||||
|
vim.keymap.set = map (attrs: attrs // { buffer = bufnr; }) cfg.keymap.set;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
plugin.nvim-tree-lua = {
|
plugin.nvim-tree-lua = {
|
||||||
name = "nvim-tree";
|
name = "nvim-tree";
|
||||||
package = cfg.package;
|
package = cfg.package;
|
||||||
setupSettings = cfg.settings;
|
setupSettings =
|
||||||
|
cfg.settings
|
||||||
|
// lib.optionalAttrs (cfg.keymap.set != [ ]) {
|
||||||
|
on_attach = config.fn.nvim-tree-lua-on-attach.lambda;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
vim.g = lib.mkIf cfg.disableNetrw {
|
vim.g = lib.mkIf cfg.disableNetrw {
|
||||||
|
|
Loading…
Reference in a new issue