I have a few more loose ends to tidy up before switching to the static version of the blog. One of the important tasks was to make sure I had a spell checker available. Back in the dim and distant past I had set up
flyspell-mode with hunspell, but I wanted to check if there was something better available these days. Enter enchant, which acts as a front end to multiple, different spell checkers. I like that Emacs has included support for enchant since version 26, plus one of the backends enchant supports is AppleSpell. In other words, when running on macOS, flyspell can make use of the OS’s built in spell checker and dictionaries.
Instructions on how to actually set up enchant on macOS are a bit thin on the ground, so I decided that I’ll put together a quick write up.
Installation itself is simple if you are using
homebrew. And if you’re not, why not? A simple `brew install enchant` gets you there. Just be aware that the binary called `enchant-2`, not `enchant`. The actual setup is very easy. First, I ran `enchant-lsmod-2` to get a list of supported backends. The homebrew build of enchant installs aspell automatically, plus I already had hunspell installed. As a result, the output looked like this:
mac-pro:$ enchant-lsmod-2 aspell (Aspell Provider) AppleSpell (AppleSpell Provider)
Interestingly enough it didn’t list hunspell, even though I have it installed on this system. The next step was to create the configuration file for enchant. The man page has more info on how to customize it, I just stuck with a single default rule. I put the config file into ~/.config/enchant. As per the man page, it has to be named `enchant.ordering`. My very simple file looks like this:
Enchant will pick the first available spell checker out of the list, which is AppleSpell if you’re running on macOS. At this point, I had a working enchant setup, but still needed to set it up for use with
To do that, I updated my .emacs file to ensure it would check if enchant was available. I also wanted to make sure that I provided a few fallback options in the order of priority that I wanted. As a result I ended up with this piece of code:
(cond ((executable-find "enchant-2") (setq-default ispell-program-name "enchant-2")) ((executable-find "hunspell") (progn (setq-default ispell-program-name "hunspell") (setq ispell-really-hunspell t))) ((executable-find "aspell") (setq-default ispell-program-name "aspell")))
The code above checks for the presence of the three spell check backends I want to use, in descending order of priority. After re-evaluating my .emacs buffer, I checked that Emacs picked the right spell checker by executing `(describe-variable ‘ispell-program-name)`. This resulted in the following output:
ispell-program-name is a variable defined in ‘ispell.el’.
Its value is "enchant-2"
Original value was
You can customize this variable.
Program invoked by M-$ and M-x ispell-region commands.
Once I was reassured that enchant was working, I wrote this blog post. In Emacs, of course, with enchant handling the spell checking.
Note – the static site version of this post has better highlighting. One of the side effects of writing the post for the static blog and then pasting it into WordPress with fairly minimal editing.