Compare commits
3 commits
6086cea1d4
...
688e8e2ece
Author | SHA1 | Date | |
---|---|---|---|
688e8e2ece | |||
238e4bf68e | |||
4cc9de194f |
5 changed files with 103 additions and 3 deletions
|
@ -43,7 +43,7 @@ let
|
|||
'';
|
||||
};
|
||||
buffer = mkOption {
|
||||
type = with types; nullOr str;
|
||||
type = with types; nullOr attrs;
|
||||
default = null;
|
||||
description = ''
|
||||
The mapping will be effective in the current buffer only.
|
||||
|
@ -129,7 +129,6 @@ let
|
|||
|
||||
genConfig = mkOption {
|
||||
type = types.attrs;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -9,11 +9,13 @@
|
|||
./modules/filetype.nix
|
||||
./modules/input.nix
|
||||
./modules/plugin.nix
|
||||
./modules/fn.nix
|
||||
|
||||
./modules/plugins/theme/catppuccin.nix
|
||||
./modules/plugins/style/neoformat.nix
|
||||
./modules/plugins/navigation/telescope.nix
|
||||
./modules/plugins/navigation/nvim-tree.nix
|
||||
./modules/plugins/gitsigns.nix
|
||||
|
||||
##################################################
|
||||
(pkgs.path + "/nixos/modules/misc/assertions.nix")
|
||||
|
|
61
modules/fn.nix
Normal file
61
modules/fn.nix
Normal file
|
@ -0,0 +1,61 @@
|
|||
{ lib, ... }:
|
||||
|
||||
let
|
||||
|
||||
fnOpts = { name, config, ... }: {
|
||||
options = with lib; {
|
||||
args = mkOption {
|
||||
type = with types; listOf str;
|
||||
default = [ ];
|
||||
};
|
||||
content = mkOption {
|
||||
type = types.functionTo (lib.types.submoduleWith {
|
||||
modules = [
|
||||
{
|
||||
options.extra = with lib; mkOption {
|
||||
type = with types; nullOr attrs;
|
||||
default = null;
|
||||
};
|
||||
}
|
||||
./vim/keymap.nix
|
||||
# ./vim/opts.nix
|
||||
];
|
||||
specialArgs = { inherit lib; };
|
||||
});
|
||||
default = { };
|
||||
};
|
||||
|
||||
lambda = mkOption {
|
||||
type = types.attrs;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
lambda = with lib.nix2lua;
|
||||
let
|
||||
fnArgs = builtins.listToAttrs (map (v: { name = v; value = raw v; }) config.args);
|
||||
innerCfg = config.content fnArgs;
|
||||
in
|
||||
lambda config.args (lib.flatten [
|
||||
innerCfg.extra
|
||||
|
||||
(lib.flip map innerCfg.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
|
||||
let
|
||||
buf = lib.optionalString (vars.buffer != null) vars.buffer.raw;
|
||||
m = if builtins.isList mode then lib.head mode else mode;
|
||||
in
|
||||
if innerCfg.vim.keymap._validate."${buf}"."${m}"."${lhs}" == rhs then vars.genConfig
|
||||
else abort "This case should never happen."
|
||||
))
|
||||
]);
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.fn = with lib; mkOption {
|
||||
type = with types; attrsOf (submodule fnOpts);
|
||||
default = { };
|
||||
};
|
||||
}
|
38
modules/plugins/gitsigns.nix
Normal file
38
modules/plugins/gitsigns.nix
Normal file
|
@ -0,0 +1,38 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let cfg = config.plugins.gitsigns; in
|
||||
|
||||
{
|
||||
options.plugins.gitsigns = with lib; {
|
||||
enable = mkEnableOption "gitsigns-nvim";
|
||||
|
||||
package = mkPackageOption pkgs.vimPlugins "gitsigns-nvim" { };
|
||||
|
||||
settings = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
};
|
||||
|
||||
keymap.set = mkOption {
|
||||
type = with types; listOf keymap;
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
fn.gitsigns-nvim-on-attach = {
|
||||
args = [ "bufnr" ];
|
||||
content = { bufnr }: {
|
||||
vim.keymap.set = map (attrs: attrs // { buffer = bufnr; }) cfg.keymap.set;
|
||||
};
|
||||
};
|
||||
|
||||
plugin.gitsigns-nvim = {
|
||||
name = "gitsigns";
|
||||
varName = "gs";
|
||||
package = cfg.package;
|
||||
setupSettings = cfg.settings // {
|
||||
on_attach = config.fn.gitsigns-nvim-on-attach.lambda;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
|
@ -30,7 +30,7 @@ let cfg = config.vim.keymap; in
|
|||
else m
|
||||
)));
|
||||
|
||||
buf = lib.optionalString (buffer != null) buffer;
|
||||
buf = lib.optionalString (buffer != null) buffer.raw;
|
||||
in
|
||||
lib.foldl lib.recursiveUpdate { }
|
||||
(lib.flip map unwrappedModes (m: {
|
||||
|
|
Loading…
Reference in a new issue