Here in Switzerland, there are four spoken and written languages: Swiss German, French, Italian and Romansh. Also, we converse a lot in German and English. Hence, it's a regular occurrence to have one file with multiple languages in them. Especially for these situations it's important to have proper spell checking. Fortunately, Emacs has us covered!

Emacs has built-in functionality for checking and correcting spelling called ispell.el. On top of that, there's a built-in minor mode for on-the-fly spell checking called flyspell-mode.

Flyspell can use multiple back-ends (for example ispell, aspell or hunspell).

Hunspell is a free spell checker and used by LibreOffice, Firefox and Chromium. It allows to set multiple dictionaries - even different dictionaries per language (aspell, for example also allows multiple dictionaries, but only for the same language).

To use hunspell, install it first:

apt install hunspell \
            hunspell-de-de \
            hunspell-en-gb \
            hunspell-en-us \

Then, configure it in your Emacs config with:

(with-eval-after-load "ispell"
  ;; Configure `LANG`, otherwise ispell.el cannot find a 'default
  ;; dictionary' even though multiple dictionaries will be configured
  ;; in next line.
  (setenv "LANG" "en_US")
  (setq ispell-program-name "hunspell")
  ;; Configure German, Swiss German, and two variants of English.
  (setq ispell-dictionary "de_DE,de_CH,en_GB,en_US")
  ;; ispell-set-spellchecker-params has to be called
  ;; before ispell-hunspell-add-multi-dic will work
  (ispell-hunspell-add-multi-dic "de_DE,de_CH,en_GB,en_US")
  ;; For saving words to the personal dictionary, don't infer it from
  ;; the locale, otherwise it would save to ~/.hunspell_de_DE.
  (setq ispell-personal-dictionary "~/.hunspell_personal"))

;; The personal dictionary file has to exist, otherwise hunspell will
;; silently not use it.
(unless (file-exists-p ispell-personal-dictionary)
  (write-region "" nil ispell-personal-dictionary nil 0))

That's it. Now you've got the full power of ispell and Flyspell set up - even with multiple dictionaries! And you can benefit from that in any major mode. So, whether you're writing Emails, doing project management, writing code, you can be safe that you're protected from typos.

Here's the gist to get going:

With M-x flyspell-mode, you'll enable Flyspell mode which highlights all misspelled words. With M-$, you'll check and correct spelling of the word at point. With M-x ispell-buffer, you'll check and correct spelling in the buffer. See the docs for all available functions and keyboard shortcuts.

If you'd like to see this configuration in action, here is it on Github. All of the config is written and documented in literate programming style.

If you're into Emacs, chances are that you're also into Org mode. We're building a free and open source implementation of Org mode without the dependency of Emacs - built for mobile and desktop browsers:

Enjoy and happy text processing!

If you liked this post and want to say 'thanks', please head over to our free/libre and open source software page - and if you like one of them, give it a star on Github or Gitlab.

Update [2020-08-24 Mon]: Use write-region instead of calling out to touch thanks to u/clemera.