This commit was manufactured by cvs2svn to create branch 'utf-2000'.
[chise/xemacs-chise.git-] / info / xemacs.info-6
1 This is ../info/xemacs.info, produced by makeinfo version 4.0 from
2 xemacs/xemacs.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * XEmacs: (xemacs).             XEmacs Editor.
7 END-INFO-DIR-ENTRY
8
9    This file documents the XEmacs editor.
10
11    Copyright (C) 1985, 1986, 1988 Richard M. Stallman.  Copyright (C)
12 1991, 1992, 1993, 1994 Lucid, Inc.  Copyright (C) 1993, 1994 Sun
13 Microsystems, Inc.  Copyright (C) 1995 Amdahl Corporation.
14
15    Permission is granted to make and distribute verbatim copies of this
16 manual provided the copyright notice and this permission notice are
17 preserved on all copies.
18
19    Permission is granted to copy and distribute modified versions of
20 this manual under the conditions for verbatim copying, provided also
21 that the sections entitled "The GNU Manifesto", "Distribution" and "GNU
22 General Public License" are included exactly as in the original, and
23 provided that the entire resulting derived work is distributed under the
24 terms of a permission notice identical to this one.
25
26    Permission is granted to copy and distribute translations of this
27 manual into another language, under the above conditions for modified
28 versions, except that the sections entitled "The GNU Manifesto",
29 "Distribution" and "GNU General Public License" may be included in a
30 translation approved by the author instead of in the original English.
31
32 \1f
33 File: xemacs.info,  Node: Scrolling,  Next: Horizontal Scrolling,  Prev: Display,  Up: Display
34
35 Scrolling
36 =========
37
38    If a buffer contains text that is too large to fit entirely within
39 the window that is displaying the buffer, XEmacs shows a contiguous
40 section of the text.  The section shown always contains point.
41
42    "Scrolling" means moving text up or down in the window so that
43 different parts of the text are visible.  Scrolling forward means that
44 text moves up, and new text appears at the bottom.  Scrolling backward
45 moves text down and new text appears at the top.
46
47    Scrolling happens automatically if you move point past the bottom or
48 top of the window.  You can also explicitly request scrolling with the
49 commands in this section.
50
51 `C-l'
52      Clear frame and redisplay, scrolling the selected window to center
53      point vertically within it (`recenter').
54
55 `C-v'
56 `pgdn'
57 `next'
58      Scroll forward (a windowful or a specified number of lines)
59      (`scroll-up').
60
61 `M-v'
62 `pgup'
63 `prior'
64      Scroll backward (`scroll-down').
65
66 `ARG C-l'
67      Scroll so point is on line ARG (`recenter').
68
69    The most basic scrolling command is `C-l' (`recenter') with no
70 argument.  It clears the entire frame and redisplays all windows.  In
71 addition, it scrolls the selected window so that point is halfway down
72 from the top of the window.
73
74    The scrolling commands `C-v' and `M-v' let you move all the text in
75 the window up or down a few lines.  `C-v' (`scroll-up') with an
76 argument shows you that many more lines at the bottom of the window,
77 moving the text and point up together as `C-l' might.  `C-v' with a
78 negative argument shows you more lines at the top of the window.
79 `Meta-v' (`scroll-down') is like `C-v', but moves in the opposite
80 direction.
81
82    To read the buffer a windowful at a time, use `C-v' with no
83 argument.  `C-v' takes the last two lines at the bottom of the window
84 and puts them at the top, followed by nearly a whole windowful of lines
85 not previously visible.  Point moves to the new top of the window if it
86 was in the text scrolled off the top.  `M-v' with no argument moves
87 backward with similar overlap.  The number of lines of overlap across a
88 `C-v' or `M-v' is controlled by the variable
89 `next-screen-context-lines'; by default, it is two.
90
91    Another way to scroll is using `C-l' with a numeric argument.  `C-l'
92 does not clear the frame when given an argument; it only scrolls the
93 selected window.  With a positive argument N, `C-l' repositions text to
94 put point N lines down from the top.  An argument of zero puts point on
95 the very top line.  Point does not move with respect to the text;
96 rather, the text and point move rigidly on the frame.  `C-l' with a
97 negative argument puts point that many lines from the bottom of the
98 window.  For example, `C-u - 1 C-l' puts point on the bottom line, and
99 `C-u - 5 C-l' puts it five lines from the bottom.  Just `C-u' as
100 argument, as in `C-u C-l', scrolls point to the center of the frame.
101
102    Scrolling happens automatically if point has moved out of the visible
103 portion of the text when it is time to display.  Usually scrolling is
104 done  to put point vertically centered within the window.  However, if
105 the variable `scroll-step' has a non-zero value, an attempt is made to
106 scroll the buffer by that many lines; if that is enough to bring point
107 back into visibility, that is what happens.
108
109    Scrolling happens automatically if point has moved out of the visible
110 portion of the text when it is time to display.  Usually scrolling is
111 done  to put point vertically centered within the window.  However, if
112 the variable `scroll-step' has a non-zero value, an attempt is made to
113 scroll the buffer by that many lines; if that is enough to bring point
114 back into visibility, that is what happens.
115
116    If you set `scroll-step' to a small value because you want to use
117 arrow keys to scroll the screen without recentering, the redisplay
118 preemption will likely make XEmacs keep recentering the screen when
119 scrolling fast, regardless of `scroll-step'.  To prevent this, set
120 `scroll-conservatively' to a small value, which will have the result of
121 overriding the redisplay preemption.
122
123 \1f
124 File: xemacs.info,  Node: Horizontal Scrolling,  Prev: Scrolling,  Up: Display
125
126 Horizontal Scrolling
127 ====================
128
129 `C-x <'
130      Scroll text in current window to the left (`scroll-left').
131
132 `C-x >'
133      Scroll to the right (`scroll-right').
134
135    The text in a window can also be scrolled horizontally.  This means
136 that each line of text is shifted sideways in the window, and one or
137 more characters at the beginning of each line are not displayed at all.
138 When a window has been scrolled horizontally in this way, text lines
139 are truncated rather than continued (*note Continuation Lines::), with
140 a `$' appearing in the first column when there is text truncated to the
141 left, and in the last column when there is text truncated to the right.
142
143    The command `C-x <' (`scroll-left') scrolls the selected window to
144 the left by N columns with argument N.  With no argument, it scrolls by
145 almost the full width of the window (two columns less, to be precise).
146 `C-x >' (`scroll-right') scrolls similarly to the right.  The window
147 cannot be scrolled any farther to the right once it is displaying
148 normally (with each line starting at the window's left margin);
149 attempting to do so has no effect.
150
151 \1f
152 File: xemacs.info,  Node: Selective Display,  Next: Display Vars,  Prev: Display,  Up: Display
153
154 Selective Display
155 =================
156
157    XEmacs can hide lines indented more than a certain number of columns
158 (you specify how many columns).  This allows you  to get an overview of
159 a part of a program.
160
161    To hide lines, type `C-x $' (`set-selective-display') with a numeric
162 argument N.  (*Note Arguments::, for information on giving the
163 argument.)  Lines with at least N columns of indentation disappear from
164 the screen.  The only indication of their presence are three dots
165 (`...'), which appear at the end of each visible line that is followed
166 by one or more invisible ones.
167
168    The invisible lines are still present in the buffer, and most editing
169 commands see them as usual, so it is very easy to put point in the
170 middle of invisible text.  When this happens, the cursor appears at the
171 end of the previous line, after the three dots.  If point is at the end
172 of the visible line, before the newline that ends it, the cursor
173 appears before the three dots.
174
175    The commands `C-n' and `C-p' move across the invisible lines as if
176 they were not there.
177
178    To make everything visible again, type `C-x $' with no argument.
179
180 \1f
181 File: xemacs.info,  Node: Display Vars,  Prev: Selective Display,  Up: Display
182
183 Variables Controlling Display
184 =============================
185
186    This section contains information for customization only.  Beginning
187 users should skip it.
188
189    When you reenter XEmacs after suspending, XEmacs normally clears the
190 screen and redraws the entire display.  On some terminals with more than
191 one page of memory, it is possible to arrange the termcap entry so that
192 the `ti' and `te' strings (output to the terminal when XEmacs is
193 entered and exited, respectively) switch between pages of memory so as
194 to use one page for XEmacs and another page for other output.  In that
195 case, you might want to set the variable `no-redraw-on-reenter' to
196 non-`nil' so that XEmacs will assume, when resumed, that the screen
197 page it is using still contains what XEmacs last wrote there.
198
199    The variable `echo-keystrokes' controls the echoing of
200 multi-character keys; its value is the number of seconds of pause
201 required to cause echoing to start, or zero, meaning don't echo at all.
202 *Note Echo Area::.
203
204    If the variable `ctl-arrow' is `nil', control characters in the
205 buffer are displayed with octal escape sequences, all except newline and
206 tab.  If its value is `t', then control characters will be printed with
207 an up-arrow, for example `^A'.
208
209    If its value is not `t' and not `nil', then characters whose code is
210 greater than 160 (that is, the space character (32) with its high bit
211 set) will be assumed to be printable, and will be displayed without
212 alteration.  This is the default when running under X Windows, since
213 XEmacs assumes an ISO/8859-1 character set (also known as "Latin1").
214 The `ctl-arrow' variable may also be set to an integer, in which case
215 all characters whose codes are greater than or equal to that value will
216 be assumed to be printable.
217
218    Altering the value of `ctl-arrow' makes it local to the current
219 buffer; until that time, the default value is in effect.  *Note
220 Locals::.
221
222    Normally, a tab character in the buffer is displayed as whitespace
223 which extends to the next display tab stop position, and display tab
224 stops come at intervals equal to eight spaces.  The number of spaces
225 per tab is controlled by the variable `tab-width', which is made local
226 by changing it, just like `ctl-arrow'.  Note that how the tab character
227 in the buffer is displayed has nothing to do with the definition of
228 <TAB> as a command.
229
230    If you set the variable `selective-display-ellipses' to `nil', the
231 three dots at the end of a line that precedes invisible lines do not
232 appear.  There is no visible indication of the invisible lines.  This
233 variable becomes local automatically when set.
234
235 \1f
236 File: xemacs.info,  Node: Search,  Next: Fixit,  Prev: Display,  Up: Top
237
238 Searching and Replacement
239 *************************
240
241    Like other editors, Emacs has commands for searching for occurrences
242 of a string.  The principal search command is unusual in that it is
243 "incremental": it begins to search before you have finished typing the
244 search string.  There are also non-incremental search commands more like
245 those of other editors.
246
247    Besides the usual `replace-string' command that finds all
248 occurrences of one string and replaces them with another, Emacs has a
249 fancy replacement command called `query-replace' which asks
250 interactively which occurrences to replace.
251
252 * Menu:
253
254 * Incremental Search::     Search happens as you type the string.
255 * Non-Incremental Search:: Specify entire string and then search.
256 * Word Search::            Search for sequence of words.
257 * Regexp Search::          Search for match for a regexp.
258 * Regexps::                Syntax of regular expressions.
259 * Search Case::            To ignore case while searching, or not.
260 * Replace::                Search, and replace some or all matches.
261 * Other Repeating Search:: Operating on all matches for some regexp.
262
263 \1f
264 File: xemacs.info,  Node: Incremental Search,  Next: Non-Incremental Search,  Prev: Search,  Up: Search
265
266 Incremental Search
267 ==================
268
269    An incremental search begins searching as soon as you type the first
270 character of the search string.  As you type in the search string, Emacs
271 shows you where the string (as you have typed it so far) is found.
272 When you have typed enough characters to identify the place you want,
273 you can stop.  Depending on what you do next, you may or may not need to
274 terminate the search explicitly with a <RET>.
275
276 `C-s'
277      Incremental search forward (`isearch-forward').
278
279 `C-r'
280      Incremental search backward (`isearch-backward').
281
282    `C-s' starts an incremental search.  `C-s' reads characters from the
283 keyboard and positions the cursor at the first occurrence of the
284 characters that you have typed.  If you type `C-s' and then `F', the
285 cursor moves right after the first `F'.  Type an `O', and see the
286 cursor move to after the first `FO'.  After another `O', the cursor is
287 after the first `FOO' after the place where you started the search.
288 Meanwhile, the search string `FOO' has been echoed in the echo area.
289
290    The echo area display ends with three dots when actual searching is
291 going on.  When search is waiting for more input, the three dots are
292 removed.  (On slow terminals, the three dots are not displayed.)
293
294    If you make a mistake in typing the search string, you can erase
295 characters with <DEL>.  Each <DEL> cancels the last character of the
296 search string.  This does not happen until Emacs is ready to read
297 another input character; first it must either find, or fail to find,
298 the character you want to erase.  If you do not want to wait for this
299 to happen, use `C-g' as described below.
300
301    When you are satisfied with the place you have reached, you can type
302 <RET> (or <C-m>), which stops searching, leaving the cursor where the
303 search brought it.  Any command not specially meaningful in searches
304 also stops the search and is then executed.  Thus, typing `C-a' exits
305 the search and then moves to the beginning of the line.  <RET> is
306 necessary only if the next command you want to type is a printing
307 character, <DEL>, <ESC>, or another control character that is special
308 within searches (`C-q', `C-w', `C-r', `C-s', or `C-y').
309
310    Sometimes you search for `FOO' and find it, but were actually
311 looking for a different occurrence of it.  To move to the next
312 occurrence of the search string, type another `C-s'.  Do this as often
313 as necessary.  If you overshoot, you can cancel some `C-s' characters
314 with <DEL>.
315
316    After you exit a search, you can search for the same string again by
317 typing just `C-s C-s': the first `C-s' is the key that invokes
318 incremental search, and the second `C-s' means "search again".
319
320    If the specified string is not found at all, the echo area displays
321 the text `Failing I-Search'.  The cursor is after the place where Emacs
322 found as much of your string as it could.  Thus, if you search for
323 `FOOT', and there is no `FOOT', the cursor may be after the `FOO' in
324 `FOOL'.  At this point there are several things you can do.  If you
325 mistyped the search string, correct it.  If you like the place you have
326 found, you can type <RET> or some other Emacs command to "accept what
327 the search offered".  Or you can type `C-g', which removes from the
328 search string the characters that could not be found (the `T' in
329 `FOOT'), leaving those that were found (the `FOO' in `FOOT').  A second
330 `C-g' at that point cancels the search entirely, returning point to
331 where it was when the search started.
332
333    If a search is failing and you ask to repeat it by typing another
334 `C-s', it starts again from the beginning of the buffer.  Repeating a
335 failing backward search with `C-r' starts again from the end.  This is
336 called "wrapping around".  `Wrapped' appears in the search prompt once
337 this has happened.
338
339    The `C-g' "quit" character does special things during searches; just
340 what it does depends on the status of the search.  If the search has
341 found what you specified and is waiting for input, `C-g' cancels the
342 entire search.  The cursor moves back to where you started the search.
343 If `C-g' is typed when there are characters in the search string that
344 have not been found--because Emacs is still searching for them, or
345 because it has failed to find them--then the search string characters
346 which have not been found are discarded from the search string.  The
347 search is now successful and waiting for more input, so a second `C-g'
348 cancels the entire search.
349
350    To search for a control character such as `C-s' or <DEL> or <ESC>,
351 you must quote it by typing `C-q' first.  This function of `C-q' is
352 analogous to its meaning as an Emacs command: it causes the following
353 character to be treated the way a graphic character would normally be
354 treated in the same context.
355
356    To search backwards, you can use `C-r' instead of `C-s' to start the
357 search; `C-r' is the key that runs the command (`isearch-backward') to
358 search backward.  You can also use `C-r' to change from searching
359 forward to searching backwards.  Do this if a search fails because the
360 place you started was too far down in the file.  Repeated `C-r' keeps
361 looking for more occurrences backwards.  `C-s' starts going forward
362 again.  You can cancel `C-r' in a search with <DEL>.
363
364    The characters `C-y' and `C-w' can be used in incremental search to
365 grab text from the buffer into the search string.  This makes it
366 convenient to search for another occurrence of text at point.  `C-w'
367 copies the word after point as part of the search string, advancing
368 point over that word.  Another `C-s' to repeat the search will then
369 search for a string including that word.  `C-y' is similar to `C-w' but
370 copies the rest of the current line into the search string.
371
372    The characters `M-p' and `M-n' can be used in an incremental search
373 to recall things which you have searched for in the past.  A list of
374 the last 16 things you have searched for is retained, and `M-p' and
375 `M-n' let you cycle through that ring.
376
377    The character `M-<TAB>' does completion on the elements in the
378 search history ring.  For example, if you know that you have recently
379 searched for the string `POTATOE', you could type `C-s P O M-<TAB>'.
380 If you had searched for other strings beginning with `PO' then you
381 would be shown a list of them, and would need to type more to select
382 one.
383
384    You can change any of the special characters in incremental search
385 via the normal keybinding mechanism: simply add a binding to the
386 `isearch-mode-map'.  For example, to make the character `C-b' mean
387 "search backwards" while in isearch-mode, do this:
388
389      (define-key isearch-mode-map "\C-b" 'isearch-repeat-backward)
390
391    These are the default bindings of isearch-mode:
392
393 `DEL'
394      Delete a character from the incremental search string
395      (`isearch-delete-char').
396
397 `RET'
398      Exit incremental search (`isearch-exit').
399
400 `C-q'
401      Quote special characters for incremental search
402      (`isearch-quote-char').
403
404 `C-s'
405      Repeat incremental search forward (`isearch-repeat-forward').
406
407 `C-r'
408      Repeat incremental search backward (`isearch-repeat-backward').
409
410 `C-y'
411      Pull rest of line from buffer into search string
412      (`isearch-yank-line').
413
414 `C-w'
415      Pull next word from buffer into search string
416      (`isearch-yank-word').
417
418 `C-g'
419      Cancels input back to what has been found successfully, or aborts
420      the isearch (`isearch-abort').
421
422 `M-p'
423      Recall the previous element in the isearch history ring
424      (`isearch-ring-retreat').
425
426 `M-n'
427      Recall the next element in the isearch history ring
428      (`isearch-ring-advance').
429
430 `M-<TAB>'
431      Do completion on the elements in the isearch history ring
432      (`isearch-complete').
433
434    Any other character which is normally inserted into a buffer when
435 typed is automatically added to the search string in isearch-mode.
436
437 Slow Terminal Incremental Search
438 --------------------------------
439
440    Incremental search on a slow terminal uses a modified style of
441 display that is designed to take less time.  Instead of redisplaying
442 the buffer at each place the search gets to, it creates a new
443 single-line window and uses that to display the line the search has
444 found.  The single-line window appears as soon as point gets outside of
445 the text that is already on the screen.
446
447    When the search is terminated, the single-line window is removed.
448 Only at this time the window in which the search was done is
449 redisplayed to show its new value of point.
450
451    The three dots at the end of the search string, normally used to
452 indicate that searching is going on, are not displayed in slow style
453 display.
454
455    The slow terminal style of display is used when the terminal baud
456 rate is less than or equal to the value of the variable
457 `search-slow-speed', initially 1200.
458
459    The number of lines to use in slow terminal search display is
460 controlled by the variable `search-slow-window-lines'.  Its normal
461 value is 1.
462
463 \1f
464 File: xemacs.info,  Node: Non-Incremental Search,  Next: Word Search,  Prev: Incremental Search,  Up: Search
465
466 Non-Incremental Search
467 ======================
468
469    Emacs also has conventional non-incremental search commands, which
470 require you type the entire search string before searching begins.
471
472 `C-s <RET> STRING <RET>'
473      Search for STRING.
474
475 `C-r <RET> STRING <RET>'
476      Search backward for STRING.
477
478    To do a non-incremental search, first type `C-s <RET>' (or `C-s
479 C-m').  This enters the minibuffer to read the search string.
480 Terminate the string with <RET> to start the search.  If the string is
481 not found, the search command gets an error.
482
483    By default, `C-s' invokes incremental search, but if you give it an
484 empty argument, which would otherwise be useless, it invokes
485 non-incremental search.  Therefore, `C-s <RET>' invokes non-incremental
486 search.  `C-r <RET>' also works this way.
487
488    Forward and backward non-incremental searches are implemented by the
489 commands `search-forward' and `search-backward'.  You can bind these
490 commands to keys.  The reason that incremental search is programmed to
491 invoke them as well is that `C-s <RET>' is the traditional sequence of
492 characters used in Emacs to invoke non-incremental search.
493
494    Non-incremental searches performed using `C-s <RET>' do not call
495 `search-forward' right away.  They first check if the next character is
496 `C-w', which requests a word search.  *Note Word Search::.
497
498 \1f
499 File: xemacs.info,  Node: Word Search,  Next: Regexp Search,  Prev: Non-Incremental Search,  Up: Search
500
501 Word Search
502 ===========
503
504    Word search looks for a sequence of words without regard to how the
505 words are separated.  More precisely, you type a string of many words,
506 using single spaces to separate them, and the string is found even if
507 there are multiple spaces, newlines or other punctuation between the
508 words.
509
510    Word search is useful in editing documents formatted by text
511 formatters.  If you edit while looking at the printed, formatted
512 version, you can't tell where the line breaks are in the source file.
513 Word search, allows you to search  without having to know the line
514 breaks.
515
516 `C-s <RET> C-w WORDS <RET>'
517      Search for WORDS, ignoring differences in punctuation.
518
519 `C-r <RET> C-w WORDS <RET>'
520      Search backward for WORDS, ignoring differences in punctuation.
521
522    Word search is a special case of non-incremental search.  It is
523 invoked with `C-s <RET> C-w' followed by the search string, which must
524 always be terminated with another <RET>.  Being non-incremental, this
525 search does not start until the argument is terminated.  It works by
526 constructing a regular expression and searching for that.  *Note Regexp
527 Search::.
528
529    You can do a backward word search with `C-r <RET> C-w'.
530
531    Forward and backward word searches are implemented by the commands
532 `word-search-forward' and `word-search-backward'.  You can bind these
533 commands to keys.  The reason that incremental search is programmed to
534 invoke them as well is that `C-s <RET> C-w' is the traditional Emacs
535 sequence of keys for word search.
536
537 \1f
538 File: xemacs.info,  Node: Regexp Search,  Next: Regexps,  Prev: Word Search,  Up: Search
539
540 Regular Expression Search
541 =========================
542
543    A "regular expression" ("regexp", for short) is a pattern that
544 denotes a (possibly infinite) set of strings.  Searching for matches
545 for a regexp is a powerful operation that editors on Unix systems have
546 traditionally offered.
547
548    To gain a thorough understanding of regular expressions and how to
549 use them to best advantage, we recommend that you study `Mastering
550 Regular Expressions, by Jeffrey E.F. Friedl, O'Reilly and Associates,
551 1997'. (It's known as the "Hip Owls" book, because of the picture on its
552 cover.)  You might also read the manuals to *Note (gawk)Top::, *Note
553 (ed)Top::, `sed', `grep', *Note (perl)Top::, *Note (regex)Top::, *Note
554 (rx)Top::, `pcre', and *Note (flex)Top::, which also make good use of
555 regular expressions.
556
557    The XEmacs regular expression syntax most closely resembles that of
558 `ed', or `grep', the GNU versions of which all utilize the GNU `regex'
559 library.  XEmacs' version of `regex' has recently been extended with
560 some Perl-like capabilities, described in the next section.
561
562    In XEmacs, you can search for the next match for a regexp either
563 incrementally or not.
564
565    Incremental search for a regexp is done by typing `M-C-s'
566 (`isearch-forward-regexp').  This command reads a search string
567 incrementally just like `C-s', but it treats the search string as a
568 regexp rather than looking for an exact match against the text in the
569 buffer.  Each time you add text to the search string, you make the
570 regexp longer, and the new regexp is searched for.  A reverse regexp
571 search command `isearch-backward-regexp' also exists, bound to `M-C-r'.
572
573    All of the control characters that do special things within an
574 ordinary incremental search have the same functionality in incremental
575 regexp search.  Typing `C-s' or `C-r' immediately after starting a
576 search retrieves the last incremental search regexp used: incremental
577 regexp and non-regexp searches have independent defaults.
578
579    Non-incremental search for a regexp is done by the functions
580 `re-search-forward' and `re-search-backward'.  You can invoke them with
581 `M-x' or bind them to keys.  You can also call `re-search-forward' by
582 way of incremental regexp search with `M-C-s <RET>'; similarly for
583 `re-search-backward' with `M-C-r <RET>'.
584
585 \1f
586 File: xemacs.info,  Node: Regexps,  Next: Search Case,  Prev: Regexp Search,  Up: Search
587
588 Syntax of Regular Expressions
589 =============================
590
591    Regular expressions have a syntax in which a few characters are
592 special constructs and the rest are "ordinary".  An ordinary character
593 is a simple regular expression that matches that character and nothing
594 else.  The special characters are `.', `*', `+', `?', `[', `]', `^',
595 `$', and `\'; no new special characters will be defined in the future.
596 Any other character appearing in a regular expression is ordinary,
597 unless a `\' precedes it.
598
599    For example, `f' is not a special character, so it is ordinary, and
600 therefore `f' is a regular expression that matches the string `f' and
601 no other string.  (It does _not_ match the string `ff'.)  Likewise, `o'
602 is a regular expression that matches only `o'.
603
604    Any two regular expressions A and B can be concatenated.  The result
605 is a regular expression that matches a string if A matches some amount
606 of the beginning of that string and B matches the rest of the string.
607
608    As a simple example, we can concatenate the regular expressions `f'
609 and `o' to get the regular expression `fo', which matches only the
610 string `fo'.  Still trivial.  To do something more powerful, you need
611 to use one of the special characters.  Here is a list of them:
612
613 `. (Period)'
614      is a special character that matches any single character except a
615      newline.  Using concatenation, we can make regular expressions
616      like `a.b', which matches any three-character string that begins
617      with `a' and ends with `b'.
618
619 `*'
620      is not a construct by itself; it is a quantifying suffix operator
621      that means to repeat the preceding regular expression as many
622      times as possible.  In `fo*', the `*' applies to the `o', so `fo*'
623      matches one `f' followed by any number of `o's.  The case of zero
624      `o's is allowed: `fo*' does match `f'.
625
626      `*' always applies to the _smallest_ possible preceding
627      expression.  Thus, `fo*' has a repeating `o', not a repeating `fo'.
628
629      The matcher processes a `*' construct by matching, immediately, as
630      many repetitions as can be found; it is "greedy".  Then it
631      continues with the rest of the pattern.  If that fails,
632      backtracking occurs, discarding some of the matches of the
633      `*'-modified construct in case that makes it possible to match the
634      rest of the pattern.  For example, in matching `ca*ar' against the
635      string `caaar', the `a*' first tries to match all three `a's; but
636      the rest of the pattern is `ar' and there is only `r' left to
637      match, so this try fails.  The next alternative is for `a*' to
638      match only two `a's.  With this choice, the rest of the regexp
639      matches successfully.
640
641      Nested repetition operators can be extremely slow if they specify
642      backtracking loops.  For example, it could take hours for the
643      regular expression `\(x+y*\)*a' to match the sequence
644      `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz'.  The slowness is because
645      Emacs must try each imaginable way of grouping the 35 `x''s before
646      concluding that none of them can work.  To make sure your regular
647      expressions run fast, check nested repetitions carefully.
648
649 `+'
650      is a quantifying suffix operator similar to `*' except that the
651      preceding expression must match at least once.  It is also
652      "greedy".  So, for example, `ca+r' matches the strings `car' and
653      `caaaar' but not the string `cr', whereas `ca*r' matches all three
654      strings.
655
656 `?'
657      is a quantifying suffix operator similar to `*', except that the
658      preceding expression can match either once or not at all.  For
659      example, `ca?r' matches `car' or `cr', but does not match anything
660      else.
661
662 `*?'
663      works just like `*', except that rather than matching the longest
664      match, it matches the shortest match.  `*?' is known as a
665      "non-greedy" quantifier, a regexp construct borrowed from Perl.
666
667      This construct is very useful for when you want to match the text
668      inside a pair of delimiters.  For instance, `/\*.*?\*/' will match
669      C comments in a string.  This could not easily be achieved without
670      the use of a non-greedy quantifier.
671
672      This construct has not been available prior to XEmacs 20.4.  It is
673      not available in FSF Emacs.
674
675 `+?'
676      is the non-greedy version of `+'.
677
678 `??'
679      is the non-greedy version of `?'.
680
681 `\{n,m\}'
682      serves as an interval quantifier, analogous to `*' or `+', but
683      specifies that the expression must match at least N times, but no
684      more than M times.  This syntax is supported by most Unix regexp
685      utilities, and has been introduced to XEmacs for the version 20.3.
686
687      Unfortunately, the non-greedy version of this quantifier does not
688      exist currently, although it does in Perl.
689
690 `[ ... ]'
691      `[' begins a "character set", which is terminated by a `]'.  In
692      the simplest case, the characters between the two brackets form
693      the set.  Thus, `[ad]' matches either one `a' or one `d', and
694      `[ad]*' matches any string composed of just `a's and `d's
695      (including the empty string), from which it follows that `c[ad]*r'
696      matches `cr', `car', `cdr', `caddaar', etc.
697
698      The usual regular expression special characters are not special
699      inside a character set.  A completely different set of special
700      characters exists inside character sets: `]', `-' and `^'.
701
702      `-' is used for ranges of characters.  To write a range, write two
703      characters with a `-' between them.  Thus, `[a-z]' matches any
704      lower case letter.  Ranges may be intermixed freely with individual
705      characters, as in `[a-z$%.]', which matches any lower case letter
706      or `$', `%', or a period.
707
708      To include a `]' in a character set, make it the first character.
709      For example, `[]a]' matches `]' or `a'.  To include a `-', write
710      `-' as the first character in the set, or put it immediately after
711      a range.  (You can replace one individual character C with the
712      range `C-C' to make a place to put the `-'.)  There is no way to
713      write a set containing just `-' and `]'.
714
715      To include `^' in a set, put it anywhere but at the beginning of
716      the set.
717
718 `[^ ... ]'
719      `[^' begins a "complement character set", which matches any
720      character except the ones specified.  Thus, `[^a-z0-9A-Z]' matches
721      all characters _except_ letters and digits.
722
723      `^' is not special in a character set unless it is the first
724      character.  The character following the `^' is treated as if it
725      were first (thus, `-' and `]' are not special there).
726
727      Note that a complement character set can match a newline, unless
728      newline is mentioned as one of the characters not to match.
729
730 `^'
731      is a special character that matches the empty string, but only at
732      the beginning of a line in the text being matched.  Otherwise it
733      fails to match anything.  Thus, `^foo' matches a `foo' that occurs
734      at the beginning of a line.
735
736      When matching a string instead of a buffer, `^' matches at the
737      beginning of the string or after a newline character `\n'.
738
739 `$'
740      is similar to `^' but matches only at the end of a line.  Thus,
741      `x+$' matches a string of one `x' or more at the end of a line.
742
743      When matching a string instead of a buffer, `$' matches at the end
744      of the string or before a newline character `\n'.
745
746 `\'
747      has two functions: it quotes the special characters (including
748      `\'), and it introduces additional special constructs.
749
750      Because `\' quotes special characters, `\$' is a regular
751      expression that matches only `$', and `\[' is a regular expression
752      that matches only `[', and so on.
753
754    *Please note:* For historical compatibility, special characters are
755 treated as ordinary ones if they are in contexts where their special
756 meanings make no sense.  For example, `*foo' treats `*' as ordinary
757 since there is no preceding expression on which the `*' can act.  It is
758 poor practice to depend on this behavior; quote the special character
759 anyway, regardless of where it appears.
760
761    For the most part, `\' followed by any character matches only that
762 character.  However, there are several exceptions: characters that,
763 when preceded by `\', are special constructs.  Such characters are
764 always ordinary when encountered on their own.  Here is a table of `\'
765 constructs:
766
767 `\|'
768      specifies an alternative.  Two regular expressions A and B with
769      `\|' in between form an expression that matches anything that
770      either A or B matches.
771
772      Thus, `foo\|bar' matches either `foo' or `bar' but no other string.
773
774      `\|' applies to the largest possible surrounding expressions.
775      Only a surrounding `\( ... \)' grouping can limit the grouping
776      power of `\|'.
777
778      Full backtracking capability exists to handle multiple uses of
779      `\|'.
780
781 `\( ... \)'
782      is a grouping construct that serves three purposes:
783
784        1. To enclose a set of `\|' alternatives for other operations.
785           Thus, `\(foo\|bar\)x' matches either `foox' or `barx'.
786
787        2. To enclose an expression for a suffix operator such as `*' to
788           act on.  Thus, `ba\(na\)*' matches `bananana', etc., with any
789           (zero or more) number of `na' strings.
790
791        3. To record a matched substring for future reference.
792
793      This last application is not a consequence of the idea of a
794      parenthetical grouping; it is a separate feature that happens to be
795      assigned as a second meaning to the same `\( ... \)' construct
796      because there is no conflict in practice between the two meanings.
797      Here is an explanation of this feature:
798
799 `\DIGIT'
800      matches the same text that matched the DIGITth occurrence of a `\(
801      ... \)' construct.
802
803      In other words, after the end of a `\( ... \)' construct.  the
804      matcher remembers the beginning and end of the text matched by that
805      construct.  Then, later on in the regular expression, you can use
806      `\' followed by DIGIT to match that same text, whatever it may
807      have been.
808
809      The strings matching the first nine `\( ... \)' constructs
810      appearing in a regular expression are assigned numbers 1 through 9
811      in the order that the open parentheses appear in the regular
812      expression.  So you can use `\1' through `\9' to refer to the text
813      matched by the corresponding `\( ... \)' constructs.
814
815      For example, `\(.*\)\1' matches any newline-free string that is
816      composed of two identical halves.  The `\(.*\)' matches the first
817      half, which may be anything, but the `\1' that follows must match
818      the same exact text.
819
820 `\(?: ... \)'
821      is called a "shy" grouping operator, and it is used just like `\(
822      ... \)', except that it does not cause the matched substring to be
823      recorded for future reference.
824
825      This is useful when you need a lot of grouping `\( ... \)'
826      constructs, but only want to remember one or two - or if you have
827      more than nine groupings and need to use backreferences to refer to
828      the groupings at the end.
829
830      Using `\(?: ... \)' rather than `\( ... \)' when you don't need
831      the captured substrings ought to speed up your programs some,
832      since it shortens the code path followed by the regular expression
833      engine, as well as the amount of memory allocation and string
834      copying it must do.  The actual performance gain to be observed
835      has not been measured or quantified as of this writing.
836
837      The shy grouping operator has been borrowed from Perl, and has not
838      been available prior to XEmacs 20.3, nor is it available in FSF
839      Emacs.
840
841 `\w'
842      matches any word-constituent character.  The editor syntax table
843      determines which characters these are.  *Note Syntax::.
844
845 `\W'
846      matches any character that is not a word constituent.
847
848 `\sCODE'
849      matches any character whose syntax is CODE.  Here CODE is a
850      character that represents a syntax code: thus, `w' for word
851      constituent, `-' for whitespace, `(' for open parenthesis, etc.
852      *Note Syntax::, for a list of syntax codes and the characters that
853      stand for them.
854
855 `\SCODE'
856      matches any character whose syntax is not CODE.
857
858    The following regular expression constructs match the empty
859 string--that is, they don't use up any characters--but whether they
860 match depends on the context.
861
862 `\`'
863      matches the empty string, but only at the beginning of the buffer
864      or string being matched against.
865
866 `\''
867      matches the empty string, but only at the end of the buffer or
868      string being matched against.
869
870 `\='
871      matches the empty string, but only at point.  (This construct is
872      not defined when matching against a string.)
873
874 `\b'
875      matches the empty string, but only at the beginning or end of a
876      word.  Thus, `\bfoo\b' matches any occurrence of `foo' as a
877      separate word.  `\bballs?\b' matches `ball' or `balls' as a
878      separate word.
879
880 `\B'
881      matches the empty string, but _not_ at the beginning or end of a
882      word.
883
884 `\<'
885      matches the empty string, but only at the beginning of a word.
886
887 `\>'
888      matches the empty string, but only at the end of a word.
889
890    Here is a complicated regexp used by Emacs to recognize the end of a
891 sentence together with any whitespace that follows.  It is given in Lisp
892 syntax to enable you to distinguish the spaces from the tab characters.
893 In Lisp syntax, the string constant begins and ends with a
894 double-quote.  `\"' stands for a double-quote as part of the regexp,
895 `\\' for a backslash as part of the regexp, `\t' for a tab and `\n' for
896 a newline.
897
898      "[.?!][]\"')]*\\($\\|\t\\|  \\)[ \t\n]*"
899
900 This regexp contains four parts: a character set matching period, `?'
901 or `!'; a character set matching close-brackets, quotes or parentheses,
902 repeated any number of times; an alternative in backslash-parentheses
903 that matches end-of-line, a tab or two spaces; and a character set
904 matching whitespace characters, repeated any number of times.
905
906 \1f
907 File: xemacs.info,  Node: Search Case,  Next: Replace,  Prev: Regexps,  Up: Search
908
909 Searching and Case
910 ==================
911
912    All searches in Emacs normally ignore the case of the text they are
913 searching through; if you specify searching for `FOO', `Foo' and `foo'
914 are also considered a match.  Regexps, and in particular character
915 sets, are included: `[aB]' matches `a' or `A' or `b' or `B'.
916
917    If you want a case-sensitive search, set the variable
918 `case-fold-search' to `nil'.  Then all letters must match exactly,
919 including case. `case-fold-search' is a per-buffer variable; altering
920 it affects only the current buffer, but there is a default value which
921 you can change as well.  *Note Locals::.  You can also use Case
922 Sensitive Search from the Options menu on your screen.
923
924 \1f
925 File: xemacs.info,  Node: Replace,  Next: Other Repeating Search,  Prev: Search Case,  Up: Search
926
927 Replacement Commands
928 ====================
929
930    Global search-and-replace operations are not needed as often in
931 Emacs as they are in other editors, but they are available.  In
932 addition to the simple `replace-string' command which is like that
933 found in most editors, there is a `query-replace' command which asks
934 you, for each occurrence of a pattern, whether to replace it.
935
936    The replace commands all replace one string (or regexp) with one
937 replacement string.  It is possible to perform several replacements in
938 parallel using the command `expand-region-abbrevs'.  *Note Expanding
939 Abbrevs::.
940
941 * Menu:
942
943 * Unconditional Replace::  Replacing all matches for a string.
944 * Regexp Replace::         Replacing all matches for a regexp.
945 * Replacement and Case::   How replacements preserve case of letters.
946 * Query Replace::          How to use querying.
947
948 \1f
949 File: xemacs.info,  Node: Unconditional Replace,  Next: Regexp Replace,  Prev: Replace,  Up: Replace
950
951 Unconditional Replacement
952 -------------------------
953
954 `M-x replace-string <RET> STRING <RET> NEWSTRING <RET>'
955      Replace every occurrence of STRING with NEWSTRING.
956
957 `M-x replace-regexp <RET> REGEXP <RET> NEWSTRING <RET>'
958      Replace every match for REGEXP with NEWSTRING.
959
960    To replace every instance of `foo' after point with `bar', use the
961 command `M-x replace-string' with the two arguments `foo' and `bar'.
962 Replacement occurs only after point: if you want to cover the whole
963 buffer you must go to the beginning first.  By default, all occurrences
964 up to the end of the buffer are replaced.  To limit replacement to part
965 of the buffer, narrow to that part of the buffer before doing the
966 replacement (*note Narrowing::).
967
968    When `replace-string' exits, point is left at the last occurrence
969 replaced.  The value of point when the `replace-string' command was
970 issued is remembered on the mark ring; `C-u C-<SPC>' moves back there.
971
972    A numeric argument restricts replacement to matches that are
973 surrounded by word boundaries.
974
975 \1f
976 File: xemacs.info,  Node: Regexp Replace,  Next: Replacement and Case,  Prev: Unconditional Replace,  Up: Replace
977
978 Regexp Replacement
979 ------------------
980
981    `replace-string' replaces exact matches for a single string.  The
982 similar command `replace-regexp' replaces any match for a specified
983 pattern.
984
985    In `replace-regexp', the NEWSTRING need not be constant.  It can
986 refer to all or part of what is matched by the REGEXP.  `\&' in
987 NEWSTRING stands for the entire text being replaced.  `\D' in
988 NEWSTRING, where D is a digit, stands for whatever matched the D'th
989 parenthesized grouping in REGEXP.  For example,
990
991      M-x replace-regexp <RET> c[ad]+r <RET> \&-safe <RET>
992
993 would replace (for example) `cadr' with `cadr-safe' and `cddr' with
994 `cddr-safe'.
995
996      M-x replace-regexp <RET> \(c[ad]+r\)-safe <RET> \1 <RET>
997
998 would perform exactly the opposite replacements.  To include a `\' in
999 the text to replace with, you must give `\\'.
1000
1001 \1f
1002 File: xemacs.info,  Node: Replacement and Case,  Next: Query Replace,  Prev: Regexp Replace,  Up: Replace
1003
1004 Replace Commands and Case
1005 -------------------------
1006
1007    If the arguments to a replace command are in lower case, the command
1008 preserves case when it makes a replacement.  Thus, the following
1009 command:
1010
1011      M-x replace-string <RET> foo <RET> bar <RET>
1012
1013 replaces a lower-case `foo' with a lower case `bar', `FOO' with `BAR',
1014 and `Foo' with `Bar'.  If upper-case letters are used in the second
1015 argument, they remain upper-case every time that argument is inserted.
1016 If upper-case letters are used in the first argument, the second
1017 argument is always substituted exactly as given, with no case
1018 conversion.  Likewise, if the variable `case-replace' is set to `nil',
1019 replacement is done without case conversion.  If `case-fold-search' is
1020 set to `nil', case is significant in matching occurrences of `foo' to
1021 replace; also, case conversion of the replacement string is not done.
1022
1023 \1f
1024 File: xemacs.info,  Node: Query Replace,  Prev: Replacement and Case,  Up: Replace
1025
1026 Query Replace
1027 -------------
1028
1029 `M-% STRING <RET> NEWSTRING <RET>'
1030 `M-x query-replace <RET> STRING <RET> NEWSTRING <RET>'
1031      Replace some occurrences of STRING with NEWSTRING.
1032
1033 `M-x query-replace-regexp <RET> REGEXP <RET> NEWSTRING <RET>'
1034      Replace some matches for REGEXP with NEWSTRING.
1035
1036    If you want to change only some of the occurrences of `foo' to
1037 `bar', not all of them, you can use `query-replace' instead of `M-%'.
1038 This command finds occurrences of `foo' one by one, displays each
1039 occurrence, and asks you whether to replace it.  A numeric argument to
1040 `query-replace' tells it to consider only occurrences that are bounded
1041 by word-delimiter characters.
1042
1043    Aside from querying, `query-replace' works just like
1044 `replace-string', and `query-replace-regexp' works just like
1045 `replace-regexp'.
1046
1047    The things you can type when you are shown an occurrence of STRING
1048 or a match for REGEXP are:
1049
1050 `<SPC>'
1051      to replace the occurrence with NEWSTRING.  This preserves case,
1052      just like `replace-string', provided `case-replace' is non-`nil',
1053      as it normally is.
1054
1055 `<DEL>'
1056      to skip to the next occurrence without replacing this one.
1057
1058 `, (Comma)'
1059      to replace this occurrence and display the result.  You are then
1060      prompted for another input character.  However, since the
1061      replacement has already been made, <DEL> and <SPC> are equivalent.
1062      At this point, you can type `C-r' (see below) to alter the
1063      replaced text.  To undo the replacement, you can type `C-x u'.
1064      This exits the `query-replace'.  If you want to do further
1065      replacement you must use `C-x ESC' to restart (*note Repetition::).
1066
1067 `<ESC>'
1068      to exit without doing any more replacements.
1069
1070 `. (Period)'
1071      to replace this occurrence and then exit.
1072
1073 `!'
1074      to replace all remaining occurrences without asking again.
1075
1076 `^'
1077      to go back to the location of the previous occurrence (or what
1078      used to be an occurrence), in case you changed it by mistake.
1079      This works by popping the mark ring.  Only one `^' in a row is
1080      allowed, because only one previous replacement location is kept
1081      during `query-replace'.
1082
1083 `C-r'
1084      to enter a recursive editing level, in case the occurrence needs
1085      to be edited rather than just replaced with NEWSTRING.  When you
1086      are done, exit the recursive editing level with `C-M-c' and the
1087      next occurrence will be displayed.  *Note Recursive Edit::.
1088
1089 `C-w'
1090      to delete the occurrence, and then enter a recursive editing level
1091      as in `C-r'.  Use the recursive edit to insert text to replace the
1092      deleted occurrence of STRING.  When done, exit the recursive
1093      editing level with `C-M-c' and the next occurrence will be
1094      displayed.
1095
1096 `C-l'
1097      to redisplay the screen and then give another answer.
1098
1099 `C-h'
1100      to display a message summarizing these options, then give another
1101      answer.
1102
1103    If you type any other character, Emacs exits the `query-replace', and
1104 executes the character as a command.  To restart the `query-replace',
1105 use `C-x <ESC>', which repeats the `query-replace' because it used the
1106 minibuffer to read its arguments.  *Note C-x ESC: Repetition.
1107
1108 \1f
1109 File: xemacs.info,  Node: Other Repeating Search,  Prev: Replace,  Up: Search
1110
1111 Other Search-and-Loop Commands
1112 ==============================
1113
1114    Here are some other commands that find matches for a regular
1115 expression.  They all operate from point to the end of the buffer.
1116
1117 `M-x occur'
1118      Print each line that follows point and contains a match for the
1119      specified regexp.  A numeric argument specifies the number of
1120      context lines to print before and after each matching line; the
1121      default is none.
1122
1123      The buffer `*Occur*' containing the output serves as a menu for
1124      finding occurrences in their original context.  Find an occurrence
1125      as listed in `*Occur*', position point there, and type `C-c C-c';
1126      this switches to the buffer that was searched and moves point to
1127      the original of the same occurrence.
1128
1129 `M-x list-matching-lines'
1130      Synonym for `M-x occur'.
1131
1132 `M-x count-matches'
1133      Print the number of matches following point for the specified
1134      regexp.
1135
1136 `M-x delete-non-matching-lines'
1137      Delete each line that follows point and does not contain a match
1138      for the specified regexp.
1139
1140 `M-x delete-matching-lines'
1141      Delete each line that follows point and contains a match for the
1142      specified regexp.
1143
1144 \1f
1145 File: xemacs.info,  Node: Fixit,  Next: Files,  Prev: Search,  Up: Top
1146
1147 Commands for Fixing Typos
1148 *************************
1149
1150    This chapter describes commands that are especially useful when you
1151 catch a mistake in your text just after you have made it, or when you
1152 change your mind while composing text on line.
1153
1154 * Menu:
1155
1156 * Kill Errors:: Commands to kill a batch of recently entered text.
1157 * Transpose::   Exchanging two characters, words, lines, lists...
1158 * Fixing Case:: Correcting case of last word entered.
1159 * Spelling::    Apply spelling checker to a word, or a whole file.
1160
1161 \1f
1162 File: xemacs.info,  Node: Kill Errors,  Next: Transpose,  Prev: Fixit,  Up: Fixit
1163
1164 Killing Your Mistakes
1165 =====================
1166
1167 `<DEL>'
1168      Delete last character (`delete-backward-char').
1169
1170 `M-<DEL>'
1171      Kill last word (`backward-kill-word').
1172
1173 `C-x <DEL>'
1174      Kill to beginning of sentence (`backward-kill-sentence').
1175
1176    The <DEL> character (`delete-backward-char') is the most important
1177 correction command.  When used among graphic (self-inserting)
1178 characters, it can be thought of as canceling the last character typed.
1179
1180    When your mistake is longer than a couple of characters, it might be
1181 more convenient to use `M-<DEL>' or `C-x <DEL>'.  `M-<DEL>' kills back
1182 to the start of the last word, and `C-x <DEL>' kills back to the start
1183 of the last sentence.  `C-x <DEL>' is particularly useful when you are
1184 thinking of what to write as you type it, in case you change your mind
1185 about phrasing.  `M-<DEL>' and `C-x <DEL>' save the killed text for
1186 `C-y' and `M-y' to retrieve.  *Note Yanking::.
1187
1188    `M-<DEL>' is often useful even when you have typed only a few
1189 characters wrong, if you know you are confused in your typing and aren't
1190 sure exactly what you typed.  At such a time, you cannot correct with
1191 <DEL> except by looking at the screen to see what you did.  It requires
1192 less thought to kill the whole word and start over.
1193