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