ErgoEmacsEmacsLispBlogEmacsLispBuy Tutorial

20.4 Checking and Correcting Spelling

This section describes the commands to check the spelling of a single word or of a portion of a buffer. These commands only work if the spelling checker program Aspell, Ispell or Hunspell is installed. Aspell, Ispell or Hunspell are not part of Emacs, but one or the other is usually installed in GNU/Linux and other free operating systems. See Aspell.

M-$
Check and correct spelling of the active region or the word at point (ispell-word).
M-x ispell
Check and correct spelling in the active region or the entire buffer.
M-x ispell-buffer
Check and correct spelling in the buffer.
M-x ispell-region
Check and correct spelling in the region.
M-x ispell-message
Check and correct spelling in a draft mail message, excluding cited material.
M-x ispell-change-dictionary <RET> dict <RET>
Restart the Aspell/Ispell/Hunspell process, using dict as the dictionary.
M-x ispell-kill-ispell
Kill the Aspell/Ispell/Hunspell subprocess.
M-<TAB>
<ESC> <TAB>
Complete the word before point based on the spelling dictionary (ispell-complete-word).
M-x flyspell-mode
Enable Flyspell mode, which highlights all misspelled words.
M-x flyspell-prog-mode
Enable Flyspell mode for comments and strings only.

To check the spelling of the word around or before point, and optionally correct it as well, type M-$ (ispell-word). If a region is active, M-$ checks the spelling of all words within the region. See Mark. (When Transient Mark mode is off, M-$ always acts on the word around or before point, ignoring the region. See Persistent Mark.)

Similarly, the command M-x ispell performs spell-checking in the region if one is active, or in the entire buffer otherwise. The commands M-x ispell-buffer and M-x ispell-region explicitly perform spell-checking on the entire buffer or the region respectively. To check spelling in an email message you are writing, use M-x ispell-message; that command checks the whole buffer, except for material that is indented or appears to be cited from other messages. See Sending Mail.

When one of these commands encounters what appears to be an incorrect word, it asks you what to do. It usually displays a list of numbered “near-misses”—words that are close to the incorrect word. Then you must type a single-character response. Here are the valid responses:

digit
Replace the word, just this time, with one of the displayed near-misses. Each near-miss is listed with a digit; type that digit to select it.
<SPC>
Skip this word—continue to consider it incorrect, but don't change it here.
r new <RET>
Replace the word, just this time, with new. (The replacement string will be rescanned for more spelling errors.)
R new <RET>
Replace the word with new, and do a query-replace so you can replace it elsewhere in the buffer if you wish. (The replacements will be rescanned for more spelling errors.)
a
Accept the incorrect word—treat it as correct, but only in this editing session.
A
Accept the incorrect word—treat it as correct, but only in this editing session and for this buffer.
i
Insert this word in your private dictionary file so that Aspell or Ispell or Hunspell will consider it correct from now on, even in future sessions.
m
Like i, but you can also specify dictionary completion information.
u
Insert the lower-case version of this word in your private dictionary file.
l word <RET>
Look in the dictionary for words that match word. These words become the new list of “near-misses”; you can select one of them as the replacement by typing a digit. You can use ‘*’ in word as a wildcard.
C-g
X
Quit interactive spell checking, leaving point at the word that was being checked. You can restart checking again afterward with C-u M-$.
x
Quit interactive spell checking and move point back to where it was when you started spell checking.
q
Quit interactive spell checking and kill the Aspell/Ispell/Hunspell subprocess.
?
Show the list of options.

In Text mode and related modes, the command M-<TAB> (ispell-complete-word) shows a list of completions based on spelling correction. Insert the beginning of a word, and then type M-<TAB>; the command displays a completion list window. (If your window manager intercepts M-<TAB>, type <ESC> <TAB> or C-M-i.) To choose one of the completions listed, click Mouse-2 or Mouse-1 fast on it, or move the cursor there in the completions window and type <RET>. See Text Mode.

Once started, the Aspell or Ispell or Hunspell subprocess continues to run, waiting for something to do, so that subsequent spell checking commands complete more quickly. If you want to get rid of the process, use M-x ispell-kill-ispell. This is not usually necessary, since the process uses no time except when you do spelling correction.

Ispell, Aspell and Hunspell use two dictionaries together for spell checking: the standard dictionary and your private dictionary. The standard dictionary is specified by ispell-local-dictionary or, if nil, by ispell-dictionary. If both are nil the default dictionary is selected. The command M-x ispell-change-dictionary sets the standard dictionary for the buffer and then restarts the subprocess, so that it will use a different standard dictionary. Personal dictionary is specified by ispell-personal-dictionary. If nil, default value is used.

Set variable ispell-dictionary to select a specific default dictionary for all your documents. Set variable ispell-local-dictionary in the local variables section to select a specific dictionary for a given document.

A separate dictionary is used for word completion. The variable ispell-complete-word-dict specifies the file name of this dictionary. The completion dictionary must be different because it cannot use root and affix information. For some languages, there is a spell checking dictionary but no word completion dictionary.

Flyspell mode is a fully-automatic way to check spelling as you edit in Emacs. It operates by checking words as you change or insert them. When it finds a word that it does not recognize, it highlights that word. This does not interfere with your editing, but when you see the highlighted word, you can move to it and fix it. Type M-x flyspell-mode to enable or disable this mode in the current buffer. To enable flyspell-mode in all text mode buffers, add turn-on-flyspell to text-mode-hook.

When Flyspell mode highlights a word as misspelled, you can click on it with Mouse-2 to display a menu of possible corrections and actions. You can also correct the word by editing it manually in any way you like.

Flyspell Prog mode works just like ordinary Flyspell mode, except that it only checks words in comments and string constants. This feature is useful for editing programs. Type M-x flyspell-prog-mode to enable or disable this mode in the current buffer.

blog comments powered by Disqus