From 81eda5b340a22c1b5ae8848ffa43ef1421e21b22 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Wed, 30 Oct 2024 15:27:30 +0300 Subject: [PATCH] neovim/spellcheck: add autogroup to spellcheck fts autocmd; fix vim-dirtytalk --- modules/neovim/init/spellcheck.nix | 19 +++++++++------ .../spellcheck/vim-dirtytalk/config.nix | 24 +++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/modules/neovim/init/spellcheck.nix b/modules/neovim/init/spellcheck.nix index 16af3ee..5d6f5be 100644 --- a/modules/neovim/init/spellcheck.nix +++ b/modules/neovim/init/spellcheck.nix @@ -64,6 +64,11 @@ in { => $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 '' 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 +139,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 diff --git a/modules/plugins/spellcheck/vim-dirtytalk/config.nix b/modules/plugins/spellcheck/vim-dirtytalk/config.nix index 08426d1..51ccfb8 100644 --- a/modules/plugins/spellcheck/vim-dirtytalk/config.nix +++ b/modules/plugins/spellcheck/vim-dirtytalk/config.nix @@ -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 - pluginRC.vim-dirtytalk = entryAfter ["basic"] '' - -- append programming to spelllang - vim.opt.spelllang:append("programming") + 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 ["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 ''; }; };