Skip to content

Emacs and Hunspell on MS Windows for Beginners

Emacs has built-in commands for spell checking, but it does not have a abuilt-in spellchecker! 🙂 As the fine manual says: These commands only work if the spelling checker program Aspell, Ispell or Hunspell is installed. These programs are not part of Emacs.

I installed spellchecker yesterday and run into some problems. While looking for help, I found quite a lot of outdated information on the web, so I decided to write a simple guide on how to install it for Emacs under MS Windows. Emacs version I am using is 24.4, but it should work for 24.3 as well I believe.

To make it short, whereever you see ispell or aspell in documentation or any other article, tutorial and so on, think of it as Hunspell. Hunspell is what you want (for the most part).

You can get precompiled version from excellent ezwinports from Source Forge.

Currently I don’t recomment to get it from original source code due to some bugs in original source which are sorted out by fine people from ezwinports (thanks Eli!).

Once you have executable file, put it somewhere, either in your path, or create a folder and add that folder to your PATH environment variable. Alternatively you might wish to setenv from within Emacs, but if you would like to use Hunspell with some other applications or from command line it is easiest to have it in PATH.

Next download dictionaries. It is possible to have several installed and to switch between languages as desired. You probably already have a Hunspell dictionary on your computer if you are using Chrome or Firefox. However get for yourself language(s) of choice from OpenOffice repositories.

Once you have downloaded files, unzip them into a shared folder of hunspell. You really need just .dic and .aff file, but hyphenation file might be of use too. In root folder where you have unzipped hunspell, there will be several subdirectories. In one named shared you will find another one named hunspell. While you can really keep dictionaries in any folder on your computer (or server) you wish, I really recommend shared folder of hunspell, just for simplicity of setup. Mine looks like this:

Now if you are using Hunspell from ezwinport, and have installed dictionaries in this folder, you are done with installation of checker and dictionaries. If you are not using those binaries, or keeping dictionaries in some other folder, you might have to add DICPATH to your environment variables and set its valute to folder with dictionaries.

For the second part you will need to configure Emacs to use your freshly installed Hunspell. We need to tell it what dictionaries we would like to use. Again, if you use more than one, add each langauge to this list:

(after 'ispell
  (add-to-list 'ispell-dictionary-alist '(("svenska"
                                           ("-d" "sv_SE")
                                            ("-d" "en_US")

  (setq-default ispell-program-name "hunspell")
  (setq ispell-local-dictionary-alist ispell-dictionary-alist)
  (setq ispell-hunspell-dictionary-alist ispell-dictionary-alist))

I am wrapping that code in eval-after-load just so ispell is not loaded until needed. For this purpose I am using “after” macro from:

(defmacro after (mode &rest body)
 "`eval-after-load' MODE evaluate BODY."
 (declare (indent defun))
 `(eval-after-load ,mode
 '(progn ,@body)))

I also have ispell mode associated with text mode only by default:

(dolist (hook '(text-mode-hook))
  (add-hook hook (lambda () (flyspell-mode 1))))


That is it, it should make it work, and you should be able to spell check your buffers.


Pictures are cool, so here is one wrong spelled word highlighted with english language in my christmass-tree Emacs:

And one suggestion from spellcheck with Swedish dictionary:

{ 1 } Comments