diff options
| author | Richard M. Stallman | 2005-08-29 08:44:20 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2005-08-29 08:44:20 +0000 |
| commit | 99543e8b33e5914918a8caa9b1c5b5cf5400c57b (patch) | |
| tree | 0047f0ade76a9cb16f6aa9f651c87965ddc59f09 /lispref | |
| parent | f215a1b4dd7d8fa4d13084b288c1b4859b008c7f (diff) | |
| download | emacs-99543e8b33e5914918a8caa9b1c5b5cf5400c57b.tar.gz emacs-99543e8b33e5914918a8caa9b1c5b5cf5400c57b.zip | |
(Searching and Matching): Move node.
Rearrange contents and add overall explanation.
(Searching and Case): Move node.
(Searching and Matching): Update menu.
Diffstat (limited to 'lispref')
| -rw-r--r-- | lispref/searching.texi | 458 |
1 files changed, 196 insertions, 262 deletions
diff --git a/lispref/searching.texi b/lispref/searching.texi index e702469a14b..84de54984ae 100644 --- a/lispref/searching.texi +++ b/lispref/searching.texi | |||
| @@ -16,13 +16,13 @@ portions of it. | |||
| 16 | 16 | ||
| 17 | @menu | 17 | @menu |
| 18 | * String Search:: Search for an exact match. | 18 | * String Search:: Search for an exact match. |
| 19 | * Searching and Case:: Case-independent or case-significant searching. | ||
| 19 | * Regular Expressions:: Describing classes of strings. | 20 | * Regular Expressions:: Describing classes of strings. |
| 20 | * Regexp Search:: Searching for a match for a regexp. | 21 | * Regexp Search:: Searching for a match for a regexp. |
| 21 | * POSIX Regexps:: Searching POSIX-style for the longest match. | 22 | * POSIX Regexps:: Searching POSIX-style for the longest match. |
| 22 | * Search and Replace:: Internals of @code{query-replace}. | ||
| 23 | * Match Data:: Finding out which part of the text matched, | 23 | * Match Data:: Finding out which part of the text matched, |
| 24 | after a string or regexp search. | 24 | after a string or regexp search. |
| 25 | * Searching and Case:: Case-independent or case-significant searching. | 25 | * Search and Replace:: Commands that loop, searching and replacing. |
| 26 | * Standard Regexps:: Useful regexps for finding sentences, pages,... | 26 | * Standard Regexps:: Useful regexps for finding sentences, pages,... |
| 27 | @end menu | 27 | @end menu |
| 28 | 28 | ||
| @@ -157,6 +157,53 @@ except that it searches backward and normally leaves point at the | |||
| 157 | beginning of the match. | 157 | beginning of the match. |
| 158 | @end deffn | 158 | @end deffn |
| 159 | 159 | ||
| 160 | @node Searching and Case | ||
| 161 | @section Searching and Case | ||
| 162 | @cindex searching and case | ||
| 163 | |||
| 164 | By default, searches in Emacs ignore the case of the text they are | ||
| 165 | searching through; if you specify searching for @samp{FOO}, then | ||
| 166 | @samp{Foo} or @samp{foo} is also considered a match. This applies to | ||
| 167 | regular expressions, too; thus, @samp{[aB]} would match @samp{a} or | ||
| 168 | @samp{A} or @samp{b} or @samp{B}. | ||
| 169 | |||
| 170 | If you do not want this feature, set the variable | ||
| 171 | @code{case-fold-search} to @code{nil}. Then all letters must match | ||
| 172 | exactly, including case. This is a buffer-local variable; altering the | ||
| 173 | variable affects only the current buffer. (@xref{Intro to | ||
| 174 | Buffer-Local}.) Alternatively, you may change the value of | ||
| 175 | @code{default-case-fold-search}, which is the default value of | ||
| 176 | @code{case-fold-search} for buffers that do not override it. | ||
| 177 | |||
| 178 | Note that the user-level incremental search feature handles case | ||
| 179 | distinctions differently. When given a lower case letter, it looks for | ||
| 180 | a match of either case, but when given an upper case letter, it looks | ||
| 181 | for an upper case letter only. But this has nothing to do with the | ||
| 182 | searching functions used in Lisp code. | ||
| 183 | |||
| 184 | @defopt case-replace | ||
| 185 | This variable determines whether the higher level replacement | ||
| 186 | functions should preserve case. If the variable is @code{nil}, that | ||
| 187 | means to use the replacement text verbatim. A non-@code{nil} value | ||
| 188 | means to convert the case of the replacement text according to the | ||
| 189 | text being replaced. | ||
| 190 | |||
| 191 | This variable is used by passing it as an argument to the function | ||
| 192 | @code{replace-match}. @xref{Replacing Match}. | ||
| 193 | @end defopt | ||
| 194 | |||
| 195 | @defopt case-fold-search | ||
| 196 | This buffer-local variable determines whether searches should ignore | ||
| 197 | case. If the variable is @code{nil} they do not ignore case; otherwise | ||
| 198 | they do ignore case. | ||
| 199 | @end defopt | ||
| 200 | |||
| 201 | @defvar default-case-fold-search | ||
| 202 | The value of this variable is the default value for | ||
| 203 | @code{case-fold-search} in buffers that do not override it. This is the | ||
| 204 | same as @code{(default-value 'case-fold-search)}. | ||
| 205 | @end defvar | ||
| 206 | |||
| 160 | @node Regular Expressions | 207 | @node Regular Expressions |
| 161 | @section Regular Expressions | 208 | @section Regular Expressions |
| 162 | @cindex regular expression | 209 | @cindex regular expression |
| @@ -1070,231 +1117,15 @@ backtracking specified by the POSIX standard for regular expression | |||
| 1070 | matching. | 1117 | matching. |
| 1071 | @end defun | 1118 | @end defun |
| 1072 | 1119 | ||
| 1073 | @ignore | ||
| 1074 | @deffn Command delete-matching-lines regexp | ||
| 1075 | This function is identical to @code{delete-non-matching-lines}, save | ||
| 1076 | that it deletes what @code{delete-non-matching-lines} keeps. | ||
| 1077 | |||
| 1078 | In the example below, point is located on the first line of text. | ||
| 1079 | |||
| 1080 | @example | ||
| 1081 | @group | ||
| 1082 | ---------- Buffer: foo ---------- | ||
| 1083 | We hold these truths | ||
| 1084 | to be self-evident, | ||
| 1085 | that all men are created | ||
| 1086 | equal, and that they are | ||
| 1087 | ---------- Buffer: foo ---------- | ||
| 1088 | @end group | ||
| 1089 | |||
| 1090 | @group | ||
| 1091 | (delete-matching-lines "the") | ||
| 1092 | @result{} nil | ||
| 1093 | |||
| 1094 | ---------- Buffer: foo ---------- | ||
| 1095 | to be self-evident, | ||
| 1096 | that all men are created | ||
| 1097 | ---------- Buffer: foo ---------- | ||
| 1098 | @end group | ||
| 1099 | @end example | ||
| 1100 | @end deffn | ||
| 1101 | |||
| 1102 | @deffn Command flush-lines regexp | ||
| 1103 | This function is the same as @code{delete-matching-lines}. | ||
| 1104 | @end deffn | ||
| 1105 | |||
| 1106 | @defun delete-non-matching-lines regexp | ||
| 1107 | This function deletes all lines following point which don't | ||
| 1108 | contain a match for the regular expression @var{regexp}. | ||
| 1109 | @end defun | ||
| 1110 | |||
| 1111 | @deffn Command keep-lines regexp | ||
| 1112 | This function is the same as @code{delete-non-matching-lines}. | ||
| 1113 | @end deffn | ||
| 1114 | |||
| 1115 | @deffn Command how-many regexp | ||
| 1116 | This function counts the number of matches for @var{regexp} there are in | ||
| 1117 | the current buffer following point. It prints this number in | ||
| 1118 | the echo area, returning the string printed. | ||
| 1119 | @end deffn | ||
| 1120 | |||
| 1121 | @deffn Command count-matches regexp | ||
| 1122 | This function is a synonym of @code{how-many}. | ||
| 1123 | @end deffn | ||
| 1124 | |||
| 1125 | @deffn Command list-matching-lines regexp &optional nlines | ||
| 1126 | This function is a synonym of @code{occur}. | ||
| 1127 | Show all lines following point containing a match for @var{regexp}. | ||
| 1128 | Display each line with @var{nlines} lines before and after, | ||
| 1129 | or @code{-}@var{nlines} before if @var{nlines} is negative. | ||
| 1130 | @var{nlines} defaults to @code{list-matching-lines-default-context-lines}. | ||
| 1131 | Interactively it is the prefix arg. | ||
| 1132 | |||
| 1133 | The lines are shown in a buffer named @samp{*Occur*}. | ||
| 1134 | It serves as a menu to find any of the occurrences in this buffer. | ||
| 1135 | @kbd{C-h m} (@code{describe-mode}) in that buffer gives help. | ||
| 1136 | @end deffn | ||
| 1137 | |||
| 1138 | @defopt list-matching-lines-default-context-lines | ||
| 1139 | Default value is 0. | ||
| 1140 | Default number of context lines to include around a @code{list-matching-lines} | ||
| 1141 | match. A negative number means to include that many lines before the match. | ||
| 1142 | A positive number means to include that many lines both before and after. | ||
| 1143 | @end defopt | ||
| 1144 | @end ignore | ||
| 1145 | |||
| 1146 | @node Search and Replace | ||
| 1147 | @section Search and Replace | ||
| 1148 | @cindex replacement | ||
| 1149 | |||
| 1150 | @defun replace-regexp-in-string regexp rep string &optional fixedcase literal subexp start | ||
| 1151 | This function copies @var{string} and searches it for matches for | ||
| 1152 | @var{regexp}, and replaces them with @var{rep}. It returns the | ||
| 1153 | modified copy. If @var{start} is non-@code{nil}, the search for | ||
| 1154 | matches starts at that index in @var{string}, so matches starting | ||
| 1155 | before that index are not changed. | ||
| 1156 | |||
| 1157 | This function uses @code{replace-match} to do the replacement, and it | ||
| 1158 | passes the optional arguments @var{fixedcase}, @var{literal} and | ||
| 1159 | @var{subexp} along to @code{replace-match}. | ||
| 1160 | |||
| 1161 | Instead of a string, @var{rep} can be a function. In that case, | ||
| 1162 | @code{replace-regexp-in-string} calls @var{rep} for each match, | ||
| 1163 | passing the text of the match as its sole argument. It collects the | ||
| 1164 | value @var{rep} returns and passes that to @code{replace-match} as the | ||
| 1165 | replacement string. The match-data at this point are the result | ||
| 1166 | of matching @var{regexp} against a substring of @var{string}. | ||
| 1167 | @end defun | ||
| 1168 | |||
| 1169 | @defun perform-replace from-string replacements query-flag regexp-flag delimited-flag &optional repeat-count map start end | ||
| 1170 | This function is the guts of @code{query-replace} and related | ||
| 1171 | commands. It searches for occurrences of @var{from-string} in the | ||
| 1172 | text between positions @var{start} and @var{end} and replaces some or | ||
| 1173 | all of them. If @var{start} is @code{nil} (or omitted), point is used | ||
| 1174 | instead, and the end of the buffer's accessible portion is used for | ||
| 1175 | @var{end}. | ||
| 1176 | |||
| 1177 | If @var{query-flag} is @code{nil}, it replaces all | ||
| 1178 | occurrences; otherwise, it asks the user what to do about each one. | ||
| 1179 | |||
| 1180 | If @var{regexp-flag} is non-@code{nil}, then @var{from-string} is | ||
| 1181 | considered a regular expression; otherwise, it must match literally. If | ||
| 1182 | @var{delimited-flag} is non-@code{nil}, then only replacements | ||
| 1183 | surrounded by word boundaries are considered. | ||
| 1184 | |||
| 1185 | The argument @var{replacements} specifies what to replace occurrences | ||
| 1186 | with. If it is a string, that string is used. It can also be a list of | ||
| 1187 | strings, to be used in cyclic order. | ||
| 1188 | |||
| 1189 | If @var{replacements} is a cons cell, @code{(@var{function} | ||
| 1190 | . @var{data})}, this means to call @var{function} after each match to | ||
| 1191 | get the replacement text. This function is called with two arguments: | ||
| 1192 | @var{data}, and the number of replacements already made. | ||
| 1193 | |||
| 1194 | If @var{repeat-count} is non-@code{nil}, it should be an integer. Then | ||
| 1195 | it specifies how many times to use each of the strings in the | ||
| 1196 | @var{replacements} list before advancing cyclically to the next one. | ||
| 1197 | |||
| 1198 | If @var{from-string} contains upper-case letters, then | ||
| 1199 | @code{perform-replace} binds @code{case-fold-search} to @code{nil}, and | ||
| 1200 | it uses the @code{replacements} without altering the case of them. | ||
| 1201 | |||
| 1202 | Normally, the keymap @code{query-replace-map} defines the possible user | ||
| 1203 | responses for queries. The argument @var{map}, if non-@code{nil}, is a | ||
| 1204 | keymap to use instead of @code{query-replace-map}. | ||
| 1205 | |||
| 1206 | @strong{Usage note:} Do not use this function in your own programs | ||
| 1207 | unless you want to do something very similar to what | ||
| 1208 | @code{query-replace} does, including setting the mark and possibly | ||
| 1209 | querying the user. For most purposes a simple loop like, for | ||
| 1210 | instance: | ||
| 1211 | |||
| 1212 | @example | ||
| 1213 | (while (re-search-forward "foo[ \t]+bar" nil t) | ||
| 1214 | (replace-match "foobar")) | ||
| 1215 | @end example | ||
| 1216 | |||
| 1217 | @noindent | ||
| 1218 | is preferable. It runs faster and avoids side effects, such as | ||
| 1219 | setting the mark. @xref{Replacing Match,, Replacing the Text that | ||
| 1220 | Matched}, for a description of @code{replace-match}. | ||
| 1221 | @end defun | ||
| 1222 | |||
| 1223 | @defvar query-replace-map | ||
| 1224 | This variable holds a special keymap that defines the valid user | ||
| 1225 | responses for @code{query-replace} and related functions, as well as | ||
| 1226 | @code{y-or-n-p} and @code{map-y-or-n-p}. It is unusual in two ways: | ||
| 1227 | |||
| 1228 | @itemize @bullet | ||
| 1229 | @item | ||
| 1230 | The ``key bindings'' are not commands, just symbols that are meaningful | ||
| 1231 | to the functions that use this map. | ||
| 1232 | |||
| 1233 | @item | ||
| 1234 | Prefix keys are not supported; each key binding must be for a | ||
| 1235 | single-event key sequence. This is because the functions don't use | ||
| 1236 | @code{read-key-sequence} to get the input; instead, they read a single | ||
| 1237 | event and look it up ``by hand.'' | ||
| 1238 | @end itemize | ||
| 1239 | @end defvar | ||
| 1240 | |||
| 1241 | Here are the meaningful ``bindings'' for @code{query-replace-map}. | ||
| 1242 | Several of them are meaningful only for @code{query-replace} and | ||
| 1243 | friends. | ||
| 1244 | |||
| 1245 | @table @code | ||
| 1246 | @item act | ||
| 1247 | Do take the action being considered---in other words, ``yes.'' | ||
| 1248 | |||
| 1249 | @item skip | ||
| 1250 | Do not take action for this question---in other words, ``no.'' | ||
| 1251 | |||
| 1252 | @item exit | ||
| 1253 | Answer this question ``no,'' and give up on the entire series of | ||
| 1254 | questions, assuming that the answers will be ``no.'' | ||
| 1255 | |||
| 1256 | @item act-and-exit | ||
| 1257 | Answer this question ``yes,'' and give up on the entire series of | ||
| 1258 | questions, assuming that subsequent answers will be ``no.'' | ||
| 1259 | |||
| 1260 | @item act-and-show | ||
| 1261 | Answer this question ``yes,'' but show the results---don't advance yet | ||
| 1262 | to the next question. | ||
| 1263 | |||
| 1264 | @item automatic | ||
| 1265 | Answer this question and all subsequent questions in the series with | ||
| 1266 | ``yes,'' without further user interaction. | ||
| 1267 | |||
| 1268 | @item backup | ||
| 1269 | Move back to the previous place that a question was asked about. | ||
| 1270 | |||
| 1271 | @item edit | ||
| 1272 | Enter a recursive edit to deal with this question---instead of any | ||
| 1273 | other action that would normally be taken. | ||
| 1274 | |||
| 1275 | @item delete-and-edit | ||
| 1276 | Delete the text being considered, then enter a recursive edit to replace | ||
| 1277 | it. | ||
| 1278 | |||
| 1279 | @item recenter | ||
| 1280 | Redisplay and center the window, then ask the same question again. | ||
| 1281 | |||
| 1282 | @item quit | ||
| 1283 | Perform a quit right away. Only @code{y-or-n-p} and related functions | ||
| 1284 | use this answer. | ||
| 1285 | |||
| 1286 | @item help | ||
| 1287 | Display some help, then ask again. | ||
| 1288 | @end table | ||
| 1289 | |||
| 1290 | @node Match Data | 1120 | @node Match Data |
| 1291 | @section The Match Data | 1121 | @section The Match Data |
| 1292 | @cindex match data | 1122 | @cindex match data |
| 1293 | 1123 | ||
| 1294 | Emacs keeps track of the start and end positions of the segments of | 1124 | Emacs keeps track of the start and end positions of the segments of |
| 1295 | text found during a search. This means, for example, that you can | 1125 | text found during a search; this is called the @dfn{match data}. |
| 1296 | search for a complex pattern, such as a date in an Rmail message, and | 1126 | Thanks to the match data, you can search for a complex pattern, such |
| 1297 | then extract parts of the match under control of the pattern. | 1127 | as a date in a mail message, and then extract parts of the match under |
| 1128 | control of the pattern. | ||
| 1298 | 1129 | ||
| 1299 | Because the match data normally describe the most recent search only, | 1130 | Because the match data normally describe the most recent search only, |
| 1300 | you must be careful not to do another search inadvertently between the | 1131 | you must be careful not to do another search inadvertently between the |
| @@ -1313,8 +1144,8 @@ match data around it, to prevent it from being overwritten. | |||
| 1313 | @node Replacing Match | 1144 | @node Replacing Match |
| 1314 | @subsection Replacing the Text that Matched | 1145 | @subsection Replacing the Text that Matched |
| 1315 | 1146 | ||
| 1316 | This function replaces the text matched by the last search with | 1147 | This function replaces all or part of the text matched by the last |
| 1317 | @var{replacement}. | 1148 | search. It works by means of the match data. |
| 1318 | 1149 | ||
| 1319 | @cindex case in replacements | 1150 | @cindex case in replacements |
| 1320 | @defun replace-match replacement &optional fixedcase literal string subexp | 1151 | @defun replace-match replacement &optional fixedcase literal string subexp |
| @@ -1661,53 +1492,156 @@ associated with it still exists. | |||
| 1661 | @end smallexample | 1492 | @end smallexample |
| 1662 | @end ignore | 1493 | @end ignore |
| 1663 | 1494 | ||
| 1664 | @node Searching and Case | 1495 | @node Search and Replace |
| 1665 | @section Searching and Case | 1496 | @section Search and Replace |
| 1666 | @cindex searching and case | 1497 | @cindex replacement |
| 1667 | 1498 | ||
| 1668 | By default, searches in Emacs ignore the case of the text they are | 1499 | If you want to find all matches for a regexp in part of the buffer, |
| 1669 | searching through; if you specify searching for @samp{FOO}, then | 1500 | and replace them, the best way is to write an explicit loop using |
| 1670 | @samp{Foo} or @samp{foo} is also considered a match. This applies to | 1501 | @code{re-search-forward} and @code{replace-match}, like this: |
| 1671 | regular expressions, too; thus, @samp{[aB]} would match @samp{a} or | ||
| 1672 | @samp{A} or @samp{b} or @samp{B}. | ||
| 1673 | 1502 | ||
| 1674 | If you do not want this feature, set the variable | 1503 | @example |
| 1675 | @code{case-fold-search} to @code{nil}. Then all letters must match | 1504 | (while (re-search-forward "foo[ \t]+bar" nil t) |
| 1676 | exactly, including case. This is a buffer-local variable; altering the | 1505 | (replace-match "foobar")) |
| 1677 | variable affects only the current buffer. (@xref{Intro to | 1506 | @end example |
| 1678 | Buffer-Local}.) Alternatively, you may change the value of | ||
| 1679 | @code{default-case-fold-search}, which is the default value of | ||
| 1680 | @code{case-fold-search} for buffers that do not override it. | ||
| 1681 | 1507 | ||
| 1682 | Note that the user-level incremental search feature handles case | 1508 | @noindent |
| 1683 | distinctions differently. When given a lower case letter, it looks for | 1509 | @xref{Replacing Match,, Replacing the Text that Matched}, for a |
| 1684 | a match of either case, but when given an upper case letter, it looks | 1510 | description of @code{replace-match}. |
| 1685 | for an upper case letter only. But this has nothing to do with the | ||
| 1686 | searching functions used in Lisp code. | ||
| 1687 | 1511 | ||
| 1688 | @defopt case-replace | 1512 | However, replacing matches in a string is more complex, especially |
| 1689 | This variable determines whether the higher level replacement | 1513 | if you want to do it efficiently. So Emacs provides a function to do |
| 1690 | functions should preserve case. If the variable is @code{nil}, that | 1514 | this. |
| 1691 | means to use the replacement text verbatim. A non-@code{nil} value | ||
| 1692 | means to convert the case of the replacement text according to the | ||
| 1693 | text being replaced. | ||
| 1694 | 1515 | ||
| 1695 | This variable is used by passing it as an argument to the function | 1516 | @defun replace-regexp-in-string regexp rep string &optional fixedcase literal subexp start |
| 1696 | @code{replace-match}. @xref{Replacing Match}. | 1517 | This function copies @var{string} and searches it for matches for |
| 1697 | @end defopt | 1518 | @var{regexp}, and replaces them with @var{rep}. It returns the |
| 1519 | modified copy. If @var{start} is non-@code{nil}, the search for | ||
| 1520 | matches starts at that index in @var{string}, so matches starting | ||
| 1521 | before that index are not changed. | ||
| 1698 | 1522 | ||
| 1699 | @defopt case-fold-search | 1523 | This function uses @code{replace-match} to do the replacement, and it |
| 1700 | This buffer-local variable determines whether searches should ignore | 1524 | passes the optional arguments @var{fixedcase}, @var{literal} and |
| 1701 | case. If the variable is @code{nil} they do not ignore case; otherwise | 1525 | @var{subexp} along to @code{replace-match}. |
| 1702 | they do ignore case. | ||
| 1703 | @end defopt | ||
| 1704 | 1526 | ||
| 1705 | @defvar default-case-fold-search | 1527 | Instead of a string, @var{rep} can be a function. In that case, |
| 1706 | The value of this variable is the default value for | 1528 | @code{replace-regexp-in-string} calls @var{rep} for each match, |
| 1707 | @code{case-fold-search} in buffers that do not override it. This is the | 1529 | passing the text of the match as its sole argument. It collects the |
| 1708 | same as @code{(default-value 'case-fold-search)}. | 1530 | value @var{rep} returns and passes that to @code{replace-match} as the |
| 1531 | replacement string. The match-data at this point are the result | ||
| 1532 | of matching @var{regexp} against a substring of @var{string}. | ||
| 1533 | @end defun | ||
| 1534 | |||
| 1535 | If you want to write a command along the lines of @code{query-replace}, | ||
| 1536 | you can use @code{perform-replace} to do the work. | ||
| 1537 | |||
| 1538 | @defun perform-replace from-string replacements query-flag regexp-flag delimited-flag &optional repeat-count map start end | ||
| 1539 | This function is the guts of @code{query-replace} and related | ||
| 1540 | commands. It searches for occurrences of @var{from-string} in the | ||
| 1541 | text between positions @var{start} and @var{end} and replaces some or | ||
| 1542 | all of them. If @var{start} is @code{nil} (or omitted), point is used | ||
| 1543 | instead, and the end of the buffer's accessible portion is used for | ||
| 1544 | @var{end}. | ||
| 1545 | |||
| 1546 | If @var{query-flag} is @code{nil}, it replaces all | ||
| 1547 | occurrences; otherwise, it asks the user what to do about each one. | ||
| 1548 | |||
| 1549 | If @var{regexp-flag} is non-@code{nil}, then @var{from-string} is | ||
| 1550 | considered a regular expression; otherwise, it must match literally. If | ||
| 1551 | @var{delimited-flag} is non-@code{nil}, then only replacements | ||
| 1552 | surrounded by word boundaries are considered. | ||
| 1553 | |||
| 1554 | The argument @var{replacements} specifies what to replace occurrences | ||
| 1555 | with. If it is a string, that string is used. It can also be a list of | ||
| 1556 | strings, to be used in cyclic order. | ||
| 1557 | |||
| 1558 | If @var{replacements} is a cons cell, @code{(@var{function} | ||
| 1559 | . @var{data})}, this means to call @var{function} after each match to | ||
| 1560 | get the replacement text. This function is called with two arguments: | ||
| 1561 | @var{data}, and the number of replacements already made. | ||
| 1562 | |||
| 1563 | If @var{repeat-count} is non-@code{nil}, it should be an integer. Then | ||
| 1564 | it specifies how many times to use each of the strings in the | ||
| 1565 | @var{replacements} list before advancing cyclically to the next one. | ||
| 1566 | |||
| 1567 | If @var{from-string} contains upper-case letters, then | ||
| 1568 | @code{perform-replace} binds @code{case-fold-search} to @code{nil}, and | ||
| 1569 | it uses the @code{replacements} without altering the case of them. | ||
| 1570 | |||
| 1571 | Normally, the keymap @code{query-replace-map} defines the possible | ||
| 1572 | user responses for queries. The argument @var{map}, if | ||
| 1573 | non-@code{nil}, specifies a keymap to use instead of | ||
| 1574 | @code{query-replace-map}. | ||
| 1575 | @end defun | ||
| 1576 | |||
| 1577 | @defvar query-replace-map | ||
| 1578 | This variable holds a special keymap that defines the valid user | ||
| 1579 | responses for @code{perform-replace} and the commands that use it, as | ||
| 1580 | well as @code{y-or-n-p} and @code{map-y-or-n-p}. This map is unusual | ||
| 1581 | in two ways: | ||
| 1582 | |||
| 1583 | @itemize @bullet | ||
| 1584 | @item | ||
| 1585 | The ``key bindings'' are not commands, just symbols that are meaningful | ||
| 1586 | to the functions that use this map. | ||
| 1587 | |||
| 1588 | @item | ||
| 1589 | Prefix keys are not supported; each key binding must be for a | ||
| 1590 | single-event key sequence. This is because the functions don't use | ||
| 1591 | @code{read-key-sequence} to get the input; instead, they read a single | ||
| 1592 | event and look it up ``by hand.'' | ||
| 1593 | @end itemize | ||
| 1709 | @end defvar | 1594 | @end defvar |
| 1710 | 1595 | ||
| 1596 | Here are the meaningful ``bindings'' for @code{query-replace-map}. | ||
| 1597 | Several of them are meaningful only for @code{query-replace} and | ||
| 1598 | friends. | ||
| 1599 | |||
| 1600 | @table @code | ||
| 1601 | @item act | ||
| 1602 | Do take the action being considered---in other words, ``yes.'' | ||
| 1603 | |||
| 1604 | @item skip | ||
| 1605 | Do not take action for this question---in other words, ``no.'' | ||
| 1606 | |||
| 1607 | @item exit | ||
| 1608 | Answer this question ``no,'' and give up on the entire series of | ||
| 1609 | questions, assuming that the answers will be ``no.'' | ||
| 1610 | |||
| 1611 | @item act-and-exit | ||
| 1612 | Answer this question ``yes,'' and give up on the entire series of | ||
| 1613 | questions, assuming that subsequent answers will be ``no.'' | ||
| 1614 | |||
| 1615 | @item act-and-show | ||
| 1616 | Answer this question ``yes,'' but show the results---don't advance yet | ||
| 1617 | to the next question. | ||
| 1618 | |||
| 1619 | @item automatic | ||
| 1620 | Answer this question and all subsequent questions in the series with | ||
| 1621 | ``yes,'' without further user interaction. | ||
| 1622 | |||
| 1623 | @item backup | ||
| 1624 | Move back to the previous place that a question was asked about. | ||
| 1625 | |||
| 1626 | @item edit | ||
| 1627 | Enter a recursive edit to deal with this question---instead of any | ||
| 1628 | other action that would normally be taken. | ||
| 1629 | |||
| 1630 | @item delete-and-edit | ||
| 1631 | Delete the text being considered, then enter a recursive edit to replace | ||
| 1632 | it. | ||
| 1633 | |||
| 1634 | @item recenter | ||
| 1635 | Redisplay and center the window, then ask the same question again. | ||
| 1636 | |||
| 1637 | @item quit | ||
| 1638 | Perform a quit right away. Only @code{y-or-n-p} and related functions | ||
| 1639 | use this answer. | ||
| 1640 | |||
| 1641 | @item help | ||
| 1642 | Display some help, then ask again. | ||
| 1643 | @end table | ||
| 1644 | |||
| 1711 | @node Standard Regexps | 1645 | @node Standard Regexps |
| 1712 | @section Standard Regular Expressions Used in Editing | 1646 | @section Standard Regular Expressions Used in Editing |
| 1713 | @cindex regexps used standardly in editing | 1647 | @cindex regexps used standardly in editing |