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