annotate man/xemacs/search.texi @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 972bbb6d6ca2 abe6d1db359e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 @node Search, Fixit, Display, Top
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 @chapter Searching and Replacement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 @cindex searching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 Like other editors, Emacs has commands for searching for occurrences of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 a string. The principal search command is unusual in that it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 @dfn{incremental}: it begins to search before you have finished typing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 search string. There are also non-incremental search commands more like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 those of other editors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 Besides the usual @code{replace-string} command that finds all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 occurrences of one string and replaces them with another, Emacs has a fancy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 replacement command called @code{query-replace} which asks interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 which occurrences to replace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 @menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 * Incremental Search:: Search happens as you type the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 * Non-Incremental Search:: Specify entire string and then search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 * Word Search:: Search for sequence of words.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 * Regexp Search:: Search for match for a regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 * Regexps:: Syntax of regular expressions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 * Search Case:: To ignore case while searching, or not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 * Replace:: Search, and replace some or all matches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 * Other Repeating Search:: Operating on all matches for some regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 @end menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 @node Incremental Search, Non-Incremental Search, Search, Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 @section Incremental Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 An incremental search begins searching as soon as you type the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 character of the search string. As you type in the search string, Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 shows you where the string (as you have typed it so far) is found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 When you have typed enough characters to identify the place you want, you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 can stop. Depending on what you do next, you may or may not need to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 terminate the search explicitly with a @key{RET}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 @c WideCommands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 @table @kbd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 @item C-s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 Incremental search forward (@code{isearch-forward}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 @item C-r
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 Incremental search backward (@code{isearch-backward}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 @end table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 @kindex C-s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 @kindex C-r
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 @findex isearch-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 @findex isearch-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 @kbd{C-s} starts an incremental search. @kbd{C-s} reads characters from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 the keyboard and positions the cursor at the first occurrence of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 characters that you have typed. If you type @kbd{C-s} and then @kbd{F},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 the cursor moves right after the first @samp{F}. Type an @kbd{O}, and see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 the cursor move to after the first @samp{FO}. After another @kbd{O}, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 cursor is after the first @samp{FOO} after the place where you started the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 search. Meanwhile, the search string @samp{FOO} has been echoed in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 echo area.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 The echo area display ends with three dots when actual searching is going
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 on. When search is waiting for more input, the three dots are removed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (On slow terminals, the three dots are not displayed.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 If you make a mistake in typing the search string, you can erase
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 characters with @key{DEL}. Each @key{DEL} cancels the last character of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 search string. This does not happen until Emacs is ready to read another
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 input character; first it must either find, or fail to find, the character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 you want to erase. If you do not want to wait for this to happen, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 @kbd{C-g} as described below.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 When you are satisfied with the place you have reached, you can type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 @key{RET} (or @key{C-m}), which stops searching, leaving the cursor where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 the search brought it. Any command not specially meaningful in searches also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 stops the search and is then executed. Thus, typing @kbd{C-a} exits the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 search and then moves to the beginning of the line. @key{RET} is necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 only if the next command you want to type is a printing character,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 @key{DEL}, @key{ESC}, or another control character that is special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 within searches (@kbd{C-q}, @kbd{C-w}, @kbd{C-r}, @kbd{C-s}, or @kbd{C-y}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 Sometimes you search for @samp{FOO} and find it, but were actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 looking for a different occurance of it. To move to the next occurrence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 of the search string, type another @kbd{C-s}. Do this as often as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 necessary. If you overshoot, you can cancel some @kbd{C-s}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 characters with @key{DEL}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 After you exit a search, you can search for the same string again by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 typing just @kbd{C-s C-s}: the first @kbd{C-s} is the key that invokes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 incremental search, and the second @kbd{C-s} means ``search again''.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 If the specified string is not found at all, the echo area displays
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 the text @samp{Failing I-Search}. The cursor is after the place where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 Emacs found as much of your string as it could. Thus, if you search for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 @samp{FOOT}, and there is no @samp{FOOT}, the cursor may be after the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 @samp{FOO} in @samp{FOOL}. At this point there are several things you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 can do. If you mistyped the search string, correct it. If you like the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 place you have found, you can type @key{RET} or some other Emacs command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 to ``accept what the search offered''. Or you can type @kbd{C-g}, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 removes from the search string the characters that could not be found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (the @samp{T} in @samp{FOOT}), leaving those that were found (the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 @samp{FOO} in @samp{FOOT}). A second @kbd{C-g} at that point cancels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 the search entirely, returning point to where it was when the search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 started.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 If a search is failing and you ask to repeat it by typing another
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 @kbd{C-s}, it starts again from the beginning of the buffer. Repeating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 a failing backward search with @kbd{C-r} starts again from the end. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 is called @dfn{wrapping around}. @samp{Wrapped} appears in the search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 prompt once this has happened.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 @cindex quitting (in search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 The @kbd{C-g} ``quit'' character does special things during searches;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 just what it does depends on the status of the search. If the search has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 found what you specified and is waiting for input, @kbd{C-g} cancels the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 entire search. The cursor moves back to where you started the search. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 @kbd{C-g} is typed when there are characters in the search string that have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 not been found---because Emacs is still searching for them, or because it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 has failed to find them---then the search string characters which have not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 been found are discarded from the search string. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 search is now successful and waiting for more input, so a second @kbd{C-g}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 cancels the entire search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 To search for a control character such as @kbd{C-s} or @key{DEL} or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 @key{ESC}, you must quote it by typing @kbd{C-q} first. This function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 of @kbd{C-q} is analogous to its meaning as an Emacs command: it causes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 the following character to be treated the way a graphic character would
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 normally be treated in the same context.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 To search backwards, you can use @kbd{C-r} instead of @kbd{C-s} to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 start the search; @kbd{C-r} is the key that runs the command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (@code{isearch-backward}) to search backward. You can also use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 @kbd{C-r} to change from searching forward to searching backwards. Do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 this if a search fails because the place you started was too far down in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 file. Repeated @kbd{C-r} keeps looking for more occurrences backwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 @kbd{C-s} starts going forward again. You can cancel @kbd{C-r} in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 search with @key{DEL}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 The characters @kbd{C-y} and @kbd{C-w} can be used in incremental search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 to grab text from the buffer into the search string. This makes it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 convenient to search for another occurrence of text at point. @kbd{C-w}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 copies the word after point as part of the search string, advancing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 point over that word. Another @kbd{C-s} to repeat the search will then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 search for a string including that word. @kbd{C-y} is similar to @kbd{C-w}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 but copies the rest of the current line into the search string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 The characters @kbd{M-p} and @kbd{M-n} can be used in an incremental
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 search to recall things which you have searched for in the past. A
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 list of the last 16 things you have searched for is retained, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 @kbd{M-p} and @kbd{M-n} let you cycle through that ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 The character @kbd{M-@key{TAB}} does completion on the elements in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 the search history ring. For example, if you know that you have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 recently searched for the string @code{POTATOE}, you could type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 @kbd{C-s P O M-@key{TAB}}. If you had searched for other strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 beginning with @code{PO} then you would be shown a list of them, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 would need to type more to select one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 You can change any of the special characters in incremental search via
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 the normal keybinding mechanism: simply add a binding to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 @code{isearch-mode-map}. For example, to make the character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 @kbd{C-b} mean ``search backwards'' while in isearch-mode, do this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (define-key isearch-mode-map "\C-b" 'isearch-repeat-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 These are the default bindings of isearch-mode:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 @findex isearch-delete-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 @findex isearch-exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 @findex isearch-quote-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 @findex isearch-repeat-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 @findex isearch-repeat-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 @findex isearch-yank-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 @findex isearch-yank-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 @findex isearch-abort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 @findex isearch-ring-retreat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 @findex isearch-ring-advance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 @findex isearch-complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 @kindex DEL (isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 @kindex RET (isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 @kindex C-q (isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 @kindex C-s (isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 @kindex C-r (isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 @kindex C-y (isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 @kindex C-w (isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 @kindex C-g (isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 @kindex M-p (isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 @kindex M-n (isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 @kindex M-TAB (isearch-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 @table @kbd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 @item DEL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 Delete a character from the incremental search string (@code{isearch-delete-char}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 @item RET
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 Exit incremental search (@code{isearch-exit}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 @item C-q
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 Quote special characters for incremental search (@code{isearch-quote-char}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 @item C-s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 Repeat incremental search forward (@code{isearch-repeat-forward}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 @item C-r
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 Repeat incremental search backward (@code{isearch-repeat-backward}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 @item C-y
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Pull rest of line from buffer into search string (@code{isearch-yank-line}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 @item C-w
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 Pull next word from buffer into search string (@code{isearch-yank-word}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 @item C-g
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 Cancels input back to what has been found successfully, or aborts the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 isearch (@code{isearch-abort}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 @item M-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 Recall the previous element in the isearch history ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (@code{isearch-ring-retreat}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 @item M-n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 Recall the next element in the isearch history ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (@code{isearch-ring-advance}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 @item M-@key{TAB}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 Do completion on the elements in the isearch history ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (@code{isearch-complete}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 @end table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 Any other character which is normally inserted into a buffer when typed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 is automatically added to the search string in isearch-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 @subsection Slow Terminal Incremental Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 Incremental search on a slow terminal uses a modified style of display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 that is designed to take less time. Instead of redisplaying the buffer at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 each place the search gets to, it creates a new single-line window and uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 that to display the line the search has found. The single-line window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 appears as soon as point gets outside of the text that is already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 on the screen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 When the search is terminated, the single-line window is removed. Only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 at this time the window in which the search was done is redisplayed to show
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 its new value of point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 The three dots at the end of the search string, normally used to indicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 that searching is going on, are not displayed in slow style display.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 @vindex search-slow-speed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 The slow terminal style of display is used when the terminal baud rate is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 less than or equal to the value of the variable @code{search-slow-speed},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 initially 1200.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 @vindex search-slow-window-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 The number of lines to use in slow terminal search display is controlled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 by the variable @code{search-slow-window-lines}. Its normal value is 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 @node Non-Incremental Search, Word Search, Incremental Search, Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 @section Non-Incremental Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 @cindex non-incremental search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 Emacs also has conventional non-incremental search commands, which require
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 you type the entire search string before searching begins.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 @table @kbd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 @item C-s @key{RET} @var{string} @key{RET}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 Search for @var{string}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 @item C-r @key{RET} @var{string} @key{RET}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 Search backward for @var{string}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 @end table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 To do a non-incremental search, first type @kbd{C-s @key{RET}}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (or @kbd{C-s C-m}). This enters the minibuffer to read the search string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 Terminate the string with @key{RET} to start the search. If the string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 is not found, the search command gets an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 By default, @kbd{C-s} invokes incremental search, but if you give it an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 empty argument, which would otherwise be useless, it invokes non-incremental
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 search. Therefore, @kbd{C-s @key{RET}} invokes non-incremental search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 @kbd{C-r @key{RET}} also works this way.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 @findex search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 @findex search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 Forward and backward non-incremental searches are implemented by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 commands @code{search-forward} and @code{search-backward}. You can bind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 these commands to keys. The reason that incremental
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 search is programmed to invoke them as well is that @kbd{C-s @key{RET}}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 is the traditional sequence of characters used in Emacs to invoke
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 non-incremental search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 Non-incremental searches performed using @kbd{C-s @key{RET}} do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 not call @code{search-forward} right away. They first check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 if the next character is @kbd{C-w}, which requests a word search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 @ifinfo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 @xref{Word Search}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 @end ifinfo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 @node Word Search, Regexp Search, Non-Incremental Search, Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 @section Word Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 @cindex word search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 Word search looks for a sequence of words without regard to how the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 words are separated. More precisely, you type a string of many words,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 using single spaces to separate them, and the string is found even if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 there are multiple spaces, newlines or other punctuation between the words.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 Word search is useful in editing documents formatted by text formatters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 If you edit while looking at the printed, formatted version, you can't tell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 where the line breaks are in the source file. Word search, allows you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 to search without having to know the line breaks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 @table @kbd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 @item C-s @key{RET} C-w @var{words} @key{RET}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 Search for @var{words}, ignoring differences in punctuation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 @item C-r @key{RET} C-w @var{words} @key{RET}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 Search backward for @var{words}, ignoring differences in punctuation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 @end table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 Word search is a special case of non-incremental search. It is invoked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 with @kbd{C-s @key{RET} C-w} followed by the search string, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 must always be terminated with another @key{RET}. Being non-incremental, this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 search does not start until the argument is terminated. It works by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 constructing a regular expression and searching for that. @xref{Regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 Search}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 You can do a backward word search with @kbd{C-r @key{RET} C-w}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 @findex word-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 @findex word-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 Forward and backward word searches are implemented by the commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 @code{word-search-forward} and @code{word-search-backward}. You can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 bind these commands to keys. The reason that incremental
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 search is programmed to invoke them as well is that @kbd{C-s @key{RET} C-w}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 is the traditional Emacs sequence of keys for word search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 @node Regexp Search, Regexps, Word Search, Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 @section Regular Expression Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 @cindex regular expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 @cindex regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 A @dfn{regular expression} (@dfn{regexp}, for short) is a pattern that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 denotes a set of strings, possibly an infinite set. Searching for matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 for a regexp is a powerful operation that editors on Unix systems have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 traditionally offered. In XEmacs, you can search for the next match for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 a regexp either incrementally or not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 @kindex M-C-s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 @findex isearch-forward-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 @findex isearch-backward-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 Incremental search for a regexp is done by typing @kbd{M-C-s}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (@code{isearch-forward-regexp}). This command reads a search string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 incrementally just like @kbd{C-s}, but it treats the search string as a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 regexp rather than looking for an exact match against the text in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 buffer. Each time you add text to the search string, you make the regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 longer, and the new regexp is searched for. A reverse regexp search command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 @code{isearch-backward-regexp} also exists, but no key runs it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 All of the control characters that do special things within an ordinary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 incremental search have the same functionality in incremental regexp search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 Typing @kbd{C-s} or @kbd{C-r} immediately after starting a search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 retrieves the last incremental search regexp used:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 incremental regexp and non-regexp searches have independent defaults.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 @findex re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 @findex re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 Non-incremental search for a regexp is done by the functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 @code{re-search-forward} and @code{re-search-backward}. You can invoke
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 them with @kbd{M-x} or bind them to keys. You can also call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 @code{re-search-forward} by way of incremental regexp search with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 @kbd{M-C-s @key{RET}}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 @node Regexps, Search Case, Regexp Search, Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 @section Syntax of Regular Expressions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 Regular expressions have a syntax in which a few characters are special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 constructs and the rest are @dfn{ordinary}. An ordinary character is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 simple regular expression which matches that character and nothing else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 The special characters are @samp{$}, @samp{^}, @samp{.}, @samp{*},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 @samp{+}, @samp{?}, @samp{[}, @samp{]} and @samp{\}; no new special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 characters will be defined. Any other character appearing in a regular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 expression is ordinary, unless a @samp{\} precedes it.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 For example, @samp{f} is not a special character, so it is ordinary, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 therefore @samp{f} is a regular expression that matches the string @samp{f}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 and no other string. (It does @i{not} match the string @samp{ff}.) Likewise,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 @samp{o} is a regular expression that matches only @samp{o}.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 Any two regular expressions @var{a} and @var{b} can be concatenated. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 result is a regular expression which matches a string if @var{a} matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 some amount of the beginning of that string and @var{b} matches the rest of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 the string.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 As a simple example, you can concatenate the regular expressions @samp{f}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 and @samp{o} to get the regular expression @samp{fo}, which matches only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 the string @samp{fo}. To do something nontrivial, you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 need to use one of the following special characters:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 @table @kbd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 @item .@: @r{(Period)}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 is a special character that matches any single character except a newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 Using concatenation, you can make regular expressions like @samp{a.b}, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 matches any three-character string which begins with @samp{a} and ends with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 @samp{b}.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 @item *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 is not a construct by itself; it is a suffix, which means the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 preceding regular expression is to be repeated as many times as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 possible. In @samp{fo*}, the @samp{*} applies to the @samp{o}, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 @samp{fo*} matches one @samp{f} followed by any number of @samp{o}s.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 The case of zero @samp{o}s is allowed: @samp{fo*} does match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 @samp{f}.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 @samp{*} always applies to the @i{smallest} possible preceding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 expression. Thus, @samp{fo*} has a repeating @samp{o}, not a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 repeating @samp{fo}.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 The matcher processes a @samp{*} construct by immediately matching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 as many repetitions as it can find. Then it continues with the rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 of the pattern. If that fails, backtracking occurs, discarding some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 of the matches of the @samp{*}-modified construct in case that makes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 it possible to match the rest of the pattern. For example, matching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 @samp{ca*ar} against the string @samp{caaar}, the @samp{a*} first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 tries to match all three @samp{a}s; but the rest of the pattern is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 @samp{ar} and there is only @samp{r} left to match, so this try fails.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 The next alternative is for @samp{a*} to match only two @samp{a}s.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 With this choice, the rest of the regexp matches successfully.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 @item +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 is a suffix character similar to @samp{*} except that it requires that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 the preceding expression be matched at least once. For example,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 @samp{ca+r} will match the strings @samp{car} and @samp{caaaar}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 but not the string @samp{cr}, whereas @samp{ca*r} would match all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 three strings.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 @item ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 is a suffix character similar to @samp{*} except that it can match the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 preceding expression either once or not at all. For example,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 @samp{ca?r} will match @samp{car} or @samp{cr}; nothing else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 @item [ @dots{} ]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 @samp{[} begins a @dfn{character set}, which is terminated by a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 @samp{]}. In the simplest case, the characters between the two form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 the set. Thus, @samp{[ad]} matches either one @samp{a} or one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 @samp{d}, and @samp{[ad]*} matches any string composed of just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 @samp{a}s and @samp{d}s (including the empty string), from which it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 follows that @samp{c[ad]*r} matches @samp{cr}, @samp{car}, @samp{cdr},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 @samp{caddaar}, etc.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 You can include character ranges in a character set by writing two
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 characters with a @samp{-} between them. Thus, @samp{[a-z]} matches any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 lower-case letter. Ranges may be intermixed freely with individual
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 characters, as in @samp{[a-z$%.]}, which matches any lower-case letter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 or @samp{$}, @samp{%}, or period.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 @refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 Note that inside a character set the usual special characters are not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 special any more. A completely different set of special characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 exists inside character sets: @samp{]}, @samp{-}, and @samp{^}.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 To include a @samp{]} in a character set, you must make it the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 character. For example, @samp{[]a]} matches @samp{]} or @samp{a}. To
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 include a @samp{-}, write @samp{---}, which is a range containing only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 @samp{-}. To include @samp{^}, make it other than the first character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 in the set.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 @item [^ @dots{} ]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 @samp{[^} begins a @dfn{complement character set}, which matches any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 character except the ones specified. Thus, @samp{[^a-z0-9A-Z]}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 matches all characters @i{except} letters and digits.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 @samp{^} is not special in a character set unless it is the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 character. The character following the @samp{^} is treated as if it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 were first (@samp{-} and @samp{]} are not special there).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 Note that a complement character set can match a newline, unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 newline is mentioned as one of the characters not to match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 @item ^
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 is a special character that matches the empty string, but only if at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 the beginning of a line in the text being matched. Otherwise, it fails
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 to match anything. Thus, @samp{^foo} matches a @samp{foo} that occurs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 at the beginning of a line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 @item $
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 is similar to @samp{^} but matches only at the end of a line. Thus,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 @samp{xx*$} matches a string of one @samp{x} or more at the end of a line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 @item \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 does two things: it quotes the special characters (including
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 @samp{\}), and it introduces additional special constructs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 Because @samp{\} quotes special characters, @samp{\$} is a regular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 expression that matches only @samp{$}, and @samp{\[} is a regular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 expression that matches only @samp{[}, and so on.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 @end table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 Note: for historical compatibility, special characters are treated as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ordinary ones if they are in contexts where their special meanings make no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 sense. For example, @samp{*foo} treats @samp{*} as ordinary since there is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 no preceding expression on which the @samp{*} can act. It is poor practice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 to depend on this behavior; better to quote the special character anyway,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 regardless of where is appears.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 Usually, @samp{\} followed by any character matches only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 that character. However, there are several exceptions: characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 which, when preceded by @samp{\}, are special constructs. Such
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 characters are always ordinary when encountered on their own. Here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 is a table of @samp{\} constructs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 @table @kbd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 @item \|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 specifies an alternative.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 Two regular expressions @var{a} and @var{b} with @samp{\|} in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 between form an expression that matches anything @var{a} or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 @var{b} matches.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 Thus, @samp{foo\|bar} matches either @samp{foo} or @samp{bar}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 but no other string.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 @samp{\|} applies to the largest possible surrounding expressions. Only a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 surrounding @samp{\( @dots{} \)} grouping can limit the grouping power of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 @samp{\|}.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 Full backtracking capability exists to handle multiple uses of @samp{\|}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 @item \( @dots{} \)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 is a grouping construct that serves three purposes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 @enumerate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 @item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 To enclose a set of @samp{\|} alternatives for other operations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 Thus, @samp{\(foo\|bar\)x} matches either @samp{foox} or @samp{barx}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 @item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 To enclose a complicated expression for the postfix @samp{*} to operate on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 Thus, @samp{ba\(na\)*} matches @samp{bananana}, etc., with any (zero or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 more) number of @samp{na} strings.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 @item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 To mark a matched substring for future reference.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 @end enumerate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 This last application is not a consequence of the idea of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 parenthetical grouping; it is a separate feature which happens to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 assigned as a second meaning to the same @samp{\( @dots{} \)} construct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 because in practice there is no conflict between the two meanings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 Here is an explanation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 @item \@var{digit}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 after the end of a @samp{\( @dots{} \)} construct, the matcher remembers the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 beginning and end of the text matched by that construct. Then, later on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 in the regular expression, you can use @samp{\} followed by @var{digit}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 to mean ``match the same text matched the @var{digit}'th time by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 @samp{\( @dots{} \)} construct.''@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 The strings matching the first nine @samp{\( @dots{} \)} constructs appearing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 in a regular expression are assigned numbers 1 through 9 in order that the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 open-parentheses appear in the regular expression. @samp{\1} through
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 @samp{\9} may be used to refer to the text matched by the corresponding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 @samp{\( @dots{} \)} construct.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 For example, @samp{\(.*\)\1} matches any newline-free string that is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 composed of two identical halves. The @samp{\(.*\)} matches the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 half, which may be anything, but the @samp{\1} that follows must match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 the same exact text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 @item \`
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 matches the empty string, provided it is at the beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 of the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 @item \'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 matches the empty string, provided it is at the end of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 @item \b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 matches the empty string, provided it is at the beginning or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 end of a word. Thus, @samp{\bfoo\b} matches any occurrence of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 @samp{foo} as a separate word. @samp{\bballs?\b} matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 @samp{ball} or @samp{balls} as a separate word.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 @item \B
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 matches the empty string, provided it is @i{not} at the beginning or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 end of a word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 @item \<
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 matches the empty string, provided it is at the beginning of a word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 @item \>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 matches the empty string, provided it is at the end of a word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 @item \w
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 matches any word-constituent character. The editor syntax table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 determines which characters these are.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 @item \W
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 matches any character that is not a word-constituent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 @item \s@var{code}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 matches any character whose syntax is @var{code}. @var{code} is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 character which represents a syntax code: thus, @samp{w} for word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 constituent, @samp{-} for whitespace, @samp{(} for open-parenthesis,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 etc. @xref{Syntax}.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 @item \S@var{code}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 matches any character whose syntax is not @var{code}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 @end table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 Here is a complicated regexp used by Emacs to recognize the end of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 sentence together with any whitespace that follows. It is given in Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 syntax to enable you to distinguish the spaces from the tab characters. In
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 Lisp syntax, the string constant begins and ends with a double-quote.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 @samp{\"} stands for a double-quote as part of the regexp, @samp{\\} for a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 backslash as part of the regexp, @samp{\t} for a tab and @samp{\n} for a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 "[.?!][]\"')]*\\($\\|\t\\| \\)[ \t\n]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 This regexp contains four parts: a character set matching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 period, @samp{?} or @samp{!}; a character set matching close-brackets,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 quotes or parentheses, repeated any number of times; an alternative in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 backslash-parentheses that matches end-of-line, a tab or two spaces; and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 a character set matching whitespace characters, repeated any number of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 @node Search Case, Replace, Regexps, Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 @section Searching and Case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 @vindex case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 All searches in Emacs normally ignore the case of the text they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 are searching through; if you specify searching for @samp{FOO},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 @samp{Foo} and @samp{foo} are also considered a match. Regexps, and in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 particular character sets, are included: @samp{[aB]} matches @samp{a}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 or @samp{A} or @samp{b} or @samp{B}.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 If you want a case-sensitive search, set the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 @code{case-fold-search} to @code{nil}. Then all letters must match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 exactly, including case. @code{case-fold-search} is a per-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 variable; altering it affects only the current buffer, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 there is a default value which you can change as well. @xref{Locals}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 You can also use @b{Case Sensitive Search} from the @b{Options} menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 on your screen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 @node Replace, Other Repeating Search, Search Case, Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 @section Replacement Commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 @cindex replacement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 @cindex string substitution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 @cindex global substitution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 Global search-and-replace operations are not needed as often in Emacs as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 they are in other editors, but they are available. In addition to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 simple @code{replace-string} command which is like that found in most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 editors, there is a @code{query-replace} command which asks you, for each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 occurrence of a pattern, whether to replace it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 The replace commands all replace one string (or regexp) with one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 replacement string. It is possible to perform several replacements in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 parallel using the command @code{expand-region-abbrevs}. @xref{Expanding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 Abbrevs}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 @menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 * Unconditional Replace:: Replacing all matches for a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 * Regexp Replace:: Replacing all matches for a regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 * Replacement and Case:: How replacements preserve case of letters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 * Query Replace:: How to use querying.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 @end menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 @node Unconditional Replace, Regexp Replace, Replace, Replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 @subsection Unconditional Replacement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 @findex replace-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 @findex replace-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 @table @kbd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 @item M-x replace-string @key{RET} @var{string} @key{RET} @var{newstring} @key{RET}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 Replace every occurrence of @var{string} with @var{newstring}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 @item M-x replace-regexp @key{RET} @var{regexp} @key{RET} @var{newstring} @key{RET}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 Replace every match for @var{regexp} with @var{newstring}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 @end table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 To replace every instance of @samp{foo} after point with @samp{bar},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 use the command @kbd{M-x replace-string} with the two arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 @samp{foo} and @samp{bar}. Replacement occurs only after point: if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 want to cover the whole buffer you must go to the beginning first. By
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 default, all occurrences up to the end of the buffer are replaced. To
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 limit replacement to part of the buffer, narrow to that part of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 buffer before doing the replacement (@pxref{Narrowing}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 When @code{replace-string} exits, point is left at the last occurrence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 replaced. The value of point when the @code{replace-string} command was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 issued is remembered on the mark ring; @kbd{C-u C-@key{SPC}} moves back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 A numeric argument restricts replacement to matches that are surrounded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 by word boundaries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 @node Regexp Replace, Replacement and Case, Unconditional Replace, Replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 @subsection Regexp Replacement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 @code{replace-string} replaces exact matches for a single string. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 similar command @code{replace-regexp} replaces any match for a specified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 pattern.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 In @code{replace-regexp}, the @var{newstring} need not be constant. It
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 can refer to all or part of what is matched by the @var{regexp}. @samp{\&}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 in @var{newstring} stands for the entire text being replaced.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 @samp{\@var{d}} in @var{newstring}, where @var{d} is a digit, stands for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 whatever matched the @var{d}'th parenthesized grouping in @var{regexp}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 For example,@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 M-x replace-regexp @key{RET} c[ad]+r @key{RET} \&-safe @key{RET}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 would replace (for example) @samp{cadr} with @samp{cadr-safe} and @samp{cddr}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 with @samp{cddr-safe}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 M-x replace-regexp @key{RET} \(c[ad]+r\)-safe @key{RET} \1 @key{RET}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 would perform exactly the opposite replacements. To include a @samp{\}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 in the text to replace with, you must give @samp{\\}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 @node Replacement and Case, Query Replace, Regexp Replace, Replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 @subsection Replace Commands and Case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 @vindex case-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 @vindex case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 If the arguments to a replace command are in lower case, the command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 preserves case when it makes a replacement. Thus, the following command:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 M-x replace-string @key{RET} foo @key{RET} bar @key{RET}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 replaces a lower-case @samp{foo} with a lower case @samp{bar}, @samp{FOO}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 with @samp{BAR}, and @samp{Foo} with @samp{Bar}. If upper-case letters are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 used in the second argument, they remain upper-case every time that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 argument is inserted. If upper-case letters are used in the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 argument, the second argument is always substituted exactly as given, with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 no case conversion. Likewise, if the variable @code{case-replace} is set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 to @code{nil}, replacement is done without case conversion. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 @code{case-fold-search} is set to @code{nil}, case is significant in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 matching occurrences of @samp{foo} to replace; also, case conversion of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 replacement string is not done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 @node Query Replace,, Replacement and Case, Replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 @subsection Query Replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 @cindex query replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 @table @kbd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 @item M-% @var{string} @key{RET} @var{newstring} @key{RET}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 @itemx M-x query-replace @key{RET} @var{string} @key{RET} @var{newstring} @key{RET}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 Replace some occurrences of @var{string} with @var{newstring}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 @item M-x query-replace-regexp @key{RET} @var{regexp} @key{RET} @var{newstring} @key{RET}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 Replace some matches for @var{regexp} with @var{newstring}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 @end table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 @kindex M-%
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 @findex query-replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 If you want to change only some of the occurrences of @samp{foo} to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 @samp{bar}, not all of them, you can use @code{query-replace} instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 @kbd{M-%}. This command finds occurrences of @samp{foo} one by one,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 displays each occurrence, and asks you whether to replace it. A numeric
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 argument to @code{query-replace} tells it to consider only occurrences
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 that are bounded by word-delimiter characters.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 @findex query-replace-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 Aside from querying, @code{query-replace} works just like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 @code{replace-string}, and @code{query-replace-regexp} works
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 just like @code{replace-regexp}.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 The things you can type when you are shown an occurrence of @var{string}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 or a match for @var{regexp} are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 @kindex SPC (query-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 @kindex DEL (query-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 @kindex , (query-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 @kindex ESC (query-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 @kindex . (query-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 @kindex ! (query-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 @kindex ^ (query-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 @kindex C-r (query-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 @kindex C-w (query-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 @kindex C-l (query-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 @c WideCommands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 @table @kbd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 @item @key{SPC}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 to replace the occurrence with @var{newstring}. This preserves case, just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 like @code{replace-string}, provided @code{case-replace} is non-@code{nil},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 as it normally is.@refill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 @item @key{DEL}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 to skip to the next occurrence without replacing this one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 @item , @r{(Comma)}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 to replace this occurrence and display the result. You are then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 prompted for another input character. However, since the replacement has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 already been made, @key{DEL} and @key{SPC} are equivalent. At this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 point, you can type @kbd{C-r} (see below) to alter the replaced text. To
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 undo the replacement, you can type @kbd{C-x u}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 This exits the @code{query-replace}. If you want to do further
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 replacement you must use @kbd{C-x ESC} to restart (@pxref{Repetition}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 @item @key{ESC}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 to exit without doing any more replacements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 @item .@: @r{(Period)}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 to replace this occurrence and then exit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 @item !
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 to replace all remaining occurrences without asking again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 @item ^
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 to go back to the location of the previous occurrence (or what used to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 be an occurrence), in case you changed it by mistake. This works by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 popping the mark ring. Only one @kbd{^} in a row is allowed, because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 only one previous replacement location is kept during @code{query-replace}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 @item C-r
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 to enter a recursive editing level, in case the occurrence needs to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 edited rather than just replaced with @var{newstring}. When you are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 done, exit the recursive editing level with @kbd{C-M-c} and the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 occurrence will be displayed. @xref{Recursive Edit}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 @item C-w
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 to delete the occurrence, and then enter a recursive editing level as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 in @kbd{C-r}. Use the recursive edit to insert text to replace the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 deleted occurrence of @var{string}. When done, exit the recursive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 editing level with @kbd{C-M-c} and the next occurrence will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 @item C-l
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 to redisplay the screen and then give another answer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 @item C-h
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 to display a message summarizing these options, then give another
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 answer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 @end table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 If you type any other character, Emacs exits the @code{query-replace}, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 executes the character as a command. To restart the @code{query-replace},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 use @kbd{C-x @key{ESC}}, which repeats the @code{query-replace} because it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 used the minibuffer to read its arguments. @xref{Repetition, C-x ESC}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 @node Other Repeating Search,, Replace, Search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 @section Other Search-and-Loop Commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 Here are some other commands that find matches for a regular expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 They all operate from point to the end of the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 @findex list-matching-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 @findex occur
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 @findex count-matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 @findex delete-non-matching-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 @findex delete-matching-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 @c grosscommands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 @table @kbd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 @item M-x occur
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 Print each line that follows point and contains a match for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 specified regexp. A numeric argument specifies the number of context
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 lines to print before and after each matching line; the default is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 @kindex C-c C-c (Occur mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 The buffer @samp{*Occur*} containing the output serves as a menu for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 finding occurrences in their original context. Find an occurrence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 as listed in @samp{*Occur*}, position point there, and type @kbd{C-c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 C-c}; this switches to the buffer that was searched and moves point to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 the original of the same occurrence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 @item M-x list-matching-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 Synonym for @kbd{M-x occur}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 @item M-x count-matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 Print the number of matches following point for the specified regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 @item M-x delete-non-matching-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 Delete each line that follows point and does not contain a match for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 the specified regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 @item M-x delete-matching-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 Delete each line that follows point and contains a match for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 specified regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 @end table