Emacs, hunspell & multiple languages
While writing yesterdays post I realized that some spellchecking might be good. And, as always, there are some quirks to fix in my setup.
I mostly write in English when on my laptop & using Emacs, due to $REASONS. But every now and then (and often enough for me to consider fixing it) I write in my first language, Swedish. So having a setup that would allow me to switch between them would be great.
The snippet below expects two (or more!) languages in the local
variable languages
. I’ve saved lots of CPU time by not typing out
that language list everywhere. ^_^
(with-eval-after-load "ispell"
(let ((languages "en_US,sv_SE"))
;; Change this path to whatever is relevant for you!
(setenv "DICPATH" (expand-file-name "~/.nix-profile/share/hunspell/"))
(setenv "LANG" (car (split-string languages ",")))
(setq ispell-program-name "hunspell"
ispell-dictionary languages
ispell-personal-dictionary "~/.hunspell_personal")
(ispell-set-spellchecker-params)
(ispell-hunspell-add-multi-dic languages)
(unless (file-exists-p ispell-personal-dictionary)
(write-region "" nil ispell-personal-dictionary nil 0))))
The snippet is shamelessly stol…adapted from this article. I
can now switch dictionaries with M-x ispell-change-dictionary
, and I
typically use it together with M-x flyspell-mode
for writing.