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