Use the spelling checker
Ispell, an interactive UNIX spelling checker, is built into Emacs and is a
powerful and convenient way to check buffers for misspelled words. The various
ispell- functions are described in this section.
Use the ispell-word function (or its equivalent key
binding, M-$) to check the spelling of the word at
point.
That word baid doesn't look right. Move point to it and check the
spelling by typing M-$.
Emacs doesn't recognize this word either, so it's highlighted as a misspelling;
you're given a list of suggestions in a new window above the buffer window, as
in Figure 6. Each suggestion is prefaced with a character
you can type to replace the misspelling with that suggestion. (You can also type
C-g to cancel the replacement.)
Figure 6. Correct spelling in Emacs with Ispell
Find the word you want, bid, and press the key that corresponds to it. Ispell exits and the misspelled word is replaced with the one you chose.
You can also spell check the region with the
ispell-region function.
Try using the mouse to highlight the last two lines in the buffer by pressing
and holding B1 as you drag over them (as described in
the first tutorial in this series). Then type
M-x ispell-region to spell check this highlighted
region of text.
In the minibuffer, Ispell reports that spell checking is complete and that no misspellings have been found.
To check the spelling of the whole buffer, use the
ispell-buffer function.
Try running it: Type M-x
ispell-buffer.
As with all the Ispell commands, you have many options whenever you encounter a misspelling in a buffer check. They are described in Table 6.
Table 6. Ispell word-replacement commands
| Key | Description |
|---|---|
| character | Make the suggested replacement prefaced by (character). |
| Space | Accept this word as correct in this context. |
| i | Accept this word as correct and insert it into the personal dictionary file. |
| a | Accept this word as correct only for this Emacs session. |
| A | Accept this word as correct only for this buffer in this Emacs session. |
| r | Replace the word with a string you type (and that Ispell then rechecks). |
| R | Replace the word with a string you type (and that Ispell then rechecks)
and run a query-replace through the rest of the
buffer. |
| l | Replace the word with a given string and do a lookup of the new string in a given dictionary file. |
| u | Insert a lowercase version of the word into the personal dictionary file. |
| m | Replace the word with a given string, save it to the personal dictionary, and then recheck the word. |
| C-l | Recenter the screen on the current line. |
| C-r | Enter a recursive edit. |
| C-z | Suspend Emacs. (In X, this iconifies the Emacs client window.) |
| x | Exit the spell check and move point back to its original position. |
| X | Exit the spell check, leaving point where it is. |
| q | Immediately quit the spell check. |
| ? | Display a menu of options. |
Catch misspellings as they happen
Flyspell mode is a special minor mode that highlights misspellings as you type them. This is particularly useful when you're writing quick documents (such as e-mails) or first drafts that have to get into production quickly. When Emacs encounters a misspelling, it doesn't stop you -- you can keep on typing -- but the misspelled word is highlighted in the buffer.
Flyspell mode works by running Ispell in the background; after you turn on Flyspell mode, even the existing text in the buffer is checked and any misspellings are highlighted.
Try it:
-
Turn on Flyspell mode: Type
M-x flyspell-mode. -
Move down to the end of the first stanza and type the following two lines, with the intentional misspelling on the first line:
Little lamb, hwo made thee? Dost thou know who made thee?
Notice that Emacs didn't like Blake's antique Dost, even though you know it's right. Both it and the misspelled hwo are highlighted, as in Figure 7.
Figure 7. Use Emacs' Flyspell mode
To correct the highlighted words, use the mouse pointer to click the middle button on each of them; a menu appears with suggested words. For hwo, choose the correct who; for Dost, choose Accept (buffer) to accept the spelling as correct for this buffer.
A few more commands are bound in Flyspell mode in addition to the mouse control; a list is given in Table 7.
Table 7. Key bindings for Flyspell mode
| Binding | Description |
|---|---|
M-$
| Correct the last misspelled word using Ispell. |
M-x flyspell-auto-correct-word,
M-Tab
| Correct the last misspelled word automatically, with a suggestion found with Ispell. |
M-x
flyspell-auto-correct-previous-word
| Correct the previous misspelled word automatically, with a suggestion found with Ispell. |
M-x flyspell-correct-word,
B2
| Display a pop-up menu with word suggestions. |
Summary of Emacs spelling commands
Table 8 summarizes the various spelling functions you've just learned for Emacs, describing their meanings and giving the default key bindings, if any.
Table 8. Spelling commands for Emacs
| Binding | Command or function | Description |
|---|---|---|
M-$
|
ispell-word
| Call Ispell to check the spelling of the word at point. |
ispell-region
| Call Ispell to check the spelling of the region. | |
ispell-buffer
| Call Ispell to check the spelling of all the words from point to the end of the buffer. | |
flyspell-mode
| Call Ispell to check the spelling of all the words in buffer in the background as you type and highlight all misspellings. |




