mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-11-25 22:56:46 +00:00
lib: move all binding related functions to lib/binds
This commit is contained in:
parent
7c730a78e5
commit
a12ba5689a
10 changed files with 51 additions and 112 deletions
|
@ -67,6 +67,7 @@
|
||||||
mkLuaBinding binding.value action binding.description;
|
mkLuaBinding binding.value action binding.description;
|
||||||
|
|
||||||
pushDownDefault = attr: mapAttrs (_name: value: mkDefault value) attr;
|
pushDownDefault = attr: mapAttrs (_name: value: mkDefault value) attr;
|
||||||
|
# pushDownDefault = attr: self.mapAttrs (name: value: self.mkDefault value) attr;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
binds
|
binds
|
||||||
|
|
|
@ -1,75 +1,15 @@
|
||||||
# From home-manager: https://github.com/nix-community/home-manager/blob/master/modules/lib/stdlib-extended.nix
|
# Cconvenience function that returns the given Nixpkgs standard library
|
||||||
# Just a convenience function that returns the given Nixpkgs standard
|
# extended with our functions using `lib.extend`.
|
||||||
# library extended with the HM library.
|
|
||||||
nixpkgsLib: let
|
nixpkgsLib: let
|
||||||
mkNvimLib = import ./.;
|
mkNvimLib = import ./.;
|
||||||
in
|
in
|
||||||
nixpkgsLib.extend (self: super: rec {
|
# WARNING: New functions should not be added here, but to files
|
||||||
|
# imported by `./default.nix` under their own categories. If your
|
||||||
|
# function does not fit to any of the existing categories, create
|
||||||
|
# a new file and import it in `./default.nix.`
|
||||||
|
nixpkgsLib.extend (self: super: {
|
||||||
nvim = mkNvimLib {lib = self;};
|
nvim = mkNvimLib {lib = self;};
|
||||||
|
|
||||||
mkLuaBinding = key: action: desc:
|
|
||||||
self.mkIf (key != null) {
|
|
||||||
"${key}" = {
|
|
||||||
inherit action desc;
|
|
||||||
lua = true;
|
|
||||||
silent = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
mkExprBinding = key: action: desc:
|
|
||||||
self.mkIf (key != null) {
|
|
||||||
"${key}" = {
|
|
||||||
inherit action desc;
|
|
||||||
lua = true;
|
|
||||||
silent = true;
|
|
||||||
expr = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
mkBinding = key: action: desc:
|
|
||||||
self.mkIf (key != null) {
|
|
||||||
"${key}" = {
|
|
||||||
inherit action desc;
|
|
||||||
silent = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
mkMappingOption = description: default:
|
|
||||||
self.mkOption {
|
|
||||||
type = self.types.nullOr self.types.str;
|
|
||||||
inherit default description;
|
|
||||||
};
|
|
||||||
|
|
||||||
# Utility function that takes two attrsets:
|
|
||||||
# { someKey = "some_value" } and
|
|
||||||
# { someKey = { description = "Some Description"; }; }
|
|
||||||
# and merges them into
|
|
||||||
# { someKey = { value = "some_value"; description = "Some Description"; }; }
|
|
||||||
addDescriptionsToMappings = actualMappings: mappingDefinitions:
|
|
||||||
self.attrsets.mapAttrs (name: value: let
|
|
||||||
isNested = self.isAttrs value;
|
|
||||||
returnedValue =
|
|
||||||
if isNested
|
|
||||||
then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}"
|
|
||||||
else {
|
|
||||||
value = value;
|
|
||||||
description = mappingDefinitions."${name}".description;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
returnedValue)
|
|
||||||
actualMappings;
|
|
||||||
|
|
||||||
mkSetBinding = binding: action:
|
|
||||||
mkBinding binding.value action binding.description;
|
|
||||||
|
|
||||||
mkSetExprBinding = binding: action:
|
|
||||||
mkExprBinding binding.value action binding.description;
|
|
||||||
|
|
||||||
mkSetLuaBinding = binding: action:
|
|
||||||
mkLuaBinding binding.value action binding.description;
|
|
||||||
|
|
||||||
pushDownDefault = attr: self.mapAttrs (name: value: self.mkDefault value) attr;
|
|
||||||
|
|
||||||
# For forward compatibility.
|
# For forward compatibility.
|
||||||
literalExpression = super.literalExpression or super.literalExample;
|
literalExpression = super.literalExpression or super.literalExample;
|
||||||
})
|
})
|
||||||
|
|
|
@ -236,6 +236,11 @@ in {
|
||||||
else abort ("Dependency cycle in ${name}: " + toJSON sortedDag);
|
else abort ("Dependency cycle in ${name}: " + toJSON sortedDag);
|
||||||
in
|
in
|
||||||
result;
|
result;
|
||||||
|
|
||||||
|
mkSection = r: ''
|
||||||
|
-- SECTION: ${r.name}
|
||||||
|
${r.data}
|
||||||
|
'';
|
||||||
in {
|
in {
|
||||||
vim = {
|
vim = {
|
||||||
startPlugins = map (x: x.package) (attrValues cfg.extraPlugins);
|
startPlugins = map (x: x.package) (attrValues cfg.extraPlugins);
|
||||||
|
@ -243,10 +248,6 @@ in {
|
||||||
globalsScript = entryAnywhere (concatStringsSep "\n" globalsScript);
|
globalsScript = entryAnywhere (concatStringsSep "\n" globalsScript);
|
||||||
|
|
||||||
luaScript = let
|
luaScript = let
|
||||||
mkSection = r: ''
|
|
||||||
-- SECTION: ${r.name}
|
|
||||||
${r.data}
|
|
||||||
'';
|
|
||||||
mapResult = r: (wrapLuaConfig (concatStringsSep "\n" (map mkSection r)));
|
mapResult = r: (wrapLuaConfig (concatStringsSep "\n" (map mkSection r)));
|
||||||
luaConfig = resolveDag {
|
luaConfig = resolveDag {
|
||||||
name = "lua config script";
|
name = "lua config script";
|
||||||
|
@ -257,10 +258,6 @@ in {
|
||||||
entryAfter ["globalsScript"] luaConfig;
|
entryAfter ["globalsScript"] luaConfig;
|
||||||
|
|
||||||
extraPluginConfigs = let
|
extraPluginConfigs = let
|
||||||
mkSection = r: ''
|
|
||||||
-- SECTION: ${r.name}
|
|
||||||
${r.data}
|
|
||||||
'';
|
|
||||||
mapResult = r: (wrapLuaConfig (concatStringsSep "\n" (map mkSection r)));
|
mapResult = r: (wrapLuaConfig (concatStringsSep "\n" (map mkSection r)));
|
||||||
extraPluginsDag = mapAttrs (_: {
|
extraPluginsDag = mapAttrs (_: {
|
||||||
after,
|
after,
|
||||||
|
|
|
@ -9,6 +9,7 @@ inputs: {
|
||||||
inherit (pkgs) wrapNeovimUnstable vimPlugins;
|
inherit (pkgs) wrapNeovimUnstable vimPlugins;
|
||||||
inherit (pkgs.vimUtils) buildVimPlugin;
|
inherit (pkgs.vimUtils) buildVimPlugin;
|
||||||
inherit (pkgs.neovimUtils) makeNeovimConfig;
|
inherit (pkgs.neovimUtils) makeNeovimConfig;
|
||||||
|
inherit (lib.attrsets) recursiveUpdate;
|
||||||
|
|
||||||
extendedLib = import ../lib/stdlib-extended.nix lib;
|
extendedLib = import ../lib/stdlib-extended.nix lib;
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ inputs: {
|
||||||
|
|
||||||
module = extendedLib.evalModules {
|
module = extendedLib.evalModules {
|
||||||
modules = [configuration] ++ nvimModules;
|
modules = [configuration] ++ nvimModules;
|
||||||
specialArgs = {modulesPath = toString ./.;} // extraSpecialArgs;
|
specialArgs = recursiveUpdate {modulesPath = toString ./.;} extraSpecialArgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
vimOptions = module.config.vim;
|
vimOptions = module.config.vim;
|
||||||
|
|
|
@ -7,16 +7,41 @@
|
||||||
|
|
||||||
cfg = config.vim;
|
cfg = config.vim;
|
||||||
in {
|
in {
|
||||||
vim.maps.normal =
|
vim.maps = {
|
||||||
mkIf cfg.disableArrows {
|
normal =
|
||||||
|
mkIf cfg.disableArrows {
|
||||||
|
"<up>" = {
|
||||||
|
action = "<nop>";
|
||||||
|
|
||||||
|
noremap = false;
|
||||||
|
};
|
||||||
|
"<down>" = {
|
||||||
|
action = "<nop>";
|
||||||
|
|
||||||
|
noremap = false;
|
||||||
|
};
|
||||||
|
"<left>" = {
|
||||||
|
action = "<nop>";
|
||||||
|
noremap = false;
|
||||||
|
};
|
||||||
|
"<right>" = {
|
||||||
|
action = "<nop>";
|
||||||
|
noremap = false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// mkIf cfg.mapLeaderSpace {
|
||||||
|
"<space>" = {
|
||||||
|
action = "<nop>";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
insert = mkIf cfg.disableArrows {
|
||||||
"<up>" = {
|
"<up>" = {
|
||||||
action = "<nop>";
|
action = "<nop>";
|
||||||
|
|
||||||
noremap = false;
|
noremap = false;
|
||||||
};
|
};
|
||||||
"<down>" = {
|
"<down>" = {
|
||||||
action = "<nop>";
|
action = "<nop>";
|
||||||
|
|
||||||
noremap = false;
|
noremap = false;
|
||||||
};
|
};
|
||||||
"<left>" = {
|
"<left>" = {
|
||||||
|
@ -27,29 +52,6 @@ in {
|
||||||
action = "<nop>";
|
action = "<nop>";
|
||||||
noremap = false;
|
noremap = false;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
// mkIf cfg.mapLeaderSpace {
|
|
||||||
"<space>" = {
|
|
||||||
action = "<nop>";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
vim.maps.insert = mkIf cfg.disableArrows {
|
|
||||||
"<up>" = {
|
|
||||||
action = "<nop>";
|
|
||||||
noremap = false;
|
|
||||||
};
|
|
||||||
"<down>" = {
|
|
||||||
action = "<nop>";
|
|
||||||
noremap = false;
|
|
||||||
};
|
|
||||||
"<left>" = {
|
|
||||||
action = "<nop>";
|
|
||||||
noremap = false;
|
|
||||||
};
|
|
||||||
"<right>" = {
|
|
||||||
action = "<nop>";
|
|
||||||
noremap = false;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,7 @@
|
||||||
inherit (lib.nvim.binds) mkBinding;
|
inherit (lib.nvim.binds) mkBinding;
|
||||||
inherit (lib.nvim.dag) entryAnywhere;
|
inherit (lib.nvim.dag) entryAnywhere;
|
||||||
inherit (lib.nvim.lua) toLuaObject;
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
# TODO: move this to its own module
|
inherit (lib.nvim.binds) pushDownDefault;
|
||||||
inherit (lib) pushDownDefault;
|
|
||||||
|
|
||||||
cfg = config.vim.filetree.nvimTree;
|
cfg = config.vim.filetree.nvimTree;
|
||||||
self = import ./nvimtree.nix {inherit pkgs lib;};
|
self = import ./nvimtree.nix {inherit pkgs lib;};
|
||||||
|
|
|
@ -5,10 +5,8 @@
|
||||||
}: let
|
}: let
|
||||||
inherit (builtins) toJSON;
|
inherit (builtins) toJSON;
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetExprBinding mkSetLuaBinding;
|
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetExprBinding mkSetLuaBinding pushDownDefault;
|
||||||
inherit (lib.nvim.dag) entryAnywhere;
|
inherit (lib.nvim.dag) entryAnywhere;
|
||||||
# TODO: move this to its own module
|
|
||||||
inherit (lib) pushDownDefault;
|
|
||||||
|
|
||||||
cfg = config.vim.git;
|
cfg = config.vim.git;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) mkMerge mkBinding mkIf;
|
inherit (lib) mkMerge mkIf;
|
||||||
|
inherit (lib.nvim.binds) mkBinding;
|
||||||
inherit (lib.nvim.lua) toLuaObject;
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
|
|
||||||
cfg = config.vim.notes.todo-comments;
|
cfg = config.vim.notes.todo-comments;
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) mkEnableOption mkOption types mkMappingOption mkRenamedOptionModule;
|
inherit (lib) mkEnableOption mkOption types mkRenamedOptionModule;
|
||||||
|
inherit (lib.nvim.binds) mkMappingOption;
|
||||||
in {
|
in {
|
||||||
imports = let
|
imports = let
|
||||||
renamedSetupOption = oldPath: newPath:
|
renamedSetupOption = oldPath: newPath:
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding;
|
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding;
|
||||||
inherit (lib.nvim.dag) entryAnywhere;
|
inherit (lib.nvim.dag) entryAnywhere;
|
||||||
# TODO: move this to its own module
|
inherit (lib.nvim.binds) pushDownDefault;
|
||||||
inherit (lib) pushDownDefault;
|
|
||||||
inherit (lib.nvim.lua) toLuaObject;
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
|
|
||||||
cfg = config.vim.telescope;
|
cfg = config.vim.telescope;
|
||||||
|
|
Loading…
Reference in a new issue