z (06/07/82)
EMACS now has a complete facility for checking and correcting spelling. If you give the command M-X Spell, EMACS will check the spelling of the words in the current buffer from the current cursor position to the end of the buffer. If you give M-X Spell an argument, all succeeding buffers will be checked as well. When you first start up M-X Spell, there is a slight delay as EMACS internally runs the Unix spell program on your buffer(s). When this is finished, EMACS moves the cursor to the first misspelled word it finds and asks you if you want to correct it. If you answer "no", EMACS asks you if it should enquire about further occurrences of the word. If you answer "no" to this question as well, EMACS assumes that the word is correctly spelled and doesn't ask you about it any more. Otherwise, EMACS will go through the same set of questions again the next time it encounters the word in your text. If you tell EMACS that you want to correct the word, it will first ask you if you want a hint about the correct spelling. If you answer "yes", a list of possibly correct words will be displayed at the top of the screen. The words displayed all have a difference of one from your word. That is to say, the words are the same as your word except that they have one letter added, one letter deleted, one letter changed, or two letters transposed. Most misspelled words contain just a single mistake, so the correct spelling for your word will probably be among the displayed words. If you would like to see words with a difference from your word greater than one, then you should set the variable Spell Tolerance to the difference you want before you run M-X Spell. The list of alternative words is formed by determining various possible correct root words for your word, and then adding to this word whatever prefixes and suffixes your word has. The new word is then compared against the spell program's stop list, which contains misspelled words which would otherwise pass through the spell program. If the new word is in the stop list, it is not displayed. As an example of this process, if you typed "stecked" when you meant to type "stacked", the word "stacked" will be among the alternatives listed. Also among these alternatives will be the nonexistent word "stucked", which is formed from the legitimate word "stuck" plus the suffix "ed". However, the nonexistent word "sticked" will not be found because it was filtered out during the pass through the stop list. Although this example shows that not all the alternatives listed are guaranteed to be legitimate words, the cases where they aren't are generally obvious and usually do not cause confusion. Note that nonexistent words which show up among the alternatives also pass through the Unix spell program without being flagged. If one of these words is a word which you think should have been caught by the spell program, ask your system's dictionary administrator add it to the stop list. In the previous example, you might want to ask your dictionary administrator to add "stucked" to the stop list. Once the alternative words are displayed, you have three options: You can type in the number of the alternative which you believe to be the correct spelling, followed by a carriage return; you can type in the correct spelling yourself; or you can type a carriage return and correct the word on the screen. If you choose the last option, you should type C-M-Z (which is usually typed C-Z C-Z) when you're done. EMACS then puts you in a recursive editing mode, which is evident from the square brackets around the mode line. Although when you are correcting the word on the screen you are able to move all over the file and execute any EMACS command, it is recommended that you do nothing that will insert or delete lines anywhere in the file, or which will insert or delete characters on the current line in front of the word being corrected. Otherwise, EMACS may become temporarily confused about where the corrected word is. Any actions taken in order to correct the word will not cause any problems, though. If you answer "no" when EMACS asks you if you want a hint about the correct spelling, or if you answer "yes" and EMACS can't figure out any alternative words, you will be asked to correct the word yourself on the screen. This is exactly equivalent to the third option described in the preceding paragraph. Once you have corrected the word one way or another, EMACS will display both the old word and the corrected word, and ask if should make this correction to the old word whenever it occurs in the rest of the file. If you answer "yes" to this question, further replacements will be done silently. Otherwise, EMACS will ask you about the word as if it had never seen it before. Whenever you are being asked a question, you can always type C-G, and M-X Spell will be aborted at that point. The one exception to this is when you are correcting a word on the screen in recursive editing mode. Here you can either type C-M-Z to leave the recursive editing mode and then type C-G to the next question, or you just type C-] (Abort Recursive Edit) to exit from both the recursive edit and from M-X Spell. M-X Spell has some features which make it easy to maintain a private spelling list (for example, of proper names) and also to keep your site's master dictionary up to date. If a buffer called .spell exists when M-X Spell is executed and contains one word per line, then EMACS assumes that these words are correctly spelled and will not flag them when it encounters them in your text. Furthermore, whenever you tell M-X Spell that a word that it has flagged is correct and that it shouldn't ask you about this word any more, this word is automatically put at the end of the .spell buffer, which is created if it didn't already exist. A mark is set in .spell at the beginning of the list of words entered in this way, making it easy to set them apart from any existing words. Some or all of the .spell buffer may then be saved for future use with M-X Spell, or the word list may be easily entered into your site's dictionary. When you are checking a large buffer or many buffers, the initial phase of M-X Spell may take a long time. There are two ways to get around this. The first is to use the command M-X Background Spell. This command will run the Unix spell program in the background, and in the mean time you can continue to edit your file. Like M-X Spell, M-X Background Spell will check the current buffer from your cursor position onward, unless it is given an argument, in which case it will check all succeeding buffers as well. Once M-X Background Spell is done, it will display a prompt in the echo area to that effect and beep once. At this point, you can move the cursor to where you started M-X Background Spell and type M-X Spell. EMACS will then ask you if you want to use the spelling list generated by M-X Background Spell; if you answer "yes", it will immediately move to the first misspelled word and proceed as described above. The second shortcut is to run the Unix spell program yourself on your files, and direct the output to a file. For example, if you directed the output of the spell program to a file called #t, then you could say M-X Spell$#t, and response would be immediate. The word guessing feature of M-X Spell is also available on a standalone basis. If you are entering text and are not sure of the spelling of a word, then you can type M-X Lookup$word, where "word" is your word, and a list of possible correct spellings for your word will be given. If your word is among them, then you know that is probably correct. As with M-X Spell, the value of the Spell Tolerance variable is used for the allowed difference. If you give M-X Lookup a numeric argument, then that argument is used as the difference instead.