This commit is contained in:
Ching Pei Yang 2024-10-05 18:15:27 +00:00 committed by GitHub
commit c1c6d3b4cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 909 additions and 337 deletions

View File

@ -28,10 +28,10 @@ configuration formats.
### `vim.maps` rewrite {#sec-vim-maps-rewrite}
Instead of specifying map modes using submodules (eg.: `vim.maps.normal`), a new
`mode` option has mode has been introduced. It can be either a string, or a list
of strings, where a string represents the short-name of the map mode(s), that
the mapping should be set for. See `:help map-modes` for more information.
Instead of specifying map modes using submodules (eg.: `vim.maps.normal`), a new `vim.keymaps`
submodule with support for a `mode` option has been introduced. It can be either a string, or a
list of strings, where a string represents the short-name of the map mode(s), that the mapping
should be set for. See `:help map-modes` for more information.
For example:
@ -42,10 +42,13 @@ vim.maps.normal."<leader>m" = { ... };
has to be replaced by
```nix
vim.maps."<leader>m" = {
mode = "n";
vim.keymaps = [
{
key = "<leader>m";
mode = "n";
}
...
};
];
```
### `vim.lsp.nvimCodeActionMenu` removed in favor of `vim.ui.fastaction` {#sec-nvim-code-action-menu-deprecation}

View File

@ -828,6 +828,39 @@
"type": "github"
}
},
"plugin-lz-n": {
"flake": false,
"locked": {
"lastModified": 1727574854,
"narHash": "sha256-qDWNleR2NHFkiEKE/+LNVOBRwEeskMC4dWTl5BTyZuE=",
"owner": "nvim-neorocks",
"repo": "lz.n",
"rev": "470173e3cbef763c6d1b918f3f129b67db75e1f8",
"type": "github"
},
"original": {
"owner": "nvim-neorocks",
"repo": "lz.n",
"type": "github"
}
},
"plugin-lzn-auto-require": {
"flake": false,
"locked": {
"lastModified": 1727636949,
"narHash": "sha256-BAOzN+XOrFAJwHmsF8JtZ2EyjP9283FD/I2TbFqGSEw=",
"owner": "horriblename",
"repo": "lzn-auto-require",
"rev": "55ecd60831dac8c01d6f3dcb63a30a63a1690eb8",
"type": "github"
},
"original": {
"owner": "horriblename",
"ref": "require-rewrite",
"repo": "lzn-auto-require",
"type": "github"
}
},
"plugin-mind-nvim": {
"flake": false,
"locked": {
@ -1859,6 +1892,8 @@
"plugin-lspkind": "plugin-lspkind",
"plugin-lspsaga": "plugin-lspsaga",
"plugin-lualine": "plugin-lualine",
"plugin-lz-n": "plugin-lz-n",
"plugin-lzn-auto-require": "plugin-lzn-auto-require",
"plugin-mind-nvim": "plugin-mind-nvim",
"plugin-minimap-vim": "plugin-minimap-vim",
"plugin-modes-nvim": "plugin-modes-nvim",

View File

@ -113,6 +113,17 @@
};
## Plugins
# Lazy loading
plugin-lz-n = {
url = "github:nvim-neorocks/lz.n";
flake = false;
};
plugin-lzn-auto-require = {
url = "github:horriblename/lzn-auto-require/require-rewrite";
flake = false;
};
# LSP plugins
plugin-nvim-lspconfig = {
url = "github:neovim/nvim-lspconfig";

View File

@ -67,6 +67,23 @@
mkLuaBinding binding.value action binding.description;
pushDownDefault = attr: mapAttrs (_: mkDefault) attr;
mkLznBinding = mode: key: action: desc: {
inherit mode desc key action;
};
mkSetLznBinding = binding: action: {
inherit action;
key = binding.value;
desc = binding.description;
};
mkSetLuaLznBinding = binding: action: {
inherit action;
key = binding.value;
lua = true;
desc = binding.description;
};
};
in
binds

View File

@ -6,7 +6,7 @@
inherit (lib.options) mkOption;
inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair;
inherit (lib.strings) hasPrefix removePrefix;
inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr;
inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf bool int;
# Get the names of all flake inputs that start with the given prefix.
fromInputs = {
@ -53,6 +53,190 @@
};
borderPresets = ["none" "single" "double" "rounded" "solid" "shadow"];
luaInline = lib.mkOptionType {
name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x;
};
lznKeysSpec = submodule {
options = {
desc = mkOption {
description = "Description of the key map";
type = nullOr str;
default = null;
};
noremap = mkOption {
description = "TBD";
type = bool;
default = false;
};
expr = mkOption {
description = "TBD";
type = bool;
default = false;
};
nowait = mkOption {
description = "TBD";
type = bool;
default = false;
};
ft = mkOption {
description = "TBD";
type = nullOr (listOf str);
default = null;
};
key = mkOption {
type = str;
description = "Key to bind to";
};
action = mkOption {
type = nullOr str;
default = null;
description = "Action to trigger.";
};
lua = mkOption {
type = bool;
default = false;
description = "If true the action is treated as a lua function instead of a vim command.";
};
mode = mkOption {
description = "Modes to bind in";
type = listOf str;
default = ["n" "x" "s" "o"];
};
};
};
lznPluginTableType = attrsOf lznPluginType;
lznPluginType = submodule {
options = {
## Should probably infer from the actual plugin somehow
## In general this is the name passed to packadd, so the dir name of the plugin
# name = mkOption {
# type= str;
# }
# Non-lz.n options
package = mkOption {
type = pluginType;
description = "Plugin package";
};
setupModule = mkOption {
type = nullOr str;
description = "Lua module to run setup function on.";
default = null;
};
setupOpts = mkOption {
type = submodule {freeformType = attrsOf anything;};
description = "Options to pass to the setup function";
default = {};
};
# lz.n options
enabled = mkOption {
type = nullOr (either bool str);
description = "When false, or if the lua function returns false, this plugin will not be included in the spec";
default = null;
};
beforeAll = mkOption {
type = nullOr str;
description = "Lua code to run before any plugins are loaded. This will be wrapped in a function.";
default = null;
};
before = mkOption {
type = nullOr str;
description = "Lua code to run before plugin is loaded. This will be wrapped in a function.";
default = null;
};
after = mkOption {
type = nullOr str;
description = "Lua code to run after plugin is loaded. This will be wrapped in a function.";
default = null;
};
event = mkOption {
description = "Lazy-load on event";
default = null;
type = let
event = submodule {
options = {
event = mkOption {
type = nullOr (either str (listOf str));
description = "Exact event name";
example = "BufEnter";
};
pattern = mkOption {
type = nullOr (either str (listOf str));
description = "Event pattern";
example = "BufEnter *.lua";
};
};
};
in
nullOr (oneOf [str (listOf str) event]);
};
cmd = mkOption {
description = "Lazy-load on command";
default = null;
type = nullOr (either str (listOf str));
};
ft = mkOption {
description = "Lazy-load on filetype";
default = null;
type = nullOr (either str (listOf str));
};
keys = mkOption {
description = "Lazy-load on key mapping";
default = null;
type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]);
example = ''
keys = [
{lhs = "<leader>s"; rhs = ":NvimTreeToggle<cr>"; desc = "Toggle NvimTree"}
]
'';
};
colorscheme = mkOption {
description = "Lazy-load on colorscheme.";
type = nullOr (either str (listOf str));
default = null;
};
priority = mkOption {
type = nullOr int;
description = "Only useful for stat plugins (not lazy-loaded) to force loading certain plugins first.";
default = null;
};
load = mkOption {
type = nullOr str;
default = null;
description = ''
Lua code to override the `vim.g.lz_n.load()` function for a single plugin.
This will be wrapped in a function
'';
};
};
};
in {
inherit extraPluginType fromInputs pluginType;

View File

@ -84,10 +84,7 @@
# built (or "normalized") plugins that are modified
builtStartPlugins = buildConfigPlugins vimOptions.startPlugins;
builtOptPlugins = map (package: {
plugin = package;
optional = true;
}) (buildConfigPlugins vimOptions.optPlugins);
builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins);
# additional Lua and Python3 packages, mapped to their respective functions
# to conform to the format mnw expects. end user should

