Spell-checking with Hunspell and flyspell-correct

In order to simplify the portability of my Emacs setup, I devised a useful shell script to install everything my configuration needs. It is aptly named esetup.

Recently I abandoned aspell in favour of hunspell, so the script has been updated accordingly. However, hunspell needs some dictionaries to work with and they are not readily available as Debian packages.

Instead of downloading the dictionaries from LibreOffice Extensions every time I install Emacs on a new machine, they are provided in my .emacs.d repository. Therefore, I just need to copy the files over to /usr/share/hunspell.

A quick test with hunspell -D shows all is set up correctly.

$ hunspell -D
AVAILABLE DICTIONARIES (path is not mandatory for -d option):

Emacs Lisp takes care of the rest.

(setq ispell-program-name (executable-find "hunspell")
      ispell-dictionary "en_GB")

I write both in English and Italian, so the spell-checker must be able to switch dictionary on demand.

(bind-key "C-c I"
          (lambda ()
            (ispell-change-dictionary "it_IT")

(bind-key "C-c E"
          (lambda ()
            (ispell-change-dictionary "en_GB")

To make things nicer, flyspell-correct makes Flyspell propose the suggested corrections via the always reliable Ivy.

(use-package flyspell-correct-ivy
  :ensure t
  :after flyspell
  :bind (:map flyspell-mode-map
              ("C-c $" . flyspell-correct-word-generic)))