* admin/gitmerge.el (gitmerge-missing):
[emacs.git] / doc / emacs / fixit.texi
blobf2dba832522ea48e6169800ceb766a2412e89cc9
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 2001-2017 Free Software
3 @c Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Fixit
6 @chapter Commands for Fixing Typos
7 @cindex typos, fixing
8 @cindex mistakes, correcting
10   In this chapter we describe commands that are useful when you catch
11 a mistake while editing.  The most fundamental of these commands is
12 the undo command @kbd{C-/} (also bound to @kbd{C-x u} and @kbd{C-_}).
13 This undoes a single command, or a
14 part of a command (as in the case of @code{query-replace}), or several
15 consecutive character insertions.  Consecutive repetitions of
16 @kbd{C-/} undo earlier and earlier changes, back to the limit of the
17 undo information available.
19   Aside from the commands described here, you can erase text using
20 deletion commands such as @key{DEL} (@code{delete-backward-char}).
21 These were described earlier in this manual.  @xref{Erasing}.
23 @menu
24 * Undo::        The Undo commands.
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} command reverses 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 back as the buffer's 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.  Consecutive character insertion
42 commands are usually grouped together into a single undo record, to
43 make undoing less tedious.
45 @table @kbd
46 @item C-/
47 @itemx C-x u
48 @itemx C-_
49 Undo one entry in the current buffer's undo records (@code{undo}).
50 @end table
52 @kindex C-x u
53 @kindex C-_
54 @kindex C-/
55 @findex undo
56   To begin to undo, type @kbd{C-/} (or its aliases, @kbd{C-_} or
57 @kbd{C-x u})@footnote{Aside from @kbd{C-/}, the @code{undo} command is
58 also bound to @kbd{C-x u} because that is more straightforward for
59 beginners to remember: @samp{u} stands for ``undo''.  It is also bound
60 to @kbd{C-_} because typing @kbd{C-/} on some text terminals actually
61 enters @kbd{C-_}.}.  This undoes the most recent change in the buffer,
62 and moves point back to where it was before that change.
63   Consecutive repetitions of @kbd{C-/} (or its aliases) undo earlier
64 and earlier changes in the current buffer.  If all the recorded
65 changes have already been undone, the undo command signals an error.
67 @cindex redo
68 @findex undo-only
69   Any command other than an undo command breaks the sequence of undo
70 commands.  Starting from that moment, the entire sequence of undo
71 commands that you have just performed are themselves placed into the
72 undo record, as a single set of changes.  Therefore, to re-apply
73 changes you have undone, type @kbd{C-f} or any other command that
74 harmlessly breaks the sequence of undoing; then type @kbd{C-/} to undo
75 the undo command.
77   Alternatively, if you want to resume undoing, without redoing
78 previous undo commands, use @kbd{M-x undo-only}.  This is like
79 @code{undo}, but will not redo changes you have just undone.
81 @c What about @kbd{M-x revert-buffer}? --xfq
82   If you notice that a buffer has been modified accidentally, the
83 easiest way to recover is to type @kbd{C-/} repeatedly until the stars
84 disappear from the front of the mode line (@pxref{Mode Line}).
85 Whenever an undo command makes the stars disappear from the mode line,
86 it means that the buffer contents are the same as they were when the
87 file was last read in or saved.  If you do not remember whether you
88 changed the buffer deliberately, type @kbd{C-/} once.  When you see
89 the last change you made undone, you will see whether it was an
90 intentional change.  If it was an accident, leave it undone.  If it
91 was deliberate, redo the change as described above.
93 @cindex selective undo
94 @kindex C-u C-/
95   When there is an active region, any use of @code{undo} performs
96 @dfn{selective undo}: it undoes the most recent change within the
97 region, instead of the entire buffer.  However, when Transient Mark
98 mode is off (@pxref{Disabled Transient Mark}), @kbd{C-/} always
99 operates on the entire buffer, ignoring the region.  In this case, you
100 can perform selective undo by supplying a prefix argument to the
101 @code{undo} command: @kbd{C-u C-/}.  To undo further changes in the
102 same region, repeat the @code{undo} command (no prefix argument is
103 needed).
105   Some specialized buffers do not make undo records.  Buffers whose
106 names start with spaces never do; these buffers are used internally by
107 Emacs to hold text that users don't normally look at or edit.
109 @vindex undo-limit
110 @vindex undo-strong-limit
111 @vindex undo-outer-limit
112 @cindex undo limit
113   When the undo information for a buffer becomes too large, Emacs discards
114 the oldest records from time to time (during @dfn{garbage
115 collection}).  You can specify how much undo information to keep by
116 setting the variables @code{undo-limit}, @code{undo-strong-limit}, and
117 @code{undo-outer-limit}.  Their values are expressed in bytes.
119   The variable @code{undo-limit} sets a soft limit: Emacs keeps undo
120 data for enough commands to reach this size, and perhaps exceed it,
121 but does not keep data for any earlier commands beyond that.  Its
122 default value is 80000.  The variable @code{undo-strong-limit} sets a
123 stricter limit: any previous command (though not the most recent one)
124 that pushes the size past this amount is forgotten.  The default value
125 of @code{undo-strong-limit} is 120000.
127   Regardless of the values of those variables, the most recent change
128 is never discarded unless it gets bigger than @code{undo-outer-limit}
129 (normally 12,000,000).  At that point, Emacs discards the undo data and
130 warns you about it.  This is the only situation in which you cannot
131 undo the last command.  If this happens, you can increase the value of
132 @code{undo-outer-limit} to make it even less likely to happen in the
133 future.  But if you didn't expect the command to create such large
134 undo data, then it is probably a bug and you should report it.
135 @xref{Bugs,, Reporting Bugs}.
137 @node Transpose
138 @section Transposing Text
140 @table @kbd
141 @item C-t
142 Transpose two characters (@code{transpose-chars}).
143 @item M-t
144 Transpose two words (@code{transpose-words}).
145 @item C-M-t
146 Transpose two balanced expressions (@code{transpose-sexps}).
147 @item C-x C-t
148 Transpose two lines (@code{transpose-lines}).
149 @end table
151 @kindex C-t
152 @findex transpose-chars
153   The common error of transposing two characters can be fixed, when they
154 are adjacent, with the @kbd{C-t} command (@code{transpose-chars}).  Normally,
155 @kbd{C-t} transposes the two characters on either side of point.  When
156 given at the end of a line, rather than transposing the last character of
157 the line with the newline, which would be useless, @kbd{C-t} transposes the
158 last two characters on the line.  So, if you catch your transposition error
159 right away, you can fix it with just a @kbd{C-t}.  If you don't catch it so
160 fast, you must move the cursor back between the two transposed
161 characters before you type @kbd{C-t}.  If you transposed a space with
162 the last character of the word before it, the word motion commands are
163 a good way of getting there.  Otherwise, a reverse search (@kbd{C-r})
164 is often the best way.  @xref{Search}.
166 @kindex C-x C-t
167 @findex transpose-lines
168 @kindex M-t
169 @findex transpose-words
170 @c Don't index C-M-t and transpose-sexps here, they are indexed in
171 @c programs.texi, in the "List Commands" node.
172 @c @kindex C-M-t
173 @c @findex transpose-sexps
174   @kbd{M-t} transposes the word before point with the word after point
175 (@code{transpose-words}).  It moves point forward over a word,
176 dragging the word preceding or containing point forward as well.  The
177 punctuation characters between the words do not move.  For example,
178 @w{@samp{FOO, BAR}} transposes into @w{@samp{BAR, FOO}} rather than
179 @samp{@w{BAR FOO,}}.
181   @kbd{C-M-t} (@code{transpose-sexps}) is a similar command for
182 transposing two expressions (@pxref{Expressions}), and @kbd{C-x C-t}
183 (@code{transpose-lines}) exchanges lines.  They work like @kbd{M-t}
184 except as regards what units of text they transpose.
186   A numeric argument to a transpose command serves as a repeat count: it
187 tells the transpose command to move the character (word, expression, line)
188 before or containing point across several other characters (words,
189 expressions, lines).  For example, @kbd{C-u 3 C-t} moves the character before
190 point forward across three other characters.  It would change
191 @samp{f@point{}oobar} into @samp{oobf@point{}ar}.  This is equivalent to
192 repeating @kbd{C-t} three times.  @kbd{C-u - 4 M-t} moves the word
193 before point backward across four words.  @kbd{C-u - C-M-t} would cancel
194 the effect of plain @kbd{C-M-t}.
196   A numeric argument of zero is assigned a special meaning (because
197 otherwise a command with a repeat count of zero would do nothing): to
198 transpose the character (word, expression, line) ending after point
199 with the one ending after the mark.
201 @node Fixing Case
202 @section Case Conversion
204 @table @kbd
205 @item M-- M-l
206 Convert last word to lower case.  Note @kbd{Meta--} is Meta-minus.
207 @item M-- M-u
208 Convert last word to all upper case.
209 @item M-- M-c
210 Convert last word to lower case with capital initial.
211 @end table
213 @kindex M-@t{-} M-l
214 @kindex M-@t{-} M-u
215 @kindex M-@t{-} M-c
216   A very common error is to type words in the wrong case.  Because of this,
217 the word case-conversion commands @kbd{M-l}, @kbd{M-u} and @kbd{M-c} have a
218 special feature when used with a negative argument: they do not move the
219 cursor.  As soon as you see you have mistyped the last word, you can simply
220 case-convert it and go on typing.  @xref{Case}.
222 @node Spelling
223 @section Checking and Correcting Spelling
224 @cindex spelling, checking and correcting
225 @cindex checking spelling
226 @cindex correcting spelling
228   This section describes the commands to check the spelling of a
229 single word or of a portion of a buffer.  These commands only work if
230 the spelling checker program Hunspell, Aspell, Ispell or Enchant is installed.
231 These programs are not part of Emacs, but one of them is usually
232 installed in GNU/Linux and other free operating systems.
233 @ifnottex
234 @xref{Top, Aspell,, aspell, The Aspell Manual}.
235 @end ifnottex
237 @table @kbd
238 @item M-$
239 Check and correct spelling of the word at point (@code{ispell-word}).
240 If the region is active, do it for all words in the region instead.
241 @item M-x ispell
242 Check and correct spelling of all words in the buffer.  If the region
243 is active, do it for all words in the region instead.
244 @item M-x ispell-buffer
245 Check and correct spelling in the buffer.
246 @item M-x ispell-region
247 Check and correct spelling in the region.
248 @item M-x ispell-message
249 Check and correct spelling in a draft mail message, excluding cited
250 material.
251 @item M-x ispell-change-dictionary @key{RET} @var{dict} @key{RET}
252 Restart the spell-checker process, using @var{dict} as the dictionary.
253 @item M-x ispell-kill-ispell
254 Kill the spell-checker subprocess.
255 @item M-@key{TAB}
256 @itemx @key{ESC} @key{TAB}
257 @itemx C-M-i
258 Complete the word before point based on the spelling dictionary
259 (@code{ispell-complete-word}).
260 @item M-x flyspell-mode
261 Enable Flyspell mode, which highlights all misspelled words.
262 @item M-x flyspell-prog-mode
263 Enable Flyspell mode for comments and strings only.
264 @end table
266 @kindex M-$
267 @findex ispell-word
268   To check the spelling of the word around or before point, and
269 optionally correct it as well, type @kbd{M-$} (@code{ispell-word}).
270 If a region is active, @kbd{M-$} checks the spelling of all words
271 within the region.  @xref{Mark}.  (When Transient Mark mode is off,
272 @kbd{M-$} always acts on the word around or before point, ignoring the
273 region; @pxref{Disabled Transient Mark}.)
275 @findex ispell
276 @findex ispell-buffer
277 @findex ispell-region
278 @cindex spell-checking the active region
279   Similarly, the command @kbd{M-x ispell} performs spell-checking in
280 the region if one is active, or in the entire buffer otherwise.  The
281 commands @kbd{M-x ispell-buffer} and @kbd{M-x ispell-region}
282 explicitly perform spell-checking on the entire buffer or the region
283 respectively.  To check spelling in an email message you are writing,
284 use @kbd{M-x ispell-message}; that command checks the whole buffer,
285 except for material that is indented or appears to be cited from other
286 messages.  @xref{Sending Mail}.
288   When one of these commands encounters what appears to be an
289 incorrect word, it asks you what to do.  It usually displays a list of
290 numbered @dfn{near-misses}---words that are close to the incorrect word.
291 Then you must type a single-character response.  Here are the valid
292 responses:
294 @table @kbd
295 @item @var{digit}
296 Replace the word, just this time, with one of the displayed
297 near-misses.  Each near-miss is listed with a digit; type that digit
298 to select it.
300 @item @key{SPC}
301 Skip this word---continue to consider it incorrect, but don't change it
302 here.
304 @item r @var{new} @key{RET}
305 Replace the word, just this time, with @var{new}.  (The replacement
306 string will be rescanned for more spelling errors.)
308 @item R @var{new} @key{RET}
309 Replace the word with @var{new}, and do a @code{query-replace} so you
310 can replace it elsewhere in the buffer if you wish.  (The replacements
311 will be rescanned for more spelling errors.)
313 @item a
314 Accept the incorrect word---treat it as correct, but only in this
315 editing session.
317 @item A
318 Accept the incorrect word---treat it as correct, but only in this
319 editing session and for this buffer.
321 @item i
322 Insert this word in your private dictionary file so that it will be
323 considered correct from now on, even in future sessions.
325 @item m
326 Like @kbd{i}, but you can also specify dictionary completion
327 information.
329 @item u
330 Insert the lower-case version of this word in your private dic@-tion@-ary
331 file.
333 @item l @var{word} @key{RET}
334 Look in the dictionary for words that match @var{word}.  These words
335 become the new list of near-misses; you can select one of them as
336 the replacement by typing a digit.  You can use @samp{*} in @var{word} as a
337 wildcard.
339 @item C-g
340 @itemx X
341 Quit interactive spell checking, leaving point at the word that was
342 being checked.  You can restart checking again afterward with @kbd{C-u
343 M-$}.
345 @item x
346 Quit interactive spell checking and move point back to where it was
347 when you started spell checking.
349 @item q
350 Quit interactive spell checking and kill the spell-checker subprocess.
352 @item ?
353 Show the list of options.
354 @end table
356 @findex ispell-complete-word
357   In Text mode and related modes, @kbd{M-@key{TAB}}
358 (@code{ispell-complete-word}) performs in-buffer completion based on
359 spelling correction.  Insert the beginning of a word, and then type
360 @kbd{M-@key{TAB}}; this shows a list of completions.  (If your
361 window manager intercepts @kbd{M-@key{TAB}}, type @kbd{@key{ESC}
362 @key{TAB}} or @kbd{C-M-i}.)  Each completion is listed with a digit or
363 character; type that digit or character to choose it.
365 @cindex @code{ispell} program
366 @findex ispell-kill-ispell
367   Once started, the spell-checker subprocess continues
368 to run, waiting for something to do, so that subsequent spell checking
369 commands complete more quickly.  If you want to get rid of the
370 process, use @kbd{M-x ispell-kill-ispell}.  This is not usually
371 necessary, since the process uses no processor time except when you do
372 spelling correction.
374 @vindex ispell-dictionary
375 @vindex ispell-local-dictionary
376 @vindex ispell-personal-dictionary
377 @findex ispell-change-dictionary
378   Spell-checkers look up spelling in two dictionaries:
379 the standard dictionary and your personal dictionary.  The standard
380 dictionary is specified by the variable @code{ispell-local-dictionary}
381 or, if that is @code{nil}, by the variable @code{ispell-dictionary}.
382 If both are @code{nil}, the spelling program's default dictionary is
383 used.  The command @kbd{M-x ispell-change-dictionary} sets the
384 standard dictionary for the buffer and then restarts the subprocess,
385 so that it will use a different standard dictionary.  Your personal
386 dictionary is specified by the variable
387 @code{ispell-personal-dictionary}.  If that is @code{nil}, the
388 spelling program looks for a personal dictionary in a default
389 location.
391 @vindex ispell-complete-word-dict
392   A separate dictionary is used for word completion.  The variable
393 @code{ispell-complete-word-dict} specifies the file name of this
394 dictionary.  The completion dictionary must be different because it
395 cannot use root and affix information.  For some languages, there
396 is a spell checking dictionary but no word completion dictionary.
398 @cindex Flyspell mode
399 @cindex mode, Flyspell
400 @findex flyspell-mode
401   Flyspell mode is a minor mode that performs automatic spell checking
402 as you type.  When it finds a word that it does not recognize, it
403 highlights that word.  Type @kbd{M-x flyspell-mode} to toggle Flyspell
404 mode in the current buffer.  To enable Flyspell mode in all text mode
405 buffers, add @code{flyspell-mode} to @code{text-mode-hook}.
406 @xref{Hooks}.
408 @findex flyspell-correct-word
409 @findex flyspell-auto-correct-word
410 @findex flyspell-correct-word-before-point
411   When Flyspell mode highlights a word as misspelled, you can click on
412 it with @kbd{mouse-2} (@code{flyspell-correct-word}) to display a menu
413 of possible corrections and actions.  In addition, @kbd{C-.} or
414 @kbd{@key{ESC}-@key{TAB}} (@code{flyspell-auto-correct-word}) will
415 propose various successive corrections for the word at point, and
416 @kbd{C-c $} (@code{flyspell-correct-word-before-point}) will pop up a
417 menu of possible corrections.  Of course, you can always correct the
418 misspelled word by editing it manually in any way you like.
420 @findex flyspell-prog-mode
421   Flyspell Prog mode works just like ordinary Flyspell mode, except
422 that it only checks words in comments and string constants.  This
423 feature is useful for editing programs.  Type @kbd{M-x
424 flyspell-prog-mode} to enable or disable this mode in the current
425 buffer.  To enable this mode in all programming mode buffers, add
426 @code{flyspell-prog-mode} to @code{prog-mode-hook} (@pxref{Hooks}).