View File

@ -50,6 +50,7 @@
"build"
"rc"
"warnings"
"lazy"
];
# Extra modules, such as deprecation warnings

View File

@ -3,32 +3,75 @@
lib,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.trivial) pipe;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.lists) flatten;
legacyMapModes = {
normal = ["n"];
insert = ["i"];
select = ["s"];
visual = ["v"];
terminal = ["t"];
normalVisualOp = ["n" "v" "o"];
visualOnly = ["n" "x"];
operator = ["o"];
insertCommand = ["i" "c"];
lang = ["l"];
command = ["c"];
};
cfg = config.vim;
in {
config = {
vim.maps = mkIf cfg.disableArrows {
"<up>" = {
mode = ["n" "i"];
action = "<nop>";
noremap = false;
};
"<down>" = {
mode = ["n" "i"];
action = "<nop>";
noremap = false;
};
"<left>" = {
mode = ["n" "i"];
action = "<nop>";
noremap = false;
};
"<right>" = {
mode = ["n" "i"];
action = "<nop>";
noremap = false;
};
};
vim.keymaps = mkMerge [
(
mkIf cfg.disableArrows [
{
key = "<up>";
mode = ["n" "i"];
action = "<nop>";
noremap = false;
}
{
key = "<down>";
mode = ["n" "i"];
action = "<nop>";
noremap = false;
}
{
key = "<left>";
mode = ["n" "i"];
action = "<nop>";
noremap = false;
}
{
key = "<right>";
mode = ["n" "i"];
action = "<nop>";
noremap = false;
}
]
)
(
pipe cfg.maps
[
(mapAttrsToList (
oldMode: keybinds:
mapAttrsToList (
key: bind:
bind
// {
inherit key;
mode = legacyMapModes.${oldMode};
}
)
keybinds
))
flatten
]
)
];
};
}

View File

