neovim/spellcheck: add autogroup to spellcheck fts autocmd; fix vim-dirtytalk

This commit is contained in:
raf 2024-10-30 15:27:30 +03:00
parent f429379e34
commit 81eda5b340
Signed by: NotAShelf
GPG key ID: AF26552424E53993
2 changed files with 29 additions and 14 deletions

View file

@ -64,6 +64,11 @@ in {
=> $out/spell/en-utf-8.add.spl => $out/spell/en-utf-8.add.spl
``` ```
::: :::
Note that while adding a new language, you will still need to add the name of
the language (e.g. "en") to the {option}`vim.spellcheck.languages` list by name
in order to enable spellchecking for the language. By default only `"en"` is in
the list.
''; '';
}; };
@ -81,18 +86,16 @@ in {
''; '';
}; };
/*
# 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.
programmingWordlist.enable = mkEnableOption '' programmingWordlist.enable = mkEnableOption ''
vim-dirtytalk, a wordlist for programmers containing vim-dirtytalk, a wordlist for programmers containing
common programming terms. common programming terms.
Setting this value as `true` has the same effect ::: {.note}
as setting {option}`vim.spellCheck.enable` Enabling this option will unconditionally set
{option}`vim.spellcheck.enable` to true as vim-dirtytalk
depends on spellchecking having been set up.
:::
''; '';
*/
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
@ -136,7 +139,9 @@ in {
-- Disable spellchecking for certain filetypes -- Disable spellchecking for certain filetypes
-- as configured by `vim.spellcheck.ignoredFiletypes` -- as configured by `vim.spellcheck.ignoredFiletypes`
vim.api.nvim_create_augroup("nvf_autocmds", {clear = false})
vim.api.nvim_create_autocmd({ "FileType" }, { vim.api.nvim_create_autocmd({ "FileType" }, {
group = "nvf_autocmds",
pattern = ${listToLuaTable cfg.ignoredFiletypes}, pattern = ${listToLuaTable cfg.ignoredFiletypes},
callback = function() callback = function()
vim.opt_local.spell = false vim.opt_local.spell = false

View file

@ -7,16 +7,26 @@
inherit (lib.nvim.dag) entryAfter; inherit (lib.nvim.dag) entryAfter;
cfg = config.vim.spellcheck; cfg = config.vim.spellcheck;
in { in {
config = mkIf (cfg.enable && cfg.programmingWordlist.enable) { config = mkIf cfg.programmingWordlist.enable {
vim = { vim = {
startPlugins = ["vim-dirtytalk"]; startPlugins = ["vim-dirtytalk"];
# vim-dirtytalk doesn't have any setup spellcheck.enable = true;
# but we would like to append programming to spelllang
# as soon as possible while the plugin is enabled # vim-dirtytalk doesn't have any setup but we would
pluginRC.vim-dirtytalk = entryAfter ["basic"] '' # like to append programming to spelllangs as soon as
-- append programming to spelllang # possible while the plugin is enabled and the state
vim.opt.spelllang:append("programming") # directory can be found.
pluginRC.vim-dirtytalk = entryAfter ["spellcheck"] ''
-- If Neovim can find (or access) the state directory
-- then append "programming" wordlist from vim-dirtytalk
-- to spelllang table. If path cannot be found, display
-- an error and avoid appending the programming words
if vim.fn.isdirectory(vim.fn.stdpath('state')) == 1 then
vim.opt.spelllang:append("programming")
else
vim.notify("State path does not exist: " .. state_path, vim.log.levels.ERROR)
end
''; '';
}; };
}; };