2024-04-20 15:09:11 +00:00
|
|
|
{
|
|
|
|
config,
|
2024-10-21 14:20:02 +00:00
|
|
|
pkgs,
|
2024-04-20 15:09:11 +00:00
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
2024-04-20 16:00:20 +00:00
|
|
|
inherit (lib.modules) mkIf mkRenamedOptionModule;
|
|
|
|
inherit (lib.options) mkOption mkEnableOption literalExpression;
|
2024-10-21 14:20:02 +00:00
|
|
|
inherit (lib.strings) concatLines;
|
|
|
|
inherit (lib.attrsets) mapAttrsToList;
|
|
|
|
inherit (lib.types) listOf str attrsOf;
|
2024-04-20 15:09:11 +00:00
|
|
|
inherit (lib.nvim.lua) listToLuaTable;
|
|
|
|
inherit (lib.nvim.dag) entryAfter;
|
|
|
|
|
2024-04-20 16:00:20 +00:00
|
|
|
cfg = config.vim.spellcheck;
|
2024-04-20 15:09:11 +00:00
|
|
|
in {
|
2024-04-20 16:00:20 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule ["vim" "spellChecking"] ["vim" "spellcheck"])
|
|
|
|
];
|
|
|
|
|
|
|
|
options.vim.spellcheck = {
|
2024-04-27 12:51:22 +00:00
|
|
|
enable = mkEnableOption "Neovim's built-in spellchecking";
|
2024-04-20 15:09:11 +00:00
|
|
|
languages = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
default = ["en"];
|
|
|
|
example = literalExpression ''["en" "de"]'';
|
2024-04-20 16:00:20 +00:00
|
|
|
description = ''
|
2024-04-20 15:09:11 +00:00
|
|
|
A list of languages that should be used for spellchecking.
|
|
|
|
|
2024-10-21 14:20:02 +00:00
|
|
|
To add your own language files, you may place your `spell` directory in either
|
|
|
|
{file}`$XDG_CONFIG_HOME/nvf` or in a path that is included in the
|
|
|
|
[additionalRuntimePaths](#opt-vim.additionalRuntimePaths) list provided by nvf.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraSpellWords = mkOption {
|
|
|
|
type = attrsOf (listOf str);
|
|
|
|
default = {};
|
|
|
|
example = literalExpression ''{"en.utf-8" = ["nvf" "word_you_want_to_add"];}'';
|
|
|
|
description = ''
|
|
|
|
Additional words to be used for spellchecking. The names of each key will be
|
|
|
|
used as the language code for the spell file. For example
|
|
|
|
|
|
|
|
```nix
|
|
|
|
"en.utf-8" = [ ... ];
|
|
|
|
```
|
|
|
|
|
|
|
|
will result in `en.utf-8.add.spl` being added to Neovim's runtime in the
|
|
|
|
{file}`spell` directory.
|
|
|
|
|
|
|
|
::: {.warning}
|
|
|
|
The attribute keys must be in `"<name>.<encoding>"` format for Neovim to
|
|
|
|
compile your spellfiles without mangling the resulting file names. Please
|
|
|
|
make sure that you enter the correct value, as nvf does not do any kind of
|
|
|
|
internal checking. Please see {command}`:help mkspell` for more details.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```nix
|
|
|
|
# "en" is the name, and "utf-8" is the encoding. For most use cases, utf-8
|
|
|
|
# will be enough, however, you may change it to any encoding format Neovim
|
|
|
|
# accepts, e.g., utf-16.
|
|
|
|
"en.utf-8" = ["nvf" "word_you_want_to_add"];
|
|
|
|
=> $out/spell/en-utf-8.add.spl
|
|
|
|
```
|
|
|
|
:::
|
2024-04-20 15:09:11 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ignoredFiletypes = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
default = ["toggleterm"];
|
|
|
|
example = literalExpression ''["markdown" "gitcommit"]'';
|
|
|
|
description = ''
|
|
|
|
A list of filetypes for which spellchecking will be disabled.
|
|
|
|
|
2024-10-21 14:20:02 +00:00
|
|
|
::: {.tip}
|
|
|
|
You may use {command}`:echo &filetype` in Neovim to find out the
|
2024-04-20 15:09:11 +00:00
|
|
|
filetype for a specific buffer.
|
2024-10-21 14:20:02 +00:00
|
|
|
:::
|
2024-04-20 15:09:11 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-04-27 13:22:42 +00:00
|
|
|
/*
|
|
|
|
# FIXME: This needs to be revisited. It tries to install
|
|
|
|
# the spellfile to an user directory, but it cannot do so
|
|
|
|
# as we sanitize runtime paths.
|
2024-04-20 15:09:11 +00:00
|
|
|
programmingWordlist.enable = mkEnableOption ''
|
|
|
|
vim-dirtytalk, a wordlist for programmers containing
|
|
|
|
common programming terms.
|
|
|
|
|
|
|
|
Setting this value as `true` has the same effect
|
|
|
|
as setting {option}`vim.spellCheck.enable`
|
|
|
|
'';
|
2024-04-27 13:22:42 +00:00
|
|
|
*/
|
2024-04-20 15:09:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2024-10-21 14:20:02 +00:00
|
|
|
vim = {
|
|
|
|
additionalRuntimePaths = let
|
|
|
|
compileJoinedSpellfiles =
|
|
|
|
pkgs.runCommandLocal "nvf-compile-spellfiles" {
|
|
|
|
# Use the same version of Neovim as the user's configuration
|
|
|
|
nativeBuildInputs = [config.vim.package];
|
2024-10-28 17:05:01 +00:00
|
|
|
|
|
|
|
spellfilesJoined = pkgs.symlinkJoin {
|
|
|
|
name = "nvf-spellfiles-joined";
|
|
|
|
paths = mapAttrsToList (name: value: pkgs.writeTextDir "spell/${name}.add" (concatLines value)) cfg.extraSpellWords;
|
|
|
|
postBuild = "echo Spellfiles joined";
|
|
|
|
};
|
2024-10-21 14:20:02 +00:00
|
|
|
} ''
|
2024-10-28 17:05:01 +00:00
|
|
|
# Fail on unset variables and non-zero exit codes
|
|
|
|
# this might be the only way to trace when `nvim --headless`
|
|
|
|
# fails in batch mode
|
|
|
|
set -eu
|
2024-10-21 14:20:02 +00:00
|
|
|
|
2024-10-28 17:05:01 +00:00
|
|
|
mkdir -p "$out/spell"
|
|
|
|
for spellfile in "$spellfilesJoined"/spell/*.add; do
|
|
|
|
name="$(basename "$spellfile" ".add")"
|
|
|
|
echo "Compiling spellfile: $spellfile"
|
|
|
|
nvim --headless --clean \
|
|
|
|
--cmd "mkspell $out/spell/$name.add.spl $spellfile" -Es -n
|
2024-10-21 14:20:02 +00:00
|
|
|
done
|
2024-10-28 17:05:01 +00:00
|
|
|
|
2024-10-21 14:20:02 +00:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
mkIf (cfg.extraSpellWords != {}) [
|
|
|
|
# If .outPath is missing, additionalRuntimePaths receives the *function*
|
|
|
|
# instead of a path, causing errors.
|
|
|
|
compileJoinedSpellfiles.outPath
|
|
|
|
];
|
|
|
|
|
|
|
|
luaConfigRC.spellcheck = entryAfter ["basic"] ''
|
|
|
|
vim.opt.spell = true
|
|
|
|
vim.opt.spelllang = ${listToLuaTable cfg.languages}
|
|
|
|
|
|
|
|
-- Disable spellchecking for certain filetypes
|
|
|
|
-- as configured by `vim.spellcheck.ignoredFiletypes`
|
|
|
|
vim.api.nvim_create_autocmd({ "FileType" }, {
|
|
|
|
pattern = ${listToLuaTable cfg.ignoredFiletypes},
|
|
|
|
callback = function()
|
|
|
|
vim.opt_local.spell = false
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
'';
|
|
|
|
};
|
2024-04-20 15:09:11 +00:00
|
|
|
};
|
|
|
|
}
|