@ -1,6 +1,6 @@
{lib, ...}: let
inherit (lib.options) mkOption;
inherit (lib.types) either str listOf attrsOf nullOr submodule bool;
inherit (lib.types) either str listOf attrsOf nullOr submodule;
inherit (lib.nvim.config) mkBool;
mapConfigOptions = {
@ -31,6 +31,10 @@
options =
mapConfigOptions
// {
key = mkOption {
type = str;
description = "The key that triggers this keybind.";
};
mode = mkOption {
type = either str (listOf str);
description = ''
@ -38,52 +42,56 @@
See `:help map-modes` for a list of modes.
'';
example = ''`["n" "v" "c"]` for normal, visual and command mode'';
};
};
};
# legacy stuff
mapOption = submodule {
options = mapConfigOptions;
};
mapOptions = mode:
legacyMapOption = mode:
mkOption {
description = "Mappings for ${mode} mode";
type = attrsOf mapOption;
type = attrsOf (submodule {
options = mapConfigOptions;
});
default = {};
};
in {
options.vim = {
maps = mkOption {
type = submodule {
freeformType = attrsOf mapType;
options = {
normal = mapOptions "normal";
insert = mapOptions "insert";
select = mapOptions "select";
visual = mapOptions "visual and select";
terminal = mapOptions "terminal";
normalVisualOp = mapOptions "normal, visual, select and operator-pending (same as plain 'map')";
visualOnly = mapOptions "visual only";
operator = mapOptions "operator-pending";
insertCommand = mapOptions "insert and command-line";
lang = mapOptions "insert, command-line and lang-arg";
command = mapOptions "command-line";
};
};
default = {};
keymaps = mkOption {
type = listOf mapType;
description = "Custom keybindings.";
example = ''
maps = {
"<leader>m" = {
vim.keymaps = [
{
key = "<leader>m";
mode = "n";
silent = true;
action = "<cmd>make<CR>";
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR>
};
action = ":make<CR>";
}
{
key = "<leader>l";
mode = ["n" "x"];
silent = true;
action = "<cmd>cnext<CR>";
}
];
'';
default = {};
};
maps = {
normal = legacyMapOption "normal";
insert = legacyMapOption "insert";
select = legacyMapOption "select";
visual = legacyMapOption "visual and select";
terminal = legacyMapOption "terminal";
normalVisualOp = legacyMapOption "normal, visual, select and operator-pending (same as plain 'map')";
visualOnly = legacyMapOption "visual only";
operator = legacyMapOption "operator-pending";
insertCommand = legacyMapOption "insert and command-line";
lang = legacyMapOption "insert, command-line and lang-arg";
command = legacyMapOption "command-line";
};
};
}

View File

@ -6,7 +6,7 @@
inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.attrsets) mapAttrs;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding mkSetLuaLznBinding;
inherit (lib.nvim.dag) entryAnywhere entryAfter;
cfg = config.vim.debugger.nvim-dap;
@ -49,24 +49,33 @@ in {
];
})
(mkIf (cfg.enable && cfg.ui.enable) {
vim.startPlugins = ["nvim-dap-ui" "nvim-nio"];
vim.startPlugins = ["nvim-nio"];
vim.pluginRC.nvim-dap-ui = entryAfter ["nvim-dap"] (''
local dapui = require("dapui")
dapui.setup()
''
+ optionalString cfg.ui.autoStart ''
vim.lazy.plugins = [
{
package = "nvim-dap-ui";
setupModule = "dapui";
setupOpts = {};
keys = [
(mkSetLuaLznBinding mappings.toggleDapUI "function() require('dapui').toggle() end")
];
}
];
vim.pluginRC.nvim-dap-ui = entryAfter ["nvim-dap"] (
optionalString cfg.ui.autoStart ''
dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open()
require("dapui").open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close()
require("dapui").close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close()
require("dapui").close()
end
'');
vim.maps.normal = mkSetLuaBinding mappings.toggleDapUI "require('dapui').toggle";
''
);
})
];
}

View File

