I first tackled spellchecking way back at the start of this blog, but I only configured the files and languages, not the dictionaries and environment. Three work laptops later, this has become a problem. First I'll install Hunspell on the MacBook:

% brew install hunspell
...
==> Caveats
Dictionary files (*.aff and *.dic) should be placed in
~/Library/Spelling/ or /Library/Spelling/.

Then I'll fetch the dictionaries and extract them where I want them to go, non-standard as that may be:

% mkdir ~/.hunspell

% file dict-en-20200501.oxt
dict-en-20200501.oxt: Zip archive data, at least v2.0 to extract

% unzip dict-en-20200501.oxt
Archive:  dict-en-20200501.oxt
  ...
  inflating: en_CA.aff
  inflating: en_CA.dic
  inflating: en_US.aff
  inflating: en_US.dic
  ...

Having to worry about different shells (Bash, Zsh, Eshell) using different startup files for setting environment variables annoyed me, so I decided I'm going to have a ~/.environment file that I make my shells all read from. While I could have used ~/.profile and then told Zsh to read from it, I'd rather a file no tool is going to get clever with and mangle.

% cat ~/.environment
# Required by Hunspell
export DICPATH="$HOME/.hunspell"

% cat ~/.profile
source ~/.environment

% cat ~/.zshenv
source ~/.environment

Deleting all but those four files, since those are the languages (dialects) in which I write, I make then need to test that they're active. First I ensure I have a fresh session and then:

% hunspell -D
SEARCH PATH:
.::/Users/mak/.hunspell:...

AVAILABLE DICTIONARIES (path is not mandatory for -d option):
/Users/mak/.hunspell/en_CA
/Users/mak/.hunspell/en_US

Next, I dogfood Hunspell by running it on its own README, and after ignoring the many false-positives I found an actual mistake:

2020-05-18-spellcheck-dictionaries.png

Hunspell was still screaming about not being able to find dictionaries, so I need to be pulling things out of shell environment variables properly. There's a package for exactly that:

(use-package exec-path-from-shell
  :pin melpa
  :config
  (add-to-list 'exec-path-from-shell-variables "DICPATH")
  (exec-path-from-shell-initialize))

And now I'm save from spelling mistakes once again.