Document the new VC directory mode.
[bpt/emacs.git] / doc / emacs / fixit.texi
CommitLineData
8cf51b2c
GM
1@c This is part of the Emacs manual.
2@c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2001, 2002,
3f548a7c 3@c 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
8cf51b2c
GM
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
11the times when you catch a mistake in your text just after you have made
12it, or change your mind while composing text on the fly.
13
14 The most fundamental command for correcting erroneous editing is the
15undo command, @kbd{C-x u} or @kbd{C-_} or @kbd{C-/}. This command
16undoes a single command (usually), a part of a command (in the case of
17@code{query-replace}), or several consecutive self-inserting
18characters. Consecutive repetitions of the undo command undo earlier
19and earlier changes, back to the limit of the undo information
20available. @xref{Undo}, for more information.
21
22@menu
23* Undo:: The Undo commands.
24* Kill Errors:: Commands to kill a batch of recently entered text.
25* Transpose:: Exchanging two characters, words, lines, lists...
26* Fixing Case:: Correcting case of last word entered.
27* Spelling:: Apply spelling checker to a word, or a whole file.
28@end menu
29
30@node Undo
31@section Undo
32@cindex undo
33@cindex changes, undoing
34
35 The @dfn{undo} commands undo recent changes in the buffer's text.
36Each buffer records changes individually, and the undo command always
37applies to the current buffer. You can undo all the changes in a
38buffer for as far as back these records go. Usually each editing
39command makes a separate entry in the undo records, but some commands
40such as @code{query-replace} divide their changes into multiple
41entries for flexibility in undoing. Meanwhile, self-inserting
42characters are usually grouped to make undoing less tedious.
43
44@table @kbd
45@item C-x u
46@itemx C-_
47@itemx C-/
48Undo one entry in the current buffer's undo records (@code{undo}).
49@end table
50
51@kindex C-x u
52@kindex C-_
53@kindex C-/
54@findex undo
a7cdd618
CY
55 To begin to undo, type the command @kbd{C-/} (or its aliases,
56@kbd{C-_} or @kbd{C-x u}). This undoes the most recent change in the
8cf51b2c
GM
57buffer, and moves point back to where it was before that change.
58
a7cdd618 59 Consecutive repetitions of @kbd{C-/} (or its aliases) undo earlier
8cf51b2c
GM
60and earlier changes in the current buffer, back to the limit of the
61current buffer's undo records. If all the recorded changes have
62already been undone, the undo command just signals an error.
63
64 If you notice that a buffer has been modified accidentally, the
a7cdd618 65easiest way to recover is to type @kbd{C-/} repeatedly until the stars
8cf51b2c
GM
66disappear from the front of the mode line. At this time, all the
67modifications you made have been canceled. Whenever an undo command
68makes the stars disappear from the mode line, it means that the buffer
69contents are the same as they were when the file was last read in or
70saved.
71
72 If you do not remember whether you changed the buffer deliberately,
a7cdd618 73type @kbd{C-/} once. When you see the last change you made undone, you
8cf51b2c
GM
74will see whether it was an intentional change. If it was an accident,
75leave it undone. If it was deliberate, redo the change as described
76below.
77
78@findex undo-only
79 Any command other than an undo command breaks the sequence of undo
80commands. Starting from that moment, the previous undo commands
81become ordinary changes that you can undo. Thus, to redo changes you
82have undone, type @kbd{C-f} or any other command that will harmlessly
83break the sequence of undoing, then type undo commands again. On the
84other hand, if you want to resume undoing, without redoing previous
85undo commands, use @kbd{M-x undo-only}. This is like @code{undo}, but
86will not redo changes you have just undone.
87
88@cindex selective undo
a7cdd618
CY
89@kindex C-u C-/
90 When there is an active region, any use of @code{undo} performs
91@dfn{selective undo}, undoing the most recent change within the
92region, instead of the entire buffer. However, when Transient Mark
93mode is off (@pxref{Persistent Mark}), @kbd{C-/} always operates on
94the entire buffer, ignoring the region. In this case, you can perform
95selective undo by supplying a prefix argument to the @code{undo}
96command: @kbd{C-u C-/} or @kbd{C-u C-x u}. To undo further changes in
97the same region, repeat the @code{undo} command (no prefix argument is
98needed).
8cf51b2c
GM
99
100 Some specialized buffers do not make undo records. Buffers
101whose names start with spaces never do; these buffers are used
102internally by Emacs and its extensions to hold text that users don't
103normally look at or edit.
104
105@vindex undo-limit
106@vindex undo-strong-limit
107@vindex undo-outer-limit
108@cindex undo limit
109 When the undo records for a buffer becomes too large, Emacs
110discards the oldest undo records from time to time (during garbage
111collection). You can specify how much undo records to keep by
112setting three variables: @code{undo-limit}, @code{undo-strong-limit},
113and @code{undo-outer-limit}. Their values are expressed in units of
114bytes of space.
115
116 The variable @code{undo-limit} sets a soft limit: Emacs keeps undo
117data for enough commands to reach this size, and perhaps exceed it,
118but does not keep data for any earlier commands beyond that. Its
119default value is 20000. The variable @code{undo-strong-limit} sets a
120stricter limit: a previous command (not the most recent one) which
121pushes the size past this amount is itself forgotten. The default
122value of @code{undo-strong-limit} is 30000.
123
124 Regardless of the values of those variables, the most recent change
125is never discarded unless it gets bigger than @code{undo-outer-limit}
126(normally 3,000,000). At that point, Emacs discards the undo data and
127warns you about it. This is the only situation in which you cannot
128undo the last command. If this happens, you can increase the value of
129@code{undo-outer-limit} to make it even less likely to happen in the
130future. But if you didn't expect the command to create such large
131undo data, then it is probably a bug and you should report it.
132@xref{Bugs,, Reporting Bugs}.
133
134 The reason the @code{undo} command has three key bindings, @kbd{C-x
135u}, @kbd{C-_} and @kbd{C-/}, is that it is worthy of a
136single-character key, but @kbd{C-x u} is more straightforward for
137beginners to remember and type. Meanwhile, @kbd{C--} on a text-only
138terminal is really @kbd{C-_}, which makes it a natural and easily
139typed binding for undoing.
140
141@node Kill Errors
142@section Killing Your Mistakes
143
144@table @kbd
145@item @key{DEL}
146Delete last character (@code{delete-backward-char}).
147@item M-@key{DEL}
148Kill last word (@code{backward-kill-word}).
149@item C-x @key{DEL}
150Kill to beginning of sentence (@code{backward-kill-sentence}).
151@end table
152
153 The @key{DEL} character (@code{delete-backward-char}) is the most
154important correction command. It deletes the character before point.
155When @key{DEL} follows a self-inserting character command, you can think
156of it as canceling that command. However, avoid the confusion of thinking
157of @key{DEL} as a general way to cancel a command!
158
159 When your mistake is longer than a couple of characters, it might be
160more convenient to use @kbd{M-@key{DEL}} or @kbd{C-x @key{DEL}}.
161@kbd{M-@key{DEL}} kills back to the start of the last word, and @kbd{C-x
162@key{DEL}} kills back to the start of the last sentence. @kbd{C-x
163@key{DEL}} is particularly useful when you change your mind about the
164phrasing of the text you are writing. @kbd{M-@key{DEL}} and @kbd{C-x
165@key{DEL}} save the killed text for @kbd{C-y} and @kbd{M-y} to
166retrieve. @xref{Yanking}.@refill
167
168 @kbd{M-@key{DEL}} is often useful even when you have typed only a few
169characters wrong, if you know you are confused in your typing and aren't
170sure exactly what you typed. At such a time, you cannot correct with
171@key{DEL} except by looking at the screen to see what you did. Often it
172requires less thought to kill the whole word and start again.
173
174@node Transpose
175@section Transposing Text
176
177@table @kbd
178@item C-t
179Transpose two characters (@code{transpose-chars}).
180@item M-t
181Transpose two words (@code{transpose-words}).
182@item C-M-t
183Transpose two balanced expressions (@code{transpose-sexps}).
184@item C-x C-t
185Transpose two lines (@code{transpose-lines}).
186@end table
187
188@kindex C-t
189@findex transpose-chars
190 The common error of transposing two characters can be fixed, when they
191are adjacent, with the @kbd{C-t} command (@code{transpose-chars}). Normally,
192@kbd{C-t} transposes the two characters on either side of point. When
193given at the end of a line, rather than transposing the last character of
194the line with the newline, which would be useless, @kbd{C-t} transposes the
195last two characters on the line. So, if you catch your transposition error
196right away, you can fix it with just a @kbd{C-t}. If you don't catch it so
197fast, you must move the cursor back between the two transposed
198characters before you type @kbd{C-t}. If you transposed a space with
199the last character of the word before it, the word motion commands are
200a good way of getting there. Otherwise, a reverse search (@kbd{C-r})
201is often the best way. @xref{Search}.
202
203@kindex C-x C-t
204@findex transpose-lines
205@kindex M-t
206@findex transpose-words
207@c Don't index C-M-t and transpose-sexps here, they are indexed in
208@c programs.texi, in the "List Commands" node.
209@c @kindex C-M-t
210@c @findex transpose-sexps
211 @kbd{M-t} transposes the word before point with the word after point
212(@code{transpose-words}). It moves point forward over a word,
213dragging the word preceding or containing point forward as well. The
214punctuation characters between the words do not move. For example,
215@w{@samp{FOO, BAR}} transposes into @w{@samp{BAR, FOO}} rather than
216@samp{@w{BAR FOO,}}.
217
218 @kbd{C-M-t} (@code{transpose-sexps}) is a similar command for
219transposing two expressions (@pxref{Expressions}), and @kbd{C-x C-t}
220(@code{transpose-lines}) exchanges lines. They work like @kbd{M-t}
221except as regards what units of text they transpose.
222
223 A numeric argument to a transpose command serves as a repeat count: it
224tells the transpose command to move the character (word, expression, line)
225before or containing point across several other characters (words,
226expressions, lines). For example, @kbd{C-u 3 C-t} moves the character before
227point forward across three other characters. It would change
228@samp{f@point{}oobar} into @samp{oobf@point{}ar}. This is equivalent to
229repeating @kbd{C-t} three times. @kbd{C-u - 4 M-t} moves the word
230before point backward across four words. @kbd{C-u - C-M-t} would cancel
231the effect of plain @kbd{C-M-t}.@refill
232
233 A numeric argument of zero is assigned a special meaning (because
234otherwise a command with a repeat count of zero would do nothing): to
235transpose the character (word, expression, line) ending after point
236with the one ending after the mark.
237
238@node Fixing Case
239@section Case Conversion
240
241@table @kbd
242@item M-- M-l
243Convert last word to lower case. Note @kbd{Meta--} is Meta-minus.
244@item M-- M-u
245Convert last word to all upper case.
246@item M-- M-c
247Convert last word to lower case with capital initial.
248@end table
249
250@kindex M-@t{-} M-l
251@kindex M-@t{-} M-u
252@kindex M-@t{-} M-c
253 A very common error is to type words in the wrong case. Because of this,
254the word case-conversion commands @kbd{M-l}, @kbd{M-u} and @kbd{M-c} have a
255special feature when used with a negative argument: they do not move the
256cursor. As soon as you see you have mistyped the last word, you can simply
257case-convert it and go on typing. @xref{Case}.@refill
258
259@node Spelling
260@section Checking and Correcting Spelling
261@cindex spelling, checking and correcting
262@cindex checking spelling
263@cindex correcting spelling
264
265 This section describes the commands to check the spelling of a single
266word or of a portion of a buffer. These commands work with the spelling
267checker programs Aspell and Ispell, which are not part of Emacs.
268@ifnottex
269@xref{Top, Aspell,, aspell, The Aspell Manual}.
270@end ifnottex
271
272@table @kbd
273@item M-x flyspell-mode
274Enable Flyspell mode, which highlights all misspelled words.
275@item M-x flyspell-prog-mode
276Enable Flyspell mode for comments and strings only.
277@item M-$
278Check and correct spelling of the word at point (@code{ispell-word}).
279@item M-@key{TAB}
280@itemx @key{ESC} @key{TAB}
281Complete the word before point based on the spelling dictionary
282(@code{ispell-complete-word}).
283@item M-x ispell
284Spell-check the active region or the current buffer.
285@item M-x ispell-buffer
286Check and correct spelling of each word in the buffer.
287@item M-x ispell-region
288Check and correct spelling of each word in the region.
289@item M-x ispell-message
290Check and correct spelling of each word in a draft mail message,
291excluding cited material.
292@item M-x ispell-change-dictionary @key{RET} @var{dict} @key{RET}
293Restart the Aspell or Ispell process, using @var{dict} as the dictionary.
294@item M-x ispell-kill-ispell
295Kill the Aspell or Ispell subprocess.
296@end table
297
298@cindex Flyspell mode
299@findex flyspell-mode
300 Flyspell mode is a fully-automatic way to check spelling as you edit
301in Emacs. It operates by checking words as you change or insert them.
302When it finds a word that it does not recognize, it highlights that
303word. This does not interfere with your editing, but when you see the
304highlighted word, you can move to it and fix it. Type @kbd{M-x
305flyspell-mode} to enable or disable this mode in the current buffer.
306
307 When Flyspell mode highlights a word as misspelled, you can click on
308it with @kbd{Mouse-2} to display a menu of possible corrections and
309actions. You can also correct the word by editing it manually in any
310way you like.
311
312@findex flyspell-prog-mode
313Flyspell Prog mode works just like ordinary Flyspell mode, except that
314it only checks words in comments and string constants. This feature
315is useful for editing programs. Type @kbd{M-x flyspell-prog-mode} to
316enable or disable this mode in the current buffer.
317
318 The other Emacs spell-checking features check or look up words when
319you give an explicit command to do so.
320
321@kindex M-$
322@findex ispell-word
323 To check the spelling of the word around or before point, and
324optionally correct it as well, use the command @kbd{M-$}
a7cdd618
CY
325(@code{ispell-word}). If the word is not correct, Emacs offers you
326various alternatives for what to do about it. If a region is active,
327@kbd{M-$} checks the spelling of all words within the region
328(@pxref{Mark}). (However, when Transient Mark mode is off, @kbd{M-$}
329always acts on the word around or before point, ignoring the region.
330@xref{Persistent Mark}.)
331
332@findex ispell
333@cindex spell-checking the active region
334 The @kbd{M-x ispell} command performs spell-checking on the entire
335buffer if no region is active, or on region if one is active. (When
336Transient Mark mode is off, it always acts on the entire buffer,
337ignoring the region.)
8cf51b2c
GM
338
339@findex ispell-buffer
340@findex ispell-region
a7cdd618
CY
341 The commands @kbd{M-x ispell-buffer} and @kbd{M-x ispell-region}
342explicitly perform spell-checking on the entire buffer or the region
343respectively.
344
345 To check spelling in an email message you are writing, use @kbd{M-x
8cf51b2c
GM
346ispell-message}; that command checks the whole buffer, except for
347material that is indented or appears to be cited from other messages.
348
8cf51b2c
GM
349 Each time these commands encounter an incorrect word, they ask you
350what to do. They display a list of alternatives, usually including
351several ``near-misses''---words that are close to the word being
352checked. Then you must type a single-character response. Here are
353the valid responses:
354
355@table @kbd
356@item @key{SPC}
357Skip this word---continue to consider it incorrect, but don't change it
358here.
359
360@item r @var{new} @key{RET}
361Replace the word (just this time) with @var{new}. (The replacement
362string will be rescanned for more spelling errors.)
363
364@item R @var{new} @key{RET}
365Replace the word with @var{new}, and do a @code{query-replace} so you
366can replace it elsewhere in the buffer if you wish. (The replacements
367will be rescanned for more spelling errors.)
368
369@item @var{digit}
370Replace the word (just this time) with one of the displayed
371near-misses. Each near-miss is listed with a digit; type that digit to
372select it.
373
374@item a
375Accept the incorrect word---treat it as correct, but only in this
376editing session.
377
378@item A
379Accept the incorrect word---treat it as correct, but only in this
380editing session and for this buffer.
381
382@item i
383Insert this word in your private dictionary file so that Aspell or Ispell will
384consider it correct from now on, even in future sessions.
385
386@item u
387Insert the lower-case version of this word in your private dic@-tion@-ary
388file.
389
390@item m
391Like @kbd{i}, but you can also specify dictionary completion
392information.
393
394@item l @var{word} @key{RET}
395Look in the dictionary for words that match @var{word}. These words
396become the new list of ``near-misses''; you can select one of them as
397the replacement by typing a digit. You can use @samp{*} in @var{word} as a
398wildcard.
399
400@item C-g
401Quit interactive spell checking, leaving point at the word that was
402being checked. You can restart checking again afterward with @kbd{C-u
403M-$}.
404
405@item X
406Same as @kbd{C-g}.
407
408@item x
409Quit interactive spell checking and move point back to where it was
410when you started spell checking.
411
412@item q
413Quit interactive spell checking and kill the Ispell subprocess.
414
415@item C-l
416Refresh the screen.
417
418@item C-z
419This key has its normal command meaning (suspend Emacs or iconify this
420frame).
421
422@item ?
423Show the list of options.
424@end table
425
426@findex ispell-complete-word
427 The command @code{ispell-complete-word}, which is bound to the key
428@kbd{M-@key{TAB}} in Text mode and related modes, shows a list of
429completions based on spelling correction. Insert the beginning of a
430word, and then type @kbd{M-@key{TAB}}; the command displays a
431completion list window. (If your window manager intercepts
432@kbd{M-@key{TAB}}, type @kbd{@key{ESC} @key{TAB}} or @kbd{C-M-i}.) To
433choose one of the completions listed, click @kbd{Mouse-2} or
434@kbd{Mouse-1} fast on it, or move the cursor there in the completions
435window and type @key{RET}. @xref{Text Mode}.
436
437@ignore
438@findex reload-ispell
439 The first time you use any of the spell checking commands, it starts
440an Ispell subprocess. The first thing the subprocess does is read your
441private dictionary, which defaults to the file @file{~/ispell.words}.
442Words that you ``insert'' with the @kbd{i} command are added to that
443file, but not right away---only at the end of the interactive
444replacement procedure. Use the @kbd{M-x reload-ispell} command to
445reload your private dictionary if you edit the file outside of Ispell.
446@end ignore
447
448@cindex @code{ispell} program
449@findex ispell-kill-ispell
450 Once started, the Aspell or Ispell subprocess continues to run
451(waiting for something to do), so that subsequent spell checking
452commands complete more quickly. If you want to get rid of the
453process, use @kbd{M-x ispell-kill-ispell}. This is not usually
454necessary, since the process uses no time except when you do spelling
455correction.
456
457@vindex ispell-dictionary
458 Ispell and Aspell use two dictionaries together for spell checking: the
459standard dictionary and your private dictionary. The variable
460@code{ispell-dictionary} specifies the file name to use for the
461standard dictionary; a value of @code{nil} selects the default
462dictionary. The command @kbd{M-x ispell-change-dictionary} sets this
463variable and then restarts the subprocess, so that it will use
464a different standard dictionary.
465
466@vindex ispell-complete-word-dict
467 Aspell and Ispell use a separate dictionary for word completion.
468The variable @code{ispell-complete-word-dict} specifies the file name
469of this dictionary. The completion dictionary must be different
470because it cannot use root and affix information. For some languages
471there is a spell checking dictionary but no word completion
472dictionary.
473
474@ignore
475 arch-tag: 3359a443-96ed-448f-9f05-c8111ba8eac0
476@end ignore