@ -5,10 +5,9 @@
...
}: let
inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.binds) mkBinding;
inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) mkLznBinding;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.binds) pushDownDefault;
cfg = config.vim.filetree.nvimTree;
@ -16,19 +15,27 @@
inherit (self.options.vim.filetree.nvimTree) mappings;
in {
config = mkIf cfg.enable {
vim.startPlugins = ["nvim-tree-lua"];
vim.maps.normal = mkMerge [
(mkBinding cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description)
(mkBinding cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description)
(mkBinding cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description)
(mkBinding cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description)
];
vim.binds.whichKey.register = pushDownDefault {
"<leader>t" = "+NvimTree";
};
vim.lazy = {
plugins = [
{
package = "nvim-tree-lua";
setupModule = "nvim-tree";
inherit (cfg) setupOpts;
cmd = ["NvimTreeClipboard" "NvimTreeClose" "NvimTreeCollapse" "NvimTreeCollapseKeepBuffers" "NvimTreeFindFile" "NvimTreeFindFileToggle" "NvimTreeFocus" "NvimTreeHiTest" "NvimTreeOpen" "NvimTreeRefresh" "NvimTreeResize" "NvimTreeToggle"];
keys = [
(mkLznBinding ["n"] cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description)
(mkLznBinding ["n"] cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description)
(mkLznBinding ["n"] cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description)
(mkLznBinding ["n"] cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description)
];
}
];
};
vim.pluginRC.nvimtreelua = entryAnywhere ''
${
optionalString cfg.setupOpts.disable_netrw ''
@ -38,10 +45,9 @@ in {
''
}
require'nvim-tree'.setup(${toLuaObject cfg.setupOpts})
${
optionalString cfg.openOnSetup ''
require('lz.n').trigger_load("nvim-tree-lua")
-- autostart behaviour
-- Open on startup has been deprecated
-- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup

View File

@ -3,9 +3,8 @@
lib,
...
}: let
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding pushDownDefault;
inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLznBinding pushDownDefault;
cfg = config.vim.lsp;
@ -15,15 +14,22 @@
in {
config = mkIf (cfg.enable && cfg.trouble.enable) {
vim = {
startPlugins = ["trouble"];
lazy.plugins = [
{
package = "trouble";
setupModule = "trouble";
inherit (cfg.trouble) setupOpts;
maps.normal = mkMerge [
(mkSetBinding mappings.toggle "<cmd>TroubleToggle<CR>")
(mkSetBinding mappings.workspaceDiagnostics "<cmd>TroubleToggle workspace_diagnostics<CR>")
(mkSetBinding mappings.documentDiagnostics "<cmd>TroubleToggle document_diagnostics<CR>")
(mkSetBinding mappings.lspReferences "<cmd>TroubleToggle lsp_references<CR>")
(mkSetBinding mappings.quickfix "<cmd>TroubleToggle quickfix<CR>")
(mkSetBinding mappings.locList "<cmd>TroubleToggle loclist<CR>")
cmd = "Trouble";
keys = [
(mkSetLznBinding mappings.toggle "<cmd>TroubleToggle<CR>")
(mkSetLznBinding mappings.workspaceDiagnostics "<cmd>TroubleToggle workspace_diagnostics<CR>")
(mkSetLznBinding mappings.documentDiagnostics "<cmd>TroubleToggle document_diagnostics<CR>")
(mkSetLznBinding mappings.lspReferences "<cmd>TroubleToggle lsp_references<CR>")
(mkSetLznBinding mappings.quickfix "<cmd>TroubleToggle quickfix<CR>")
(mkSetLznBinding mappings.locList "<cmd>TroubleToggle loclist<CR>")
];
}
];
binds.whichKey.register = pushDownDefault {
@ -31,11 +37,6 @@ in {
"<leader>x" = "+Trouble";
"<leader>lw" = "Workspace";
};
pluginRC.trouble = entryAnywhere ''
-- Enable trouble diagnostics viewer
require("trouble").setup {}
'';
};
};
}

View File

@ -1,11 +1,14 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption;
in {
options.vim.lsp = {
trouble = {
enable = mkEnableOption "trouble diagnostics viewer";
setupOpts = mkPluginSetupOption "Telescope" {};
mappings = {
toggle = mkMappingOption "Toggle trouble [trouble]" "<leader>xx";
workspaceDiagnostics = mkMappingOption "Workspace diagnostics [trouble]" "<leader>lwd";

View File

@ -4,55 +4,45 @@
...
}: let
inherit (builtins) toJSON;
inherit (lib.lists) optionals;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf;
inherit (lib.meta) getExe;
inherit (lib.nvim.binds) mkBinding;
inherit (lib.nvim.dag) entryAnywhere entryAfter;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.binds) mkLznBinding;
cfg = config.vim.terminal.toggleterm;
in {
config = mkMerge [
(
mkIf cfg.enable {
vim = {
startPlugins = [
"toggleterm-nvim"
config = mkIf cfg.enable {
vim = {
lazy.plugins = [
{
package = "toggleterm-nvim";
cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"];
keys = [
(mkLznBinding ["n"] cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal")
{key = cfg.lazygit.mappings.open;}
];
maps.normal = mkBinding cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal";
setupModule = "toggleterm";
inherit (cfg) setupOpts;
after = optionalString cfg.lazygit.enable ''
local terminal = require 'toggleterm.terminal'
local lazygit = terminal.Terminal:new({
cmd = '${
if (cfg.lazygit.package != null)
then getExe cfg.lazygit.package
else "lazygit"
}',
direction = '${cfg.lazygit.direction}',
hidden = true,
on_open = function(term)
vim.cmd("startinsert!")
end
})
pluginRC.toggleterm = entryAnywhere ''
require("toggleterm").setup(${toLuaObject cfg.setupOpts})
vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = 'Open lazygit [toggleterm]'})
'';
};
}
)
(
mkIf (cfg.enable && cfg.lazygit.enable)
{
vim.startPlugins = optionals (cfg.lazygit.package != null) [
cfg.lazygit.package
];
vim.pluginRC.toggleterm-lazygit = entryAfter ["toggleterm"] ''
local terminal = require 'toggleterm.terminal'
local lazygit = terminal.Terminal:new({
cmd = '${
if (cfg.lazygit.package != null)
then getExe cfg.lazygit.package
else "lazygit"
}',
direction = '${cfg.lazygit.direction}',
hidden = true,
on_open = function(term)
vim.cmd("startinsert!")
end
})
vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = 'Open lazygit [toggleterm]'})
'';
}
)
];
}
];
};
};
}

View File

@ -4,15 +4,20 @@
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.strings) optionalString;
cfg = config.vim.binds.cheatsheet;
in {
config = mkIf cfg.enable {
vim.startPlugins = ["cheatsheet-nvim"];
vim.lazy.plugins = [
{
package = "cheatsheet-nvim";
setupModule = "cheatsheet";
setupOpts = {};
cmd = ["Cheatsheet" "CheatsheetEdit"];
vim.pluginRC.cheaetsheet-nvim = entryAnywhere ''
require('cheatsheet').setup({})
'';
before = optionalString config.vim.lazy.enable "require('lz.n').trigger_load('telescope')";
}
];
};
}

View File

@ -8,9 +8,16 @@
cfg = config.vim.utility.diffview-nvim;
in {
config = mkIf cfg.enable {
vim.startPlugins = [
"diffview-nvim"
"plenary-nvim"
];
vim = {
startPlugins = ["plenary-nvim"];
lazy.plugins = [
{
package = "diffview-nvim";
cmd = ["DiffviewClose" "DiffviewFileHistory" "DiffviewFocusFiles" "DiffviewLog" "DiffviewOpen" "DiffviewRefresh" "DiffviewToggleFiles"];
setupModule = "diffview";
inherit (cfg) setupOpts;
}
];
};
};
}

View File

@ -1,7 +1,9 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption;
inherit (lib.nvim.types) mkPluginSetupOption;
in {
options.vim.utility.diffview-nvim = {
enable = mkEnableOption "diffview-nvim: cycle through diffs for all modified files for any git rev";
setupOpts = mkPluginSetupOption "Fidget" {};
};
}

View File

@ -4,20 +4,22 @@
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.utility.icon-picker;
in {
config = mkIf cfg.enable {
vim.startPlugins = [
"icon-picker-nvim"
"dressing-nvim"
];
vim.startPlugins = ["dressing-nvim"];
vim.pluginRC.icon-picker = entryAnywhere ''
require("icon-picker").setup({
disable_legacy_commands = true
})
'';
vim.lazy.plugins = [
{
package = "icon-picker-nvim";
setupModule = "icon-picker";
setupOpts = {
disable_legacy_commands = true;
};
cmd = ["IconPickerInsert" "IconPickerNormal" "IconPickerYank"];
}
];
};
}

View File

@ -3,71 +3,59 @@
lib,
...
}: let
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.binds) mkBinding;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) mkLznBinding;
cfg = config.vim.utility.motion.leap;
in {
config = mkIf cfg.enable {
vim.startPlugins = [
"leap-nvim"
"vim-repeat"
];
vim = {
startPlugins = ["vim-repeat"];
lazy.plugins = [
{
package = "leap-nvim";
keys = [
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapForwardTo "<Plug>(leap-forward-to)" "Leap forward to")
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapBackwardTo "<Plug>(leap-backward-to)" "Leap backward to")
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapForwardTill "<Plug>(leap-forward-till)" "Leap forward till")
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapBackwardTill "<Plug>(leap-backward-till)" "Leap backward till")
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapFromWindow "<Plug>(leap-from-window)" "Leap from window")
];
vim.maps.normal = mkMerge [
(mkBinding cfg.mappings.leapForwardTo "<Plug>(leap-forward-to)" "Leap forward to")
(mkBinding cfg.mappings.leapBackwardTo "<Plug>(leap-backward-to)" "Leap backward to")
(mkBinding cfg.mappings.leapFromWindow "<Plug>(leap-from-window)" "Leap from window")
];
vim.maps.operator = mkMerge [
(mkBinding cfg.mappings.leapForwardTo "<Plug>(leap-forward-to)" "Leap forward to")
(mkBinding cfg.mappings.leapBackwardTo "<Plug>(leap-backward-to)" "Leap backward to")
(mkBinding cfg.mappings.leapForwardTill "<Plug>(leap-forward-till)" "Leap forward till")
(mkBinding cfg.mappings.leapBackwardTill "<Plug>(leap-backward-till)" "Leap backward till")
(mkBinding cfg.mappings.leapFromWindow "<Plug>(leap-from-window)" "Leap from window")
];
vim.maps.visualOnly = mkMerge [
(mkBinding cfg.mappings.leapForwardTo "<Plug>(leap-forward-to)" "Leap forward to")
(mkBinding cfg.mappings.leapBackwardTo "<Plug>(leap-backward-to)" "Leap backward to")
(mkBinding cfg.mappings.leapForwardTill "<Plug>(leap-forward-till)" "Leap forward till")
(mkBinding cfg.mappings.leapBackwardTill "<Plug>(leap-backward-till)" "Leap backward till")
(mkBinding cfg.mappings.leapFromWindow "<Plug>(leap-from-window)" "Leap from window")
];
vim.pluginRC.leap-nvim = entryAnywhere ''
require('leap').opts = {
max_phase_one_targets = nil,
highlight_unlabeled_phase_one_targets = false,
max_highlighted_traversal_targets = 10,
case_sensitive = false,
equivalence_classes = { ' \t\r\n', },
substitute_chars = {},
safe_labels = {
"s", "f", "n", "u", "t", "/",
"S", "F", "N", "L", "H", "M", "U", "G", "T", "?", "Z"
},
labels = {
"s", "f", "n",
"j", "k", "l", "h", "o", "d", "w", "e", "m", "b",
"u", "y", "v", "r", "g", "t", "c", "x", "/", "z",
"S", "F", "N",
"J", "K", "L", "H", "O", "D", "W", "E", "M", "B",
"U", "Y", "V", "R", "G", "T", "C", "X", "?", "Z"
},
special_keys = {
repeat_search = '<enter>',
next_phase_one_target = '<enter>',
next_target = {'<enter>', ';'},
prev_target = {'<tab>', ','},
next_group = '<space>',
prev_group = '<tab>',
multi_accept = '<enter>',
multi_revert = '<backspace>',
},
}
'';
after = ''
require('leap').opts = {
max_phase_one_targets = nil,
highlight_unlabeled_phase_one_targets = false,
max_highlighted_traversal_targets = 10,
case_sensitive = false,
equivalence_classes = { ' \t\r\n', },
substitute_chars = {},
safe_labels = {
"s", "f", "n", "u", "t", "/",
"S", "F", "N", "L", "H", "M", "U", "G", "T", "?", "Z"
},
labels = {
"s", "f", "n",
"j", "k", "l", "h", "o", "d", "w", "e", "m", "b",
"u", "y", "v", "r", "g", "t", "c", "x", "/", "z",
"S", "F", "N",
"J", "K", "L", "H", "O", "D", "W", "E", "M", "B",
"U", "Y", "V", "R", "G", "T", "C", "X", "?", "Z"
},
special_keys = {
repeat_search = '<enter>',
next_phase_one_target = '<enter>',
next_target = {'<enter>', ';'},
prev_target = {'<tab>', ','},
next_group = '<space>',
prev_group = '<tab>',
multi_accept = '<enter>',
multi_revert = '<backspace>',
},
}
'';
}
];
};
};
}

