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 2e1779fbae
commit b836b39941
Signed by: NotAShelf
GPG key ID: AF26552424E53993
2 changed files with 23 additions and 13 deletions

View file

@ -81,18 +81,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 ''
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`
::: {.note}
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 {
@ -136,7 +134,9 @@ in {
-- Disable spellchecking for certain filetypes
-- as configured by `vim.spellcheck.ignoredFiletypes`
vim.api.nvim_create_augroup("nvf_autocmds", {clear = false})
vim.api.nvim_create_autocmd({ "FileType" }, {
group = "nvf_autocmds",
pattern = ${listToLuaTable cfg.ignoredFiletypes},
callback = function()
vim.opt_local.spell = false

View file

@ -7,16 +7,26 @@
inherit (lib.nvim.dag) entryAfter;
cfg = config.vim.spellcheck;
in {
config = mkIf (cfg.enable && cfg.programmingWordlist.enable) {
config = mkIf cfg.programmingWordlist.enable {
vim = {
startPlugins = ["vim-dirtytalk"];
# vim-dirtytalk doesn't have any setup
# but we would like to append programming to spelllang
# as soon as possible while the plugin is enabled
spellcheck.enable = true;
# vim-dirtytalk doesn't have any setup but we would
# like to append programming to spelllangs as soon as
# possible while the plugin is enabled and the state
# directory can be found.
pluginRC.vim-dirtytalk = entryAfter ["basic"] ''
-- append programming to spelllang
-- 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
'';
};
};