This commit is contained in:
raf 2026-02-03 17:46:18 -05:00 committed by GitHub
commit 83a6d014b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 271 additions and 131 deletions

View file

@ -10,7 +10,6 @@
# such as spellchecking, mappings, and the init script (init.vim). # such as spellchecking, mappings, and the init script (init.vim).
neovim = map (p: ./neovim + "/${p}") [ neovim = map (p: ./neovim + "/${p}") [
"init" "init"
"mappings"
]; ];
# Individual plugin modules, separated by the type of plugin. # Individual plugin modules, separated by the type of plugin.

View file

@ -5,8 +5,10 @@
./clipboard.nix ./clipboard.nix
./debug.nix ./debug.nix
./diagnostics.nix ./diagnostics.nix
./filetype.nix
./highlight.nix ./highlight.nix
./lsp.nix ./lsp.nix
./mappings.nix
./spellcheck.nix ./spellcheck.nix
./util.nix ./util.nix
]; ];

View file

@ -0,0 +1,121 @@
{
config,
lib,
...
}: let
inherit (lib.options) mkOption;
inherit (lib.types) nullOr either oneOf attrsOf str listOf submodule ints;
inherit (lib.nvim.types) luaInline;
inherit (lib.nvim.dag) entryBefore;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim;
# vim.filetype.add() is quite robust, but this makes for a very
# complex type that we have to handle. It takes a string, a Lua function
# or a dictionary with the priority of the extension.
ftOptionType = attrsOf (oneOf [
str # "filetype"
luaInline # `function(path, bufnr) ... end`
# { 'dosini', { priority = 10 } },
(listOf (either str (submodule {
options = {
priority = mkOption {
type = ints.unsigned;
description = ''
`vim.filetype.add()` can take an optional priority value to resolve
conflicts where a filetype is registered by multiple patterns. When
priority is specified, file with the higher priority value will be
matched first on conflict.
'';
};
};
})))
]);
in {
options.vim.filetype = mkOption {
type = submodule {
options = {
extension = mkOption {
type = nullOr ftOptionType;
default = null;
description = "register a new filetype by extension";
};
filename = mkOption {
type = nullOr ftOptionType;
default = null;
description = "register a new filetype by file name";
};
pattern = mkOption {
type = nullOr ftOptionType;
default = null;
description = "register a new filetype by pattern";
};
};
};
default = {};
example = {
filename = {
".foorc" = "toml";
"/etc/foo/config" = "toml";
"todo.txt" = "todotxt";
};
pattern = {
".*%.scm" = "query";
".*README.(%a+)" = ''
function(path, bufnr, ext)
if ext == 'md' then
return 'markdown'
elseif ext == 'rst' then
return 'rst'
end
end,
'';
};
extension = {
mdx = "markdown";
bar = lib.mkLuaInline ''
bar = function(path, bufnr)
if some_condition() then
return 'barscript', function(bufnr)
-- Set a buffer variable
vim.b[bufnr].barscript_version = 2
end
end
return 'bar'
end,
'';
};
};
description = ''
Additional filetypes to be registered through `vim.filetype.add()`
Filetype mappings can be added either by extension or by filename. The
key can be either the "tail" or the full file path. The full file path
is checked first, followed by the file name. If a match is not found
using the filename, then the filename is matched against the list of
Lua patterns (sorted by priority) until a match is found.
If a pattern matching does not find a filetype, then the file extension
is used.
See `:h vim.filetype.add()` for more details.
'';
};
config = {
# XXX: some plugins can be loaded on filetype, and unless the filetypes
# are registered first, chances are custom filetypes will not be usable
# for lazy-loading on ft.
vim.luaConfigRC.filetype = entryBefore ["lazyConfigs"] ''
vim.filetype.add(${toLuaObject cfg.filetype})
'';
};
}

View file

@ -1,19 +1,31 @@
{lib, ...}: let {
config,
lib,
...
}: let
inherit (lib.modules) mkMerge;
inherit (lib.options) mkOption literalMD; inherit (lib.options) mkOption literalMD;
inherit (lib.types) either str listOf attrsOf nullOr submodule; inherit (lib.types) either str listOf attrsOf nullOr submodule;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.lists) flatten;
inherit (lib.trivial) pipe;
inherit (lib.nvim.config) mkBool; inherit (lib.nvim.config) mkBool;
mapConfigOptions = { mapConfigOptions = {
desc = mkOption { desc = mkOption {
type = nullOr str; type = nullOr str;
default = null; default = null;
description = "A description of this keybind, to be shown in which-key, if you have it enabled."; description = ''
Description for the keybind, to be shown in which-key, if you have enabled
in the module system.
'';
}; };
action = mkOption { action = mkOption {
type = str; type = str;
description = "The command to execute."; description = "The command to execute.";
}; };
lua = mkBool false '' lua = mkBool false ''
If true, `action` is considered to be lua code. If true, `action` is considered to be lua code.
Thus, it will not be wrapped in `""`. Thus, it will not be wrapped in `""`.
@ -55,6 +67,22 @@
}); });
default = {}; default = {};
}; };
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 { in {
options.vim = { options.vim = {
keymaps = mkOption { keymaps = mkOption {
@ -94,4 +122,27 @@ in {
command = legacyMapOption "command-line"; command = legacyMapOption "command-line";
}; };
}; };
config = {
vim.keymaps = mkMerge [
(
pipe cfg.maps
[
(mapAttrsToList (
oldMode: keybinds:
mapAttrsToList (
key: bind:
bind
// {
inherit key;
mode = legacyMapModes.${oldMode};
}
)
keybinds
))
flatten
]
)
];
};
} }

View file

@ -3,11 +3,6 @@
lib, lib,
... ...
}: let }: let
inherit (lib.modules) mkMerge;
inherit (lib.trivial) pipe;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.lists) flatten;
legacyMapModes = { legacyMapModes = {
normal = ["n"]; normal = ["n"];
insert = ["i"]; insert = ["i"];
@ -24,26 +19,4 @@
cfg = config.vim; cfg = config.vim;
in { in {
config = {
vim.keymaps = mkMerge [
(
pipe cfg.maps
[
(mapAttrsToList (
oldMode: keybinds:
mapAttrsToList (
key: bind:
bind
// {
inherit key;
mode = legacyMapModes.${oldMode};
}
)
keybinds
))
flatten
]
)
];
};
} }

View file

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