View File

@ -4,11 +4,11 @@
lib,
...
}: let
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.binds) pushDownDefault;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) addDescriptionsToMappings;
inherit (lib.strings) optionalString;
inherit (lib.lists) optionals;
inherit (lib.nvim.binds) pushDownDefault mkSetLznBinding;
cfg = config.vim.telescope;
self = import ./telescope.nix {inherit pkgs lib;};
@ -18,45 +18,58 @@
in {
config = mkIf cfg.enable {
vim = {
startPlugins = [
"telescope"
"plenary-nvim"
];
startPlugins = ["plenary-nvim"];
maps.normal = mkMerge [
(mkSetBinding mappings.findFiles "<cmd> Telescope find_files<CR>")
(mkSetBinding mappings.liveGrep "<cmd> Telescope live_grep<CR>")
(mkSetBinding mappings.buffers "<cmd> Telescope buffers<CR>")
(mkSetBinding mappings.helpTags "<cmd> Telescope help_tags<CR>")
(mkSetBinding mappings.open "<cmd> Telescope<CR>")
(mkSetBinding mappings.resume "<cmd> Telescope resume<CR>")
lazy.plugins = [
{
package = "telescope";
setupModule = "telescope";
inherit (cfg) setupOpts;
# FIXME: how do I deal with extensions? set all as deps?
after = ''
local telescope = require("telescope")
${optionalString config.vim.ui.noice.enable "telescope.load_extension('noice')"}
${optionalString config.vim.notify.nvim-notify.enable "telescope.load_extension('notify')"}
${optionalString config.vim.projects.project-nvim.enable "telescope.load_extension('projects')"}
'';
(mkSetBinding mappings.gitCommits "<cmd> Telescope git_commits<CR>")
(mkSetBinding mappings.gitBufferCommits "<cmd> Telescope git_bcommits<CR>")
(mkSetBinding mappings.gitBranches "<cmd> Telescope git_branches<CR>")
(mkSetBinding mappings.gitStatus "<cmd> Telescope git_status<CR>")
(mkSetBinding mappings.gitStash "<cmd> Telescope git_stash<CR>")
cmd = ["Telescope"];
(mkIf config.vim.lsp.enable (mkMerge [
(mkSetBinding mappings.lspDocumentSymbols "<cmd> Telescope lsp_document_symbols<CR>")
(mkSetBinding mappings.lspWorkspaceSymbols "<cmd> Telescope lsp_workspace_symbols<CR>")
keys =
[
(mkSetLznBinding mappings.findFiles "<cmd> Telescope find_files<CR>")
(mkSetLznBinding mappings.liveGrep "<cmd> Telescope live_grep<CR>")
(mkSetLznBinding mappings.buffers "<cmd> Telescope buffers<CR>")
(mkSetLznBinding mappings.helpTags "<cmd> Telescope help_tags<CR>")
(mkSetLznBinding mappings.open "<cmd> Telescope<CR>")
(mkSetBinding mappings.lspReferences "<cmd> Telescope lsp_references<CR>")
(mkSetBinding mappings.lspImplementations "<cmd> Telescope lsp_implementations<CR>")
(mkSetBinding mappings.lspDefinitions "<cmd> Telescope lsp_definitions<CR>")
(mkSetBinding mappings.lspTypeDefinitions "<cmd> Telescope lsp_type_definitions<CR>")
(mkSetBinding mappings.diagnostics "<cmd> Telescope diagnostics<CR>")
]))
(mkSetLznBinding mappings.gitCommits "<cmd> Telescope git_commits<CR>")
(mkSetLznBinding mappings.gitBufferCommits "<cmd> Telescope git_bcommits<CR>")
(mkSetLznBinding mappings.gitBranches "<cmd> Telescope git_branches<CR>")
(mkSetLznBinding mappings.gitStatus "<cmd> Telescope git_status<CR>")
(mkSetLznBinding mappings.gitStash "<cmd> Telescope git_stash<CR>")
]
++ (optionals config.vim.lsp.enable [
(mkSetLznBinding mappings.lspDocumentSymbols "<cmd> Telescope lsp_document_symbols<CR>")
(mkSetLznBinding mappings.lspWorkspaceSymbols "<cmd> Telescope lsp_workspace_symbols<CR>")
(
mkIf config.vim.treesitter.enable
(mkSetBinding mappings.treesitter "<cmd> Telescope treesitter<CR>")
)
(
mkIf config.vim.projects.project-nvim.enable
(mkSetBinding mappings.findProjects "<cmd> Telescope projects<CR>")
)
(mkSetLznBinding mappings.lspReferences "<cmd> Telescope lsp_references<CR>")
(mkSetLznBinding mappings.lspImplementations "<cmd> Telescope lsp_implementations<CR>")
(mkSetLznBinding mappings.lspDefinitions "<cmd> Telescope lsp_definitions<CR>")
(mkSetLznBinding mappings.lspTypeDefinitions "<cmd> Telescope lsp_type_definitions<CR>")
(mkSetLznBinding mappings.diagnostics "<cmd> Telescope diagnostics<CR>")
])
++ (
optionals config.vim.treesitter.enable [
(mkSetLznBinding mappings.treesitter "<cmd> Telescope treesitter<CR>")
]
)
++ (
optionals config.vim.projects.project-nvim.enable [
(mkSetLznBinding mappings.findProjects "<cmd Telescope projects<CR>")
]
);
}
];
binds.whichKey.register = pushDownDefault {
@ -66,29 +79,6 @@ in {
"<leader>fv" = "Telescope Git";
"<leader>fvc" = "Commits";
};
pluginRC.telescope = entryAnywhere ''
local telescope = require('telescope')
telescope.setup(${toLuaObject cfg.setupOpts})
${
if config.vim.ui.noice.enable
then "telescope.load_extension('noice')"
else ""
}
${
if config.vim.notify.nvim-notify.enable
then "telescope.load_extension('notify')"
else ""
}
${
if config.vim.projects.project-nvim.enable
then "telescope.load_extension('projects')"
else ""
}
'';
};
};
}

View File

@ -4,16 +4,19 @@
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.visuals.fidget-nvim;
in {
config = mkIf cfg.enable {
vim.startPlugins = ["fidget-nvim"];
vim.pluginRC.fidget-nvim = entryAnywhere ''
require'fidget'.setup(${toLuaObject cfg.setupOpts})
'';
vim.lazy = {
plugins = [
{
package = "fidget-nvim";
setupModule = "fidget";
event = "LspAttach";
inherit (cfg) setupOpts;
}
];
};
};
}

View File

@ -0,0 +1,85 @@
{
lib,
config,
...
}: let
inherit (builtins) toJSON typeOf head length tryEval filter;
inherit (lib.modules) mkIf;
inherit (lib.generators) mkLuaInline;
inherit (lib.strings) optionalString;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.dag) entryBefore;
cfg = config.vim.lazy;
toLuaLznKeySpec = {
desc,
noremap,
expr,
nowait,
ft,
key,
action,
lua,
mode,
}: {
"@1" = key;
"@2" =
if lua
then mkLuaInline action
else action;
inherit desc noremap expr nowait ft mode;
};
toLuaLznSpec = spec: let
name =
if typeOf spec.package == "string"
then spec.package
else if (spec.package ? pname && (tryEval spec.package.pname).success)
then spec.package.pname
else spec.package.name;
in
(removeAttrs spec ["package" "setupModule" "setupOpts" "keys"])
// {
"@1" = name;
before =
if spec.before != null
then
mkLuaInline ''
function()
${spec.before}
end
''
else null;
after =
if spec.setupModule == null && spec.after == null
then null
else
mkLuaInline ''
function()
${
optionalString (spec.setupModule != null)
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})"
}
${optionalString (spec.after != null) spec.after}
end
'';
keys =
if typeOf spec.keys == "list" && length spec.keys > 0 && typeOf (head spec.keys) == "set"
then map toLuaLznKeySpec (filter (keySpec: keySpec.key != null) spec.keys)
# empty list or str or (listOf str)
else spec.keys;
};
lznSpecs = map toLuaLznSpec cfg.plugins;
in {
config.vim = mkIf cfg.enable {
startPlugins = ["lz-n" "lzn-auto-require"];
optPlugins = map (plugin: plugin.package) cfg.plugins;
luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] ''
require('lz.n').load(${toLuaObject lznSpecs})
'';
};
}

