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