Emacs’s built-in ispell package handles spell-checking and correction, while flyspell provides on-the-fly checking and highlighting of misspellings.
Emacs supports three spelling checkers by default: Hunspell, which is now widely used by popular free software such as LibreOffice, OpenOffice, Firefox and Thunderbird; GNU Aspell, which pays particular attention to quality of suggestions, and the original Ispell. If no spell checker is manually configured, Emacs will choose aspell over hunspell over ispell.
Hunspell is a widely-used free software spelling checker, and supports a wider range of languages than others. It has many dictionaries.
ispell.el in Emacs 24.4 has built-in support for detecting Hunspell’s default dictionary, so it should now work out of the box with no Emacs configuration.
Using the ezwinports version of Hunspell should work out of the box, but sometimes it results in the error:
ispell-phaf: No matching entry for nil.
This is due to Hunspell’s auto-configuration failing, usually because Hunspell, when run within emacs, can’t find a default dictionary. There are two potential work-arounds for this. you can set the DICTIONARY
environment variable to your dictionary name (eg, en_GB) or you can create a dictionary file that matches Emacs’s LANG
variable. In my case this was “ENG”, but you can check it with:
(getenv "LANG")
Then just copy (or softlink) your preferred dictionary to that name, eg.:
en_GB.dic -> ENG.dic en_GB.aff -> ENG.aff
Emacs on OS X can run into the same problem as on Windows. I got installed Hunspell from Homebrew, and while it worked in the terminal, and if I ran Emacs from the terminal, it didn’t work if I ran emacs from spotlight. Setting the environment variable DICTIONARY
did the trick. The easiest way I found was to set it within my .emacs:
(setenv "DICTIONARY" "en_GB")
However it can also be set using launchctl.
The ELPA package rw-hunspell provides some useful extensions to ispell.el for Hunspell.
On my linux setup I use the following:
(require 'rw-language-and-country-codes) (require 'rw-ispell) (require 'rw-hunspell) (setq ispell-dictionary "da_DK_hunspell") ;; The following is set via custom (custom-set-variables '(rw-hunspell-default-dictionary "da_DK_hunspell") '(rw-hunspell-dicpath-list (quote ("/usr/share/hunspell"))) '(rw-hunspell-make-dictionary-menu t) '(rw-hunspell-use-rw-ispell t) )
The code below comes from http://unix.stackexchange.com/questions/86554/make-hunspell-work-with-emacs-and-german-language, and works for me.
(add-to-list 'ispell-local-dictionary-alist '("deutsch-hunspell" "[[:alpha:]]" "[^[:alpha:]]" "[']" t ("-d" "de_DE"); Dictionary file name nil iso-8859-1)) (add-to-list 'ispell-local-dictionary-alist '("english-hunspell" "[[:alpha:]]" "[^[:alpha:]]" "[']" t ("-d" "en_US") nil iso-8859-1)) (setq ispell-program-name "hunspell" ; Use hunspell to correct mistakes ispell-dictionary "deutsch-hunspell") ; Default dictionary to use
Aspell was originally designed as a replacement for Ispell; its primary advantage today is the quality of its suggested replacements. This is particularly useful when used with flyspell-auto-correct-previous-word, where you can iterate through suggested spellings – it’s much more useful when the correct spelling is near the head of the list.
Aspell is a lot slower than Ispell; on modern machines, this probably doesn’t matter, but if you find editing is sluggish with flyspell-mode using Aspell, you can speed it up at the cost of reducing the quality of its suggestions with:
(setq ispell-extra-args '("--sug-mode=fast"))
Ispell, short for “international spell”, is a successor of the original “spell” spelling program. The main reason to use it is if it has a better dictionary (or any dictionary) for the language you want to check.
You can get the binary and lots of dictionaries from the home page; here are direct links to a german dictionary [1] and a french dictionary [2]. The files contain installation instructions.
The list of installed dictionaries can be obtained by typing
M-x ispell-change-dictionary RET SPC
or by typing
M-: (ispell-valid-dictionary-list) RET
Or by browsing the menu Tools > Spell-checking > Change Dictionary
and typing SPC in minibuffer when asked.
You can specify which dictionary to use at startup by putting in your InitFile
(setq ispell-dictionary "german")
If you want to use the english dictionary in a particular buffer instead, put the following on the first line of the buffer
-*- ispell-dictionary: "english" -*-
Here are some extensions to ispell.el
:
=for stopwords
per-file words listHere is some code for your ~/.emacs that makes a new dictionary available to ‘ispell-change-dictionary’
. This dictionary is a variation of the German dictionary and is called “swiss”. The appropriate entry to the Tools / Spell Checking menu is added as well.
(require 'ispell) (add-to-list 'ispell-dictionary-alist '("swiss" "[a-zA-Z\304\326\334\344\366\337\374]" "[^a-zA-Z\304\326\334\344\366\337\374]" "[']" t ("-C" "-d" "swiss") "~latin1" iso-8859-1)) (defun my-ispell-swiss-dictionary () "Switch to the Swiss dictionary." (interactive) (ispell-change-dictionary "swiss")) (require 'easymenu) (easy-menu-add-item nil '("tools" "spell") ["Select Swiss Dict" my-ispell-swiss-dictionary t])
ispell must be required before adding to the Spell Checking menu, because loading it resets the menu.
If you ever need to produce the list of octal escapes yourself, use something like the following:
(insert (mapconcat (lambda (c) (format "\\%o" (multibyte-char-to-unibyte c))) "äöüÄÖÜ" ""))
Customize the variable ‘ispell-message-dictionary-alist’
if you want to switch dictionary according to some header when you use ‘ispell-message’
.
Other than that, take a look at WikiSpell. It has code that uses GuessBufferLanguage and chooses a dictionary accordingly.
Other modes for that are GuessLang and AutoLangMode.
A third way to use emacs is with SpeckMode which is an alternative to iSpell.
WcheckMode is a fast general-purpose on-the-fly (spell-)checker interface which can use external programs or Emacs Lisp functions as the text-checker engine. It works not only with Ispell, Enchant, Hunspell etc. but also many other command-line text-filtering programs and shell scripts. Wcheck mode is highly configurable.
(Enchant is a wrapper for ispell, aspell, hunspell, myspell, voikko, zemberek, etc. An advantage of using it is that it can be configured to use different spelling checkers according to the language, and that, since it is used by other programs, such as AbiWord and LyX, that configuration can be useful outside Emacs.)
(defun dired-do-ispell (&optional arg) (interactive "P") (dolist (file (dired-get-marked-files nil arg #'(lambda (f) (not (file-directory-p f))))) (save-window-excursion (with-current-buffer (find-file file) (ispell-buffer))) (message nil)))
If you use TypographicalPunctuationMarks you may find you get spelling errors for words like “isn’t”.
If you’re using hunspell, Emacs parses the dictionary’s .aff file to determine which letters are allowed in words automatically. The .aff file should have some entries similar to:
ICONV 1 ICONV ’ ' WORDCHARS 0123456789'’
The ICONV lines tell the spell checker that the curly and straight apostrophes are equivalent, and WORDCHARS is a list of the characters that are allowed in words, which both the spell checker and Emacs parse. WORDCHARS needs to contain both the curly and straight apostrophe.
You need to tell Emacs that the extra characters you use are allowed in words. Customize ispell-local-dictionary-alist, and add, for example:
(quote (("british" "[[:alpha:]]" "[^[:alpha:]]" "['’]" t ("-d" "en_GB") nil utf-8)))
Note the curly quote in the (short) list of non-letter characters allowed in words.