View File

@ -0,0 +1,6 @@
_: {
imports = [
./lazy.nix
./config.nix
];
}

View File

@ -0,0 +1,205 @@
{lib, ...}: let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) enum listOf submodule nullOr str bool int attrsOf anything either oneOf;
inherit (lib.nvim.types) pluginType;
inherit (lib.nvim.config) mkBool;
lznKeysSpec = submodule {
options = {
key = mkOption {
type = nullOr str;
description = "Key to bind to. If key is null this entry is ignored.";
};
action = mkOption {
type = nullOr str;
default = null;
description = "Action to trigger.";
};
lua = mkBool false ''
If true, `action` is considered to be lua code.
Thus, it will not be wrapped in `""`.
'';
desc = mkOption {
description = "Description of the key map";
type = nullOr str;
default = null;
};
ft = mkOption {
description = "TBD";
type = nullOr (listOf str);
default = null;
};
mode = mkOption {
description = "Modes to bind in";
type = listOf str;
default = ["n" "x" "s" "o"];
};
noremap = mkBool true "Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default.";
expr = mkBool false "Means that the action is actually an expression. Equivalent to adding <expr> to a map.";
nowait = mkBool false "Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map.";
};
};
lznPluginType = submodule {
options = {
## Should probably infer from the actual plugin somehow
## In general this is the name passed to packadd, so the dir name of the plugin
# name = mkOption {
# type= str;
# }
# Non-lz.n options
package = mkOption {
type = pluginType;
description = "Plugin package";
};
setupModule = mkOption {
type = nullOr str;
description = "Lua module to run setup function on.";
default = null;
};
setupOpts = mkOption {
type = submodule {freeformType = attrsOf anything;};
description = "Options to pass to the setup function";
default = {};
};
# lz.n options
enabled = mkOption {
type = nullOr (either bool str);
description = "When false, or if the lua function returns false, this plugin will not be included in the spec";
default = null;
};
beforeAll = mkOption {
type = nullOr str;
description = "Lua code to run before any plugins are loaded. This will be wrapped in a function.";
default = null;
};
before = mkOption {
type = nullOr str;
description = "Lua code to run before plugin is loaded. This will be wrapped in a function.";
default = null;
};
after = mkOption {
type = nullOr str;
description = "Lua code to run after plugin is loaded. This will be wrapped in a function.";
default = null;
};
event = mkOption {
description = "Lazy-load on event";
default = null;
type = let
event = submodule {
options = {
event = mkOption {
type = nullOr (either str (listOf str));
description = "Exact event name";
example = "BufEnter";
};
pattern = mkOption {
type = nullOr (either str (listOf str));
description = "Event pattern";
example = "BufEnter *.lua";
};
};
};
in
nullOr (oneOf [str (listOf str) event]);
};
cmd = mkOption {
description = "Lazy-load on command";
default = null;
type = nullOr (either str (listOf str));
};
ft = mkOption {
description = "Lazy-load on filetype";
default = null;
type = nullOr (either str (listOf str));
};
keys = mkOption {
description = "Lazy-load on key mapping";
default = null;
type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]);
example = ''
keys = [
{
mode = "n";
key = "<leader>s";
action = ":DapStepOver<cr>";
desc = "DAP Step Over";
}
{
mode = ["n", "x"];
key = "<leader>dc";
action = "function() require('dap').continue() end";
lua = true;
desc = "DAP Continue";
}
]
'';
};
colorscheme = mkOption {
description = "Lazy-load on colorscheme.";
type = nullOr (either str (listOf str));
default = null;
};
priority = mkOption {
type = nullOr int;
description = "Only useful for stat plugins (not lazy-loaded) to force loading certain plugins first.";
default = null;
};
load = mkOption {
type = nullOr str;
default = null;
description = ''
Lua code to override the `vim.g.lz_n.load()` function for a single plugin.
This will be wrapped in a function
'';
};
};
};
in {
options.vim.lazy = {
enable = mkEnableOption "plugin lazy-loading" // {default = true;};
loader = mkOption {
description = "Lazy loader to use";
type = enum ["lz.n"];
default = "lz.n";
};
plugins = mkOption {
default = [];
type = listOf lznPluginType;
description = "list of plugins to lazy load";
example = ''
[
{
package = "toggleterm-nvim";
after = lib.generators.mkLuaInline "function() require('toggleterm').setup{} end";
cmd = ["ToggleTerm"];
}
]
'';
};
};
}

