Update years in copyright notice; nfc.
[bpt/emacs.git] / man / fixit.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2002, 2003,
3 @c 2004, 2005 Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Fixit, Keyboard Macros, Search, Top
6 @chapter Commands for Fixing Typos
7 @cindex typos, fixing
8 @cindex mistakes, correcting
9
10 In this chapter we describe the commands that are especially useful for
11 the times when you catch a mistake in your text just after you have made
12 it, or change your mind while composing text on the fly.
13
14 The most fundamental command for correcting erroneous editing is the
15 undo command, @kbd{C-x u} or @kbd{C-_} or @kbd{C-/}. This command
16 undoes a single command (usually), a part of a command (in the case of
17 @code{query-replace}), or several consecutive self-inserting
18 characters. Consecutive repetitions of the undo command undo earlier
19 and earlier changes, back to the limit of the undo information
20 available. @xref{Undo}, for more information.
21
22 @menu
23 * Kill Errors:: Commands to kill a batch of recently entered text.
24 * Transpose:: Exchanging two characters, words, lines, lists...
25 * Fixing Case:: Correcting case of last word entered.
26 * Spelling:: Apply spelling checker to a word, or a whole file.
27 @end menu
28
29 @node Kill Errors
30 @section Killing Your Mistakes
31
32 @table @kbd
33 @item @key{DEL}
34 Delete last character (@code{delete-backward-char}).
35 @item M-@key{DEL}
36 Kill last word (@code{backward-kill-word}).
37 @item C-x @key{DEL}
38 Kill to beginning of sentence (@code{backward-kill-sentence}).
39 @end table
40
41 The @key{DEL} character (@code{delete-backward-char}) is the most
42 important correction command. It deletes the character before point.
43 When @key{DEL} follows a self-inserting character command, you can think
44 of it as canceling that command. However, avoid the mistake of thinking
45 of @key{DEL} as a general way to cancel a command!
46
47 When your mistake is longer than a couple of characters, it might be
48 more convenient to use @kbd{M-@key{DEL}} or @kbd{C-x @key{DEL}}.
49 @kbd{M-@key{DEL}} kills back to the start of the last word, and @kbd{C-x
50 @key{DEL}} kills back to the start of the last sentence. @kbd{C-x
51 @key{DEL}} is particularly useful when you change your mind about the
52 phrasing of the text you are writing. @kbd{M-@key{DEL}} and @kbd{C-x
53 @key{DEL}} save the killed text for @kbd{C-y} and @kbd{M-y} to
54 retrieve. @xref{Yanking}.@refill
55
56 @kbd{M-@key{DEL}} is often useful even when you have typed only a few
57 characters wrong, if you know you are confused in your typing and aren't
58 sure exactly what you typed. At such a time, you cannot correct with
59 @key{DEL} except by looking at the screen to see what you did. Often it
60 requires less thought to kill the whole word and start again.
61
62 @node Transpose
63 @section Transposing Text
64
65 @table @kbd
66 @item C-t
67 Transpose two characters (@code{transpose-chars}).
68 @item M-t
69 Transpose two words (@code{transpose-words}).
70 @item C-M-t
71 Transpose two balanced expressions (@code{transpose-sexps}).
72 @item C-x C-t
73 Transpose two lines (@code{transpose-lines}).
74 @end table
75
76 @kindex C-t
77 @findex transpose-chars
78 The common error of transposing two characters can be fixed, when they
79 are adjacent, with the @kbd{C-t} command (@code{transpose-chars}). Normally,
80 @kbd{C-t} transposes the two characters on either side of point. When
81 given at the end of a line, rather than transposing the last character of
82 the line with the newline, which would be useless, @kbd{C-t} transposes the
83 last two characters on the line. So, if you catch your transposition error
84 right away, you can fix it with just a @kbd{C-t}. If you don't catch it so
85 fast, you must move the cursor back between the two transposed
86 characters before you type @kbd{C-t}. If you transposed a space with
87 the last character of the word before it, the word motion commands are
88 a good way of getting there. Otherwise, a reverse search (@kbd{C-r})
89 is often the best way. @xref{Search}.
90
91 @kindex C-x C-t
92 @findex transpose-lines
93 @kindex M-t
94 @findex transpose-words
95 @c Don't index C-M-t and transpose-sexps here, they are indexed in
96 @c programs.texi, in the "List Commands" node.
97 @c @kindex C-M-t
98 @c @findex transpose-sexps
99 @kbd{M-t} transposes the word before point with the word after point
100 (@code{transpose-words}). It moves point forward over a word,
101 dragging the word preceding or containing point forward as well. The
102 punctuation characters between the words do not move. For example,
103 @w{@samp{FOO, BAR}} transposes into @w{@samp{BAR, FOO}} rather than
104 @samp{@w{BAR FOO,}}.
105
106 @kbd{C-M-t} (@code{transpose-sexps}) is a similar command for
107 transposing two expressions (@pxref{Expressions}), and @kbd{C-x C-t}
108 (@code{transpose-lines}) exchanges lines. They work like @kbd{M-t}
109 except as regards what units of text they transpose.
110
111 A numeric argument to a transpose command serves as a repeat count: it
112 tells the transpose command to move the character (word, expression, line)
113 before or containing point across several other characters (words,
114 expressions, lines). For example, @kbd{C-u 3 C-t} moves the character before
115 point forward across three other characters. It would change
116 @samp{f@point{}oobar} into @samp{oobf@point{}ar}. This is equivalent to
117 repeating @kbd{C-t} three times. @kbd{C-u - 4 M-t} moves the word
118 before point backward across four words. @kbd{C-u - C-M-t} would cancel
119 the effect of plain @kbd{C-M-t}.@refill
120
121 A numeric argument of zero is assigned a special meaning (because
122 otherwise a command with a repeat count of zero would do nothing): to
123 transpose the character (word, expression, line) ending after point
124 with the one ending after the mark.
125
126 @node Fixing Case
127 @section Case Conversion
128
129 @table @kbd
130 @item M-- M-l
131 Convert last word to lower case. Note @kbd{Meta--} is Meta-minus.
132 @item M-- M-u
133 Convert last word to all upper case.
134 @item M-- M-c
135 Convert last word to lower case with capital initial.
136 @end table
137
138 @kindex M-@t{-} M-l
139 @kindex M-@t{-} M-u
140 @kindex M-@t{-} M-c
141 A very common error is to type words in the wrong case. Because of this,
142 the word case-conversion commands @kbd{M-l}, @kbd{M-u} and @kbd{M-c} have a
143 special feature when used with a negative argument: they do not move the
144 cursor. As soon as you see you have mistyped the last word, you can simply
145 case-convert it and go on typing. @xref{Case}.@refill
146
147 @node Spelling
148 @section Checking and Correcting Spelling
149 @cindex spelling, checking and correcting
150 @cindex checking spelling
151 @cindex correcting spelling
152
153 This section describes the commands to check the spelling of a single
154 word or of a portion of a buffer. These commands work with the spelling
155 checker program Ispell, which is not part of Emacs.
156 @ifinfo
157 @xref{Top, Ispell, Overview ispell, ispell, The Ispell Manual}.
158 @end ifinfo
159
160 @table @kbd
161 @item M-x flyspell-mode
162 Enable Flyspell mode, which highlights all misspelled words.
163 @item M-x flyspell-prog-mode
164 Enable Flyspell mode for comments and strings only.
165 @item M-$
166 Check and correct spelling of the word at point (@code{ispell-word}).
167 @item M-@key{TAB}
168 @itemx @key{ESC} @key{TAB}
169 Complete the word before point based on the spelling dictionary
170 (@code{ispell-complete-word}).
171 @item M-x ispell
172 Spell-check the active region or the current buffer.
173 @item M-x ispell-buffer
174 Check and correct spelling of each word in the buffer.
175 @item M-x ispell-region
176 Check and correct spelling of each word in the region.
177 @item M-x ispell-message
178 Check and correct spelling of each word in a draft mail message,
179 excluding cited material.
180 @item M-x ispell-change-dictionary @key{RET} @var{dict} @key{RET}
181 Restart the Ispell process, using @var{dict} as the dictionary.
182 @item M-x ispell-kill-ispell
183 Kill the Ispell subprocess.
184 @end table
185
186 @cindex Flyspell mode
187 @findex flyspell-mode
188 Flyspell mode is a fully-automatic way to check spelling as you edit
189 in Emacs. It operates by checking words as you change or insert them.
190 When it finds a word that it does not recognize, it highlights that
191 word. This does not interfere with your editing, but when you see the
192 highlighted word, you can move to it and fix it. Type @kbd{M-x
193 flyspell-mode} to enable or disable this mode in the current buffer.
194
195 When Flyspell mode highlights a word as misspelled, you can click on
196 it with @kbd{Mouse-2} to display a menu of possible corrections and
197 actions. You can also correct the word by editing it manually in any
198 way you like.
199
200 @findex flyspell-prog-mode
201 Flyspell Prog mode works just like ordinary Flyspell mode, except that
202 it only checks words in comments and string constants. This feature
203 is useful for editing programs. Type @kbd{M-x flyspell-prog-mode} to
204 enable or disable this mode in the current buffer.
205
206 The other Emacs spell-checking features check or look up words when
207 you give an explicit command to do so.
208
209 @kindex M-$
210 @findex ispell-word
211 To check the spelling of the word around or before point, and
212 optionally correct it as well, use the command @kbd{M-$}
213 (@code{ispell-word}). If the word is not correct, the command offers
214 you various alternatives for what to do about it.
215
216 @findex ispell-buffer
217 @findex ispell-region
218 To check the entire current buffer, use @kbd{M-x ispell-buffer}. Use
219 @kbd{M-x ispell-region} to check just the current region. To check
220 spelling in an email message you are writing, use @kbd{M-x
221 ispell-message}; that command checks the whole buffer, except for
222 material that is indented or appears to be cited from other messages.
223
224 @findex ispell
225 @cindex spell-checking the active region
226 The @kbd{M-x ispell} command spell-checks the active region if the
227 Transient Mark mode is on (@pxref{Transient Mark}), otherwise it
228 spell-checks the current buffer.
229
230 Each time these commands encounter an incorrect word, they ask you
231 what to do. They display a list of alternatives, usually including
232 several ``near-misses''---words that are close to the word being
233 checked. Then you must type a single-character response. Here are
234 the valid responses:
235
236 @table @kbd
237 @item @key{SPC}
238 Skip this word---continue to consider it incorrect, but don't change it
239 here.
240
241 @item r @var{new} @key{RET}
242 Replace the word (just this time) with @var{new}. (The replacement
243 string will be rescanned for more spelling errors.)
244
245 @item R @var{new} @key{RET}
246 Replace the word with @var{new}, and do a @code{query-replace} so you
247 can replace it elsewhere in the buffer if you wish. (The replacements
248 will be rescanned for more spelling errors.)
249
250 @item @var{digit}
251 Replace the word (just this time) with one of the displayed
252 near-misses. Each near-miss is listed with a digit; type that digit to
253 select it.
254
255 @item a
256 Accept the incorrect word---treat it as correct, but only in this
257 editing session.
258
259 @item A
260 Accept the incorrect word---treat it as correct, but only in this
261 editing session and for this buffer.
262
263 @item i
264 Insert this word in your private dictionary file so that Ispell will
265 consider it correct from now on, even in future sessions.
266
267 @item u
268 Insert the lower-case version of this word in your private dic@-tion@-ary
269 file.
270
271 @item m
272 Like @kbd{i}, but you can also specify dictionary completion
273 information.
274
275 @item l @var{word} @key{RET}
276 Look in the dictionary for words that match @var{word}. These words
277 become the new list of ``near-misses''; you can select one of them as
278 the replacement by typing a digit. You can use @samp{*} in @var{word} as a
279 wildcard.
280
281 @item C-g
282 Quit interactive spell checking, leaving point at the word that was
283 being checked. You can restart checking again afterward with @kbd{C-u
284 M-$}.
285
286 @item X
287 Same as @kbd{C-g}.
288
289 @item x
290 Quit interactive spell checking and move point back to where it was
291 when you started spell checking.
292
293 @item q
294 Quit interactive spell checking and kill the Ispell subprocess.
295
296 @item C-l
297 Refresh the screen.
298
299 @item C-z
300 This key has its normal command meaning (suspend Emacs or iconify this
301 frame).
302
303 @item ?
304 Show the list of options.
305 @end table
306
307 @findex ispell-complete-word
308 The command @code{ispell-complete-word}, which is bound to the key
309 @kbd{M-@key{TAB}} in Text mode and related modes, shows a list of
310 completions based on spelling correction. Insert the beginning of a
311 word, and then type @kbd{M-@key{TAB}}; the command displays a
312 completion list window. (If your window manager intercepts
313 @kbd{M-@key{TAB}}, type @kbd{@key{ESC} @key{TAB}} or @kbd{C-M-i}.) To
314 choose one of the completions listed, click @kbd{Mouse-2} or
315 @kbd{Mouse-1} fast on it, or move the cursor there in the completions
316 window and type @key{RET}. @xref{Text Mode}.
317
318 @ignore
319 @findex reload-ispell
320 The first time you use any of the spell checking commands, it starts
321 an Ispell subprocess. The first thing the subprocess does is read your
322 private dictionary, which defaults to the file @file{~/ispell.words}.
323 Words that you ``insert'' with the @kbd{i} command are added to that
324 file, but not right away---only at the end of the interactive
325 replacement procedure. Use the @kbd{M-x reload-ispell} command to
326 reload your private dictionary if you edit the file outside of Ispell.
327 @end ignore
328
329 @cindex @code{ispell} program
330 @findex ispell-kill-ispell
331 Once started, the Ispell subprocess continues to run (waiting for
332 something to do), so that subsequent spell checking commands complete
333 more quickly. If you want to get rid of the Ispell process, use
334 @kbd{M-x ispell-kill-ispell}. This is not usually necessary, since the
335 process uses no time except when you do spelling correction.
336
337 @vindex ispell-dictionary
338 Ispell uses two dictionaries together for spell checking: the
339 standard dictionary and your private dictionary. The variable
340 @code{ispell-dictionary} specifies the file name to use for the
341 standard dictionary; a value of @code{nil} selects the default
342 dictionary. The command @kbd{M-x ispell-change-dictionary} sets this
343 variable and then restarts the Ispell subprocess, so that it will use
344 a different standard dictionary.
345
346 @vindex ispell-complete-word-dict
347 Ispell uses a separate dictionary for word completion. The variable
348 @code{ispell-complete-word-dict} specifies the file name of this
349 dictionary. The completion dictionary must be different because it
350 cannot use root and affix information. For some languages
351 there is a spell checking dictionary but no word completion
352 dictionary.
353
354 @ignore
355 arch-tag: 3359a443-96ed-448f-9f05-c8111ba8eac0
356 @end ignore