View File

@ -3,9 +3,9 @@
lib,
...
}: let
inherit (builtins) map mapAttrs filter removeAttrs attrNames;
inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList;
inherit (lib.strings) concatLines concatMapStringsSep;
inherit (builtins) map mapAttrs filter;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.strings) concatLines concatMapStringsSep optionalString;
inherit (lib.trivial) showWarnings;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
@ -41,40 +41,9 @@ in {
inherit (keymap) desc silent nowait script expr unique noremap;
};
toLuaKeymap = {
name,
value,
}: "vim.keymap.set(${toLuaObject value.mode}, ${toLuaObject name}, ${toLuaObject (getAction value)}, ${toLuaObject (getOpts value)})";
toLuaKeymap = bind: "vim.keymap.set(${toLuaObject bind.mode}, ${toLuaObject bind.key}, ${toLuaObject (getAction bind)}, ${toLuaObject (getOpts bind)})";
namedModes = {
"normal" = ["n"];
"insert" = ["i"];
"select" = ["s"];
"visual" = ["v"];
"terminal" = ["t"];
"normalVisualOp" = ["n" "v" "o"];
"visualOnly" = ["n" "x"];
"operator" = ["o"];
"insertCommand" = ["i" "c"];
"lang" = ["l"];
"command" = ["c"];
};
maps =
removeAttrs cfg.maps (attrNames namedModes)
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.normal;}) cfg.maps.normal
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.insert;}) cfg.maps.insert
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.select;}) cfg.maps.select
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.visual;}) cfg.maps.visual
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.terminal;}) cfg.maps.terminal
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.normalVisualOp;}) cfg.maps.normalVisualOp
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.visualOnly;}) cfg.maps.visualOnly
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.operator;}) cfg.maps.operator
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.insertCommand;}) cfg.maps.insertCommand
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.lang;}) cfg.maps.lang
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.command;}) cfg.maps.command;
keymaps = concatLines (map toLuaKeymap (attrsToList (filterAttrs (_: value: value != null) maps)));
keymaps = concatLines (map toLuaKeymap cfg.keymaps);
in {
vim = {
luaConfigRC = {
@ -86,6 +55,8 @@ in {
pluginConfigs = entryAfter ["optionsScript"] pluginConfigs;
extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs;
mappings = entryAfter ["extraPluginConfigs"] keymaps;
# FIXME: put this somewhere less stupid
footer = entryAfter ["mappings"] (optionalString config.vim.lazy.enable "require('lzn-auto-require').enable()");
};
builtLuaConfigRC = let