diff options
| author | Chong Yidong | 2008-09-25 17:52:23 +0000 |
|---|---|---|
| committer | Chong Yidong | 2008-09-25 17:52:23 +0000 |
| commit | b5fb9df55e726fa5996e3464fc25659ae6fa3f7f (patch) | |
| tree | a281e97657fdfc968cf5a5fdbdf5866d58016496 | |
| parent | 321e63fc4969b95882c4623657b367d64e3fc6cf (diff) | |
| download | emacs-b5fb9df55e726fa5996e3464fc25659ae6fa3f7f.tar.gz emacs-b5fb9df55e726fa5996e3464fc25659ae6fa3f7f.zip | |
(Search): Shorten introduction.
(Basic Isearch): Add command table. Discuss reverse isearch and
isearch highlighting.
(Repeat Isearch): Move lazy highlighting discussion here. Add search
ring to cindex.
(Special Isearch): Move input methods discussion here.
(Non-ASCII Isearch): Node deleted, merged with Special Isearch.
(Isearch Yank): Node deleted, and contents moved into Basic Isearch and
Repeat Isearch.
(Isearch Minibuffer): New node.
(Word Search): Document new word search commands.
(Regexp Example): Simplify example using sentence-end-base variable.
(Replace): Reword introduction.
(Unconditional Replace): Remove unnecessary example.
(Other Repeating Search): Document new `M-s o' binding.
| -rw-r--r-- | doc/emacs/search.texi | 586 |
1 files changed, 288 insertions, 298 deletions
diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi index 979d6670f57..98838724fa3 100644 --- a/doc/emacs/search.texi +++ b/doc/emacs/search.texi | |||
| @@ -7,20 +7,13 @@ | |||
| 7 | @cindex searching | 7 | @cindex searching |
| 8 | @cindex finding strings within text | 8 | @cindex finding strings within text |
| 9 | 9 | ||
| 10 | Like other editors, Emacs has commands for searching for occurrences of | 10 | Like other editors, Emacs has commands to search for occurrences of |
| 11 | a string. The principal search command is unusual in that it is | 11 | a string. Emacs also has commands to replace occurrences of a string |
| 12 | @dfn{incremental}; it begins to search before you have finished typing the | 12 | with a different string. There are also commands that do the same |
| 13 | search string. There are also nonincremental search commands more like | 13 | thing, but search for patterns instead of fixed strings. |
| 14 | those of other editors. | 14 | |
| 15 | 15 | You can also search multiple files under the control of a tags table | |
| 16 | Besides the usual @code{replace-string} command that finds all | 16 | (@pxref{Tags Search}) or through the Dired @kbd{A} command |
| 17 | occurrences of one string and replaces them with another, Emacs has a | ||
| 18 | more flexible replacement command called @code{query-replace}, which | ||
| 19 | asks interactively which occurrences to replace. There are also | ||
| 20 | commands to find and operate on all matches for a pattern. | ||
| 21 | |||
| 22 | You can also search multiple files under control of a tags | ||
| 23 | table (@pxref{Tags Search}) or through the Dired @kbd{A} command | ||
| 24 | (@pxref{Operating on Files}), or ask the @code{grep} program to do it | 17 | (@pxref{Operating on Files}), or ask the @code{grep} program to do it |
| 25 | (@pxref{Grep Searching}). | 18 | (@pxref{Grep Searching}). |
| 26 | 19 | ||
| @@ -43,12 +36,13 @@ table (@pxref{Tags Search}) or through the Dired @kbd{A} command | |||
| 43 | @cindex incremental search | 36 | @cindex incremental search |
| 44 | @cindex isearch | 37 | @cindex isearch |
| 45 | 38 | ||
| 46 | An incremental search begins searching as soon as you type the first | 39 | The principal search command in Emacs is @dfn{incremental}: it |
| 47 | character of the search string. As you type in the search string, Emacs | 40 | begins searching as soon as you type the first character of the search |
| 48 | shows you where the string (as you have typed it so far) would be | 41 | string. As you type in the search string, Emacs shows you where the |
| 49 | found. When you have typed enough characters to identify the place you | 42 | string (as you have typed it so far) would be found. When you have |
| 50 | want, you can stop. Depending on what you plan to do next, you may or | 43 | typed enough characters to identify the place you want, you can stop. |
| 51 | may not need to terminate the search explicitly with @key{RET}. | 44 | Depending on what you plan to do next, you may or may not need to |
| 45 | terminate the search explicitly with @key{RET}. | ||
| 52 | 46 | ||
| 53 | @table @kbd | 47 | @table @kbd |
| 54 | @item C-s | 48 | @item C-s |
| @@ -62,68 +56,106 @@ Incremental search backward (@code{isearch-backward}). | |||
| 62 | * Repeat Isearch:: Searching for the same string again. | 56 | * Repeat Isearch:: Searching for the same string again. |
| 63 | * Error in Isearch:: When your string is not found. | 57 | * Error in Isearch:: When your string is not found. |
| 64 | * Special Isearch:: Special input in incremental search. | 58 | * Special Isearch:: Special input in incremental search. |
| 65 | * Non-ASCII Isearch:: How to search for non-ASCII characters. | ||
| 66 | * Isearch Yank:: Commands that grab text into the search string | 59 | * Isearch Yank:: Commands that grab text into the search string |
| 67 | or else edit the search string. | 60 | or else edit the search string. |
| 68 | * Highlight Isearch:: Isearch highlights the other possible matches. | ||
| 69 | * Isearch Scroll:: Scrolling during an incremental search. | 61 | * Isearch Scroll:: Scrolling during an incremental search. |
| 62 | * Isearch Minibuffer:: Incremental search of the minibuffer history. | ||
| 70 | * Slow Isearch:: Incremental search features for slow terminals. | 63 | * Slow Isearch:: Incremental search features for slow terminals. |
| 71 | @end menu | 64 | @end menu |
| 72 | 65 | ||
| 73 | @node Basic Isearch | 66 | @node Basic Isearch |
| 74 | @subsection Basics of Incremental Search | 67 | @subsection Basics of Incremental Search |
| 75 | 68 | ||
| 69 | @table @kbd | ||
| 70 | @item C-s | ||
| 71 | Begin incremental search (@code{isearch-forward}). | ||
| 72 | @item C-r | ||
| 73 | Begin reverse incremental search (@code{isearch-backward}). | ||
| 74 | @end table | ||
| 75 | |||
| 76 | @kindex C-s | 76 | @kindex C-s |
| 77 | @findex isearch-forward | 77 | @findex isearch-forward |
| 78 | @kbd{C-s} starts a forward incremental search. It reads characters | 78 | @kbd{C-s} (@code{isearch-forward}) starts a forward incremental |
| 79 | from the keyboard, and moves point past the next occurrence of those | 79 | search. It reads characters from the keyboard, and moves point just |
| 80 | characters. If you type @kbd{C-s} and then @kbd{F}, that puts the | 80 | past the end of the next occurrence of those characters in the buffer. |
| 81 | cursor after the first @samp{F} (the first following the starting point, since | 81 | |
| 82 | this is a forward search). Then if you type an @kbd{O}, you will see | 82 | For instance, if you type @kbd{C-s} and then @kbd{F}, that puts the |
| 83 | the cursor move to just after the first @samp{FO} (the @samp{F} in that | 83 | cursor after the first @samp{F} that occurs in the buffer after the |
| 84 | @samp{FO} may or may not be the first @samp{F}). After another | 84 | starting point. Then if you then type @kbd{O}, the cursor moves to |
| 85 | @kbd{O}, the cursor moves to just after the first @samp{FOO} after the place | 85 | just after the first @samp{FO}; the @samp{F} in that @samp{FO} might |
| 86 | where you started the search. At each step, the buffer text that | 86 | not be the first @samp{F} previously found. After another @kbd{O}, |
| 87 | matches the search string is highlighted, if the terminal can do that; | 87 | the cursor moves to just after the first @samp{FOO}. |
| 88 | the current search string is always displayed in the echo area. | 88 | |
| 89 | 89 | @cindex faces for highlighting search matches | |
| 90 | If you make a mistake in typing the search string, you can cancel | 90 | At each step, Emacs highlights the @dfn{current match}---the buffer |
| 91 | characters with @key{DEL}. Each @key{DEL} cancels the last character of | 91 | text that matches the search string---using the @code{isearch} face |
| 92 | search string. This does not happen until Emacs is ready to read another | 92 | (@pxref{Faces}). The current search string is also displayed in the |
| 93 | input character; first it must either find, or fail to find, the character | 93 | echo area. |
| 94 | you want to erase. If you do not want to wait for this to happen, use | 94 | |
| 95 | @kbd{C-g} as described below. | 95 | If you make a mistake typing the search string, type @key{DEL}. |
| 96 | 96 | Each @key{DEL} cancels the last character of the search string. | |
| 97 | When you are satisfied with the place you have reached, you can type | 97 | |
| 98 | @key{RET}, which stops searching, leaving the cursor where the search | 98 | When you are satisfied with the place you have reached, type |
| 99 | @key{RET}. This stops searching, leaving the cursor where the search | ||
| 99 | brought it. Also, any command not specially meaningful in searches | 100 | brought it. Also, any command not specially meaningful in searches |
| 100 | stops the searching and is then executed. Thus, typing @kbd{C-a} | 101 | stops the searching and is then executed. Thus, typing @kbd{C-a} |
| 101 | would exit the search and then move to the beginning of the line. | 102 | exits the search and then moves to the beginning of the line. |
| 102 | @key{RET} is necessary only if the next command you want to type is a | 103 | @key{RET} is necessary only if the next command you want to type is a |
| 103 | printing character, @key{DEL}, @key{RET}, or another character that is | 104 | printing character, @key{DEL}, @key{RET}, or another character that is |
| 104 | special within searches (@kbd{C-q}, @kbd{C-w}, @kbd{C-r}, @kbd{C-s}, | 105 | special within searches (@kbd{C-q}, @kbd{C-w}, @kbd{C-r}, @kbd{C-s}, |
| 105 | @kbd{C-y}, @kbd{M-y}, @kbd{M-r}, @kbd{M-c}, @kbd{M-e}, and some other | 106 | @kbd{C-y}, @kbd{M-y}, @kbd{M-r}, @kbd{M-c}, @kbd{M-e}, and some others |
| 106 | meta-characters). | 107 | described below). |
| 108 | |||
| 109 | As a special exception, entering @key{RET} when the search string is | ||
| 110 | empty launches nonincremental search (@pxref{Nonincremental Search}). | ||
| 107 | 111 | ||
| 108 | When you exit the incremental search, it adds the original value of | 112 | When you exit the incremental search, it adds the original value of |
| 109 | point to the mark ring, without activating the mark. You can thus use | 113 | point to the mark ring, without activating the mark; you can thus use |
| 110 | @kbd{C-@key{SPC}} to return to where you were before beginning the | 114 | @kbd{C-u C-@key{SPC}} to return to where you were before beginning the |
| 111 | search. @xref{Mark Ring}. It only does this if the mark was not | 115 | search. @xref{Mark Ring}. It only does this if the mark was not |
| 112 | already active. | 116 | already active. |
| 113 | 117 | ||
| 118 | @kindex C-r | ||
| 119 | @findex isearch-backward | ||
| 120 | To search backwards, use @kbd{C-r} (@code{isearch-backward}) instead | ||
| 121 | of @kbd{C-s} to start the search. A backward search finds matches | ||
| 122 | that end before the starting point, just as a forward search finds | ||
| 123 | matches that begin after it. | ||
| 124 | |||
| 114 | @node Repeat Isearch | 125 | @node Repeat Isearch |
| 115 | @subsection Repeating Incremental Search | 126 | @subsection Repeating Incremental Search |
| 116 | 127 | ||
| 117 | Sometimes you search for @samp{FOO} and find one, but not the one you | 128 | Suppose you search forward for @samp{FOO} and find a match, but not |
| 118 | expected to find. There was a second @samp{FOO} that you forgot | 129 | the one you expected to find: the @samp{FOO} you were aiming for |
| 119 | about, before the one you were aiming for. In this event, type | 130 | occurs later in the buffer. In this event, type another @kbd{C-s} to |
| 120 | another @kbd{C-s} to move to the next occurrence of the search string. | 131 | move to the next occurrence of the search string. You can repeat this |
| 121 | You can repeat this any number of times. If you overshoot, you can | 132 | any number of times. If you overshoot, you can cancel some @kbd{C-s} |
| 122 | cancel some @kbd{C-s} characters with @key{DEL}. | 133 | characters with @key{DEL}. Similarly, each @kbd{C-r} in a backward |
| 134 | incremental search repeats the backward search. | ||
| 135 | |||
| 136 | @cindex lazy search highlighting | ||
| 137 | @vindex isearch-lazy-highlight | ||
| 138 | If you pause for a little while during incremental search, Emacs | ||
| 139 | highlights all the other possible matches for the search string that | ||
| 140 | are present on the screen. This helps you anticipate where you can | ||
| 141 | get to by typing @kbd{C-s} or @kbd{C-r} to repeat the search. The | ||
| 142 | other matches are highlighted differently from the current match, | ||
| 143 | using the customizable face @code{lazy-highlight} (@pxref{Faces}). If | ||
| 144 | you don't like this feature, you can disable it by setting | ||
| 145 | @code{isearch-lazy-highlight} to @code{nil}. | ||
| 146 | |||
| 147 | After exiting a search, you can search for the same string again by | ||
| 148 | typing just @kbd{C-s C-s}. The first @kbd{C-s} is the key that | ||
| 149 | invokes incremental search, and the second @kbd{C-s} means ``search | ||
| 150 | again.'' Similarly, @kbd{C-r C-r} searches backward for the last | ||
| 151 | search string. In determining the last search string, it doesn't | ||
| 152 | matter whether the string was searched for with @kbd{C-s} or | ||
| 153 | @kbd{C-r}. | ||
| 123 | 154 | ||
| 124 | After you exit a search, you can search for the same string again by | 155 | If you are searching forward but you realize you were looking for |
| 125 | typing just @kbd{C-s C-s}: the first @kbd{C-s} is the key that invokes | 156 | something before the starting point, type @kbd{C-r} to switch to a |
| 126 | incremental search, and the second @kbd{C-s} means ``search again.'' | 157 | backward search, leaving the search string unchanged. Similarly, |
| 158 | @kbd{C-s} in a backward search switches to a forward search. | ||
| 127 | 159 | ||
| 128 | If a search is failing and you ask to repeat it by typing another | 160 | If a search is failing and you ask to repeat it by typing another |
| 129 | @kbd{C-s}, it starts again from the beginning of the buffer. | 161 | @kbd{C-s}, it starts again from the beginning of the buffer. |
| @@ -134,97 +166,75 @@ going past the original starting point of the search, it changes to | |||
| 134 | @samp{Overwrapped}, which means that you are revisiting matches that | 166 | @samp{Overwrapped}, which means that you are revisiting matches that |
| 135 | you have already seen. | 167 | you have already seen. |
| 136 | 168 | ||
| 169 | @cindex search ring | ||
| 137 | To reuse earlier search strings, use the @dfn{search ring}. The | 170 | To reuse earlier search strings, use the @dfn{search ring}. The |
| 138 | commands @kbd{M-p} and @kbd{M-n} move through the ring to pick a search | 171 | commands @kbd{M-p} and @kbd{M-n} move through the ring to pick a |
| 139 | string to reuse. These commands leave the selected search ring element | 172 | search string to reuse. These commands leave the selected search ring |
| 140 | in the minibuffer, where you can edit it. To edit the current search | 173 | element in the minibuffer, where you can edit it. To edit the current |
| 141 | string in the minibuffer without replacing it with items from the | 174 | search string in the minibuffer without replacing it with items from |
| 142 | search ring, type @kbd{M-e}. Type @kbd{C-s} or @kbd{C-r} | 175 | the search ring, type @kbd{M-e}. Type @kbd{C-s} or @kbd{C-r} to |
| 143 | to terminate editing the string and search for it. | 176 | terminate editing the string and search for it. |
| 144 | |||
| 145 | You can change to searching backwards with @kbd{C-r}. For instance, | ||
| 146 | if you are searching forward but you realize you were looking for | ||
| 147 | something above the starting point, you can do this. Repeated | ||
| 148 | @kbd{C-r} keeps looking for more occurrences backwards. A @kbd{C-s} | ||
| 149 | starts going forwards again. @kbd{C-r} in a search can be canceled | ||
| 150 | with @key{DEL}. | ||
| 151 | |||
| 152 | @kindex C-r | ||
| 153 | @findex isearch-backward | ||
| 154 | If you know initially that you want to search backwards, you can use | ||
| 155 | @kbd{C-r} instead of @kbd{C-s} to start the search, because @kbd{C-r} | ||
| 156 | as a key runs a command (@code{isearch-backward}) to search backward. | ||
| 157 | A backward search finds matches that end before the starting point, | ||
| 158 | just as a forward search finds matches that begin after it. | ||
| 159 | 177 | ||
| 160 | @node Error in Isearch | 178 | @node Error in Isearch |
| 161 | @subsection Errors in Incremental Search | 179 | @subsection Errors in Incremental Search |
| 162 | 180 | ||
| 163 | If your string is not found at all, the echo area says @samp{Failing | 181 | If your string is not found at all, the echo area says @samp{Failing |
| 164 | I-Search}. The cursor is after the place where Emacs found as much of your | 182 | I-Search}. The cursor is after the place where Emacs found as much of |
| 165 | string as it could. Thus, if you search for @samp{FOOT}, and there is no | 183 | your string as it could. Thus, if you search for @samp{FOOT}, and |
| 166 | @samp{FOOT}, you might see the cursor after the @samp{FOO} in @samp{FOOL}. | 184 | there is no @samp{FOOT}, you might see the cursor after the @samp{FOO} |
| 167 | At this point there are several things you can do. If your string was | 185 | in @samp{FOOL}. In the echo area, the part of the search string that |
| 168 | mistyped, you can rub some of it out and correct it. If you like the place | 186 | failed to match is highlighted using the customizable face |
| 169 | you have found, you can type @key{RET} or some other Emacs command to | 187 | @code{isearch-fail}. |
| 170 | remain there. Or you can type @kbd{C-g}, which | 188 | |
| 171 | removes from the search string the characters that could not be found (the | 189 | At this point, there are several things you can do. If your string |
| 172 | @samp{T} in @samp{FOOT}), leaving those that were found (the @samp{FOO} in | 190 | was mistyped, you can use @key{DEL} to erase some of it and correct |
| 191 | it. If you like the place you have found, you can type @key{RET} to | ||
| 192 | remain there. Or you can type @kbd{C-g}, which removes from the | ||
| 193 | search string the characters that could not be found (the @samp{T} in | ||
| 194 | @samp{FOOT}), leaving those that were found (the @samp{FOO} in | ||
| 173 | @samp{FOOT}). A second @kbd{C-g} at that point cancels the search | 195 | @samp{FOOT}). A second @kbd{C-g} at that point cancels the search |
| 174 | entirely, returning point to where it was when the search started. | 196 | entirely, returning point to where it was when the search started. |
| 175 | 197 | ||
| 176 | @cindex quitting (in search) | 198 | @cindex quitting (in search) |
| 177 | The @kbd{C-g} ``quit'' character does special things during searches; | 199 | The quit command, @kbd{C-g}, does special things during searches; |
| 178 | just what it does depends on the status of the search. If the search has | 200 | just what it does depends on the status of the search. If the search |
| 179 | found what you specified and is waiting for input, @kbd{C-g} cancels the | 201 | has found what you specified and is waiting for input, @kbd{C-g} |
| 180 | entire search. The cursor moves back to where you started the search. If | 202 | cancels the entire search, moving the cursor back to where you started |
| 181 | @kbd{C-g} is typed when there are characters in the search string that have | 203 | the search. If @kbd{C-g} is typed when there are characters in the |
| 182 | not been found---because Emacs is still searching for them, or because it | 204 | search string that have not been found---because Emacs is still |
| 183 | has failed to find them---then the search string characters which have not | 205 | searching for them, or because it has failed to find them---then the |
| 184 | been found are discarded from the search string. With them gone, the | 206 | search string characters which have not been found are discarded from |
| 185 | search is now successful and waiting for more input, so a second @kbd{C-g} | 207 | the search string. With them gone, the search is now successful and |
| 186 | will cancel the entire search. | 208 | waiting for more input, so a second @kbd{C-g} will cancel the entire |
| 209 | search. | ||
| 187 | 210 | ||
| 188 | @node Special Isearch | 211 | @node Special Isearch |
| 189 | @subsection Special Input for Incremental Search | 212 | @subsection Special Input for Incremental Search |
| 190 | 213 | ||
| 191 | An upper-case letter in the search string makes the search | 214 | Some of the characters you type during incremental search have |
| 192 | case-sensitive. If you delete the upper-case character from the search | 215 | special effects. |
| 193 | string, it ceases to have this effect. @xref{Search Case}. | 216 | |
| 194 | 217 | If the search string you entered contains only lower-case letters, | |
| 195 | To search for a newline, type @kbd{C-j}. To search for another | 218 | the search is case-insensitive; as long as an upper-case letter exists |
| 196 | control character, such as control-S or carriage return, you must quote | 219 | in the search string, the search becomes case-sensitive. If you |
| 197 | it by typing @kbd{C-q} first. This function of @kbd{C-q} is analogous | 220 | delete the upper-case character from the search string, it ceases to |
| 198 | to its use for insertion (@pxref{Inserting Text}): it causes the | 221 | have this effect. @xref{Search Case}. |
| 199 | following character to be treated the way any ``ordinary'' character is | 222 | |
| 200 | treated in the same context. You can also specify a character by its | 223 | To search for a newline character, type @kbd{C-j}. |
| 201 | octal code: enter @kbd{C-q} followed by a sequence of octal digits. | 224 | |
| 202 | 225 | To search for other control characters, such as @key{control-S}, | |
| 203 | @kbd{M-%} typed in incremental search invokes @code{query-replace} | 226 | quote it by typing @kbd{C-q} first (@pxref{Inserting Text}). To |
| 204 | or @code{query-replace-regexp} (depending on search mode) with the | 227 | search for non-@acronym{ASCII} characters, you can either use |
| 205 | current search string used as the string to replace. @xref{Query | 228 | @kbd{C-q} and enter its octal code, or use an input method |
| 206 | Replace}. | 229 | (@pxref{Input Methods}). If an input method is enabled in the current |
| 207 | 230 | buffer when you start the search, you can use it in the search string | |
| 208 | Entering @key{RET} when the search string is empty launches | 231 | also. While typing the search string, you can toggle the input method |
| 209 | nonincremental search (@pxref{Nonincremental Search}). | 232 | with the command @kbd{C-\} (@code{isearch-toggle-input-method}). You |
| 210 | 233 | can also turn on a non-default input method with @kbd{C-^} | |
| 211 | @vindex isearch-mode-map | 234 | (@code{isearch-toggle-specified-input-method}), which prompts for the |
| 212 | To customize the special characters that incremental search understands, | 235 | name of the input method. When an input method is active during |
| 213 | alter their bindings in the keymap @code{isearch-mode-map}. For a list | 236 | incremental search, the search prompt includes the input method |
| 214 | of bindings, look at the documentation of @code{isearch-mode} with | 237 | mnemonic, like this: |
| 215 | @kbd{C-h f isearch-mode @key{RET}}. | ||
| 216 | |||
| 217 | @node Non-ASCII Isearch | ||
| 218 | @subsection Isearch for Non-@acronym{ASCII} Characters | ||
| 219 | @cindex searching for non-@acronym{ASCII} characters | ||
| 220 | @cindex input method, during incremental search | ||
| 221 | |||
| 222 | To enter non-@acronym{ASCII} characters in an incremental search, | ||
| 223 | you can use @kbd{C-q} (see the previous section), but it is easier to | ||
| 224 | use an input method (@pxref{Input Methods}). If an input method is | ||
| 225 | enabled in the current buffer when you start the search, you can use | ||
| 226 | it in the search string also. Emacs indicates that by including the | ||
| 227 | input method mnemonic in its prompt, like this: | ||
| 228 | 238 | ||
| 229 | @example | 239 | @example |
| 230 | I-search [@var{im}]: | 240 | I-search [@var{im}]: |
| @@ -233,33 +243,37 @@ I-search [@var{im}]: | |||
| 233 | @noindent | 243 | @noindent |
| 234 | @findex isearch-toggle-input-method | 244 | @findex isearch-toggle-input-method |
| 235 | @findex isearch-toggle-specified-input-method | 245 | @findex isearch-toggle-specified-input-method |
| 236 | where @var{im} is the mnemonic of the active input method. | 246 | where @var{im} is the mnemonic of the active input method. Any input |
| 247 | method you enable during incremental search remains enabled in the | ||
| 248 | current buffer afterwards. | ||
| 237 | 249 | ||
| 238 | You can toggle (enable or disable) the input method while you type | 250 | @kbd{M-%} typed in incremental search invokes @code{query-replace} |
| 239 | the search string with @kbd{C-\} (@code{isearch-toggle-input-method}). | 251 | or @code{query-replace-regexp} (depending on search mode) with the |
| 240 | You can turn on a certain (non-default) input method with @kbd{C-^} | 252 | current search string used as the string to replace. @xref{Query |
| 241 | (@code{isearch-toggle-specified-input-method}), which prompts for the | 253 | Replace}. |
| 242 | name of the input method. The input method you enable during | 254 | |
| 243 | incremental search remains enabled in the current buffer afterwards. | 255 | @vindex isearch-mode-map |
| 256 | When incremental search is active, you can type @kbd{C-h C-h} to | ||
| 257 | access interactive help options, including a list of special | ||
| 258 | keybindings. These keybindings are part of the keymap | ||
| 259 | @code{isearch-mode-map} (@pxref{Keymaps}). | ||
| 244 | 260 | ||
| 245 | @node Isearch Yank | 261 | @node Isearch Yank |
| 246 | @subsection Isearch Yanking | 262 | @subsection Isearch Yanking |
| 247 | 263 | ||
| 248 | The characters @kbd{C-w} and @kbd{C-y} can be used in incremental | 264 | Within incremental search, you can use @kbd{C-w} and @kbd{C-y} to grab |
| 249 | search to grab text from the buffer into the search string. This | 265 | text from the buffer into the search string. This makes it convenient |
| 250 | makes it convenient to search for another occurrence of text at point. | 266 | to search for another occurrence of text at point. |
| 251 | @kbd{C-w} copies the character or word after point as part of the | 267 | |
| 252 | search string, advancing point over it. (The decision, whether to | 268 | @kbd{C-w} copies the character or word after point and adds it to |
| 253 | copy a character or a word, is heuristic.) Another @kbd{C-s} to | 269 | the search string, advancing point over it. (The decision, whether to |
| 254 | repeat the search will then search for a string including that | 270 | copy a character or a word, is heuristic.) |
| 255 | character or word. | ||
| 256 | 271 | ||
| 257 | @kbd{C-y} is similar to @kbd{C-w} but copies all the rest of the | 272 | @kbd{C-y} is similar to @kbd{C-w} but copies all the rest of the |
| 258 | current line into the search string. If point is already at the end | 273 | current line into the search string. If point is already at the end |
| 259 | of a line, it grabs the entire next line. Both @kbd{C-y} and | 274 | of a line, it grabs the entire next line. If the search is currently |
| 260 | @kbd{C-w} convert the text they copy to lower case if the search is | 275 | case-insensitive, both @kbd{C-y} and @kbd{C-w} convert the text they |
| 261 | currently not case-sensitive; this is so the search remains | 276 | copy to lower case, so that the search remains case-insensitive. |
| 262 | case-insensitive. | ||
| 263 | 277 | ||
| 264 | @kbd{C-M-w} and @kbd{C-M-y} modify the search string by only one | 278 | @kbd{C-M-w} and @kbd{C-M-y} modify the search string by only one |
| 265 | character at a time: @kbd{C-M-w} deletes the last character from the | 279 | character at a time: @kbd{C-M-w} deletes the last character from the |
| @@ -269,28 +283,9 @@ after point into the search string is to enter the minibuffer by | |||
| 269 | @kbd{M-e} and to type @kbd{C-f} at the end of the search string in the | 283 | @kbd{M-e} and to type @kbd{C-f} at the end of the search string in the |
| 270 | minibuffer. | 284 | minibuffer. |
| 271 | 285 | ||
| 272 | The character @kbd{M-y} copies text from the kill ring into the search | 286 | The character @kbd{M-y} copies text from the kill ring into the |
| 273 | string. It uses the same text that @kbd{C-y} as a command would yank. | 287 | search string. It uses the same text that @kbd{C-y} would yank. |
| 274 | @kbd{Mouse-2} in the echo area does the same. | 288 | @kbd{Mouse-2} in the echo area does the same. @xref{Yanking}. |
| 275 | @xref{Yanking}. | ||
| 276 | |||
| 277 | @node Highlight Isearch | ||
| 278 | @subsection Lazy Search Highlighting | ||
| 279 | @cindex lazy search highlighting | ||
| 280 | @vindex isearch-lazy-highlight | ||
| 281 | |||
| 282 | When you pause for a little while during incremental search, it | ||
| 283 | highlights all other possible matches for the search string. This | ||
| 284 | makes it easier to anticipate where you can get to by typing @kbd{C-s} | ||
| 285 | or @kbd{C-r} to repeat the search. The short delay before highlighting | ||
| 286 | other matches helps indicate which match is the current one. | ||
| 287 | If you don't like this feature, you can turn it off by setting | ||
| 288 | @code{isearch-lazy-highlight} to @code{nil}. | ||
| 289 | |||
| 290 | @cindex faces for highlighting search matches | ||
| 291 | You can control how this highlighting looks by customizing the faces | ||
| 292 | @code{isearch} (used for the current match) and @code{lazy-highlight} | ||
| 293 | (for all the other matches). | ||
| 294 | 289 | ||
| 295 | @node Isearch Scroll | 290 | @node Isearch Scroll |
| 296 | @subsection Scrolling During Incremental Search | 291 | @subsection Scrolling During Incremental Search |
| @@ -331,6 +326,30 @@ change point, the buffer contents, the match data, the current buffer, | |||
| 331 | or the selected window and frame. The command must not itself attempt | 326 | or the selected window and frame. The command must not itself attempt |
| 332 | an incremental search. | 327 | an incremental search. |
| 333 | 328 | ||
| 329 | @node Isearch Minibuffer | ||
| 330 | @subsection Searching the Minibuffer | ||
| 331 | @cindex minibuffer history, searching | ||
| 332 | |||
| 333 | If you start an incremental search while the minibuffer is active, | ||
| 334 | Emacs searches the contents of the minibuffer. Unlike searching an | ||
| 335 | ordinary buffer, the search string is not shown in the echo area, | ||
| 336 | because that is used to display the minibuffer. | ||
| 337 | |||
| 338 | If an incremental search fails in the minibuffer, it tries searching | ||
| 339 | the minibuffer history. @xref{Minibuffer History}. You can visualize | ||
| 340 | the minibuffer and its history as a series of ``pages'', with the | ||
| 341 | earliest history element on the first page and the current minibuffer | ||
| 342 | on the last page. A forward search, @kbd{C-s}, searches forward to | ||
| 343 | later pages; a reverse search, @kbd{C-r}, searches backwards to | ||
| 344 | earlier pages. Like in ordinary buffer search, a failing search can | ||
| 345 | wrap around, going from the last page to the first page or vice versa. | ||
| 346 | |||
| 347 | When the current match is on a history element, that history element | ||
| 348 | is pulled into the minibuffer. If you exit the incremental search | ||
| 349 | normally (e.g. by typing @key{RET}), it remains in the minibuffer | ||
| 350 | afterwards. Cancelling the search, with @kbd{C-g}, restores the | ||
| 351 | contents of the minibuffer when you began the search. | ||
| 352 | |||
| 334 | @node Slow Isearch | 353 | @node Slow Isearch |
| 335 | @subsection Slow Terminal Incremental Search | 354 | @subsection Slow Terminal Incremental Search |
| 336 | 355 | ||
| @@ -369,88 +388,79 @@ Search for @var{string}. | |||
| 369 | Search backward for @var{string}. | 388 | Search backward for @var{string}. |
| 370 | @end table | 389 | @end table |
| 371 | 390 | ||
| 372 | To do a nonincremental search, first type @kbd{C-s @key{RET}}. This | 391 | To start a nonincremental search, first type @kbd{C-s @key{RET}}. |
| 373 | enters the minibuffer to read the search string; terminate the string | 392 | This enters the minibuffer to read the search string; terminate the |
| 374 | with @key{RET}, and then the search takes place. If the string is not | 393 | string with @key{RET}, and then the search takes place. If the string |
| 375 | found, the search command signals an error. | 394 | is not found, the search command signals an error. |
| 376 | 395 | ||
| 377 | When you type @kbd{C-s @key{RET}}, the @kbd{C-s} invokes incremental | 396 | When you type @kbd{C-s @key{RET}}, the @kbd{C-s} invokes incremental |
| 378 | search as usual. That command is specially programmed to invoke | 397 | search as usual. That command is specially programmed to invoke |
| 379 | nonincremental search, @code{search-forward}, if the string you | 398 | nonincremental search, @code{search-forward}, if the string you |
| 380 | specify is empty. (Such an empty argument would otherwise be | 399 | specify is empty. (Such an empty argument would otherwise be |
| 381 | useless.) But it does not call @code{search-forward} right away. First | 400 | useless.) @kbd{C-r @key{RET}} does likewise, for a reverse |
| 382 | it checks the next input character to see if is @kbd{C-w}, | 401 | incremental search. |
| 383 | which specifies a word search. | ||
| 384 | @ifnottex | ||
| 385 | @xref{Word Search}. | ||
| 386 | @end ifnottex | ||
| 387 | @kbd{C-r @key{RET}} does likewise, for a reverse incremental search. | ||
| 388 | 402 | ||
| 389 | @findex search-forward | 403 | @findex search-forward |
| 390 | @findex search-backward | 404 | @findex search-backward |
| 391 | Forward and backward nonincremental searches are implemented by the | 405 | Forward and backward nonincremental searches are implemented by the |
| 392 | commands @code{search-forward} and @code{search-backward}. These | 406 | commands @code{search-forward} and @code{search-backward}. These |
| 393 | commands may be bound to keys in the usual manner. The feature that you | 407 | commands may be bound to other keys in the usual manner. |
| 394 | can get to them via the incremental search commands exists for | ||
| 395 | historical reasons, and to avoid the need to find separate key sequences | ||
| 396 | for them. | ||
| 397 | 408 | ||
| 398 | @node Word Search | 409 | @node Word Search |
| 399 | @section Word Search | 410 | @section Word Search |
| 400 | @cindex word search | 411 | @cindex word search |
| 401 | 412 | ||
| 402 | Word search searches for a sequence of words without regard to how the | 413 | A @dfn{word search} finds a sequence of words without regard to the |
| 403 | words are separated. More precisely, you type a string of many words, | 414 | type of punctuation between them. For instance, if you enter a search |
| 404 | using single spaces to separate them, and the string can be found even | 415 | string that consists of two words separated by a single space, the |
| 405 | if there are multiple spaces, newlines, or other punctuation characters | 416 | search matches any sequence of those two words separated by one or |
| 406 | between these words. | 417 | more spaces, newlines, or other punctuation characters. This is |
| 407 | 418 | particularly useful for searching text documents, because you don't | |
| 408 | Word search is useful for editing a printed document made with a text | 419 | have to worry whether the words you are looking for are separated by |
| 409 | formatter. If you edit while looking at the printed, formatted version, | 420 | newlines or spaces. |
| 410 | you can't tell where the line breaks are in the source file. With word | ||
| 411 | search, you can search without having to know them. | ||
| 412 | 421 | ||
| 413 | @table @kbd | 422 | @table @kbd |
| 414 | @item C-s @key{RET} C-w @var{words} @key{RET} | 423 | @item M-s w |
| 415 | Search for @var{words}, ignoring details of punctuation. | 424 | If incremental search is active, toggle word search mode |
| 416 | @item C-r @key{RET} C-w @var{words} @key{RET} | 425 | (@code{isearch-toggle-word}); otherwise, begin an incremental forward |
| 417 | Search backward for @var{words}, ignoring details of punctuation. | 426 | word search (@code{isearch-forward-word}). |
| 427 | @item C-s @key{RET} C-w | ||
| 428 | Begin a non-incremental forward word search. | ||
| 429 | @item C-r @key{RET} C-w | ||
| 430 | Begin a non-incremental backward word search. | ||
| 418 | @end table | 431 | @end table |
| 419 | 432 | ||
| 420 | Word search as a special case of nonincremental search is invoked | 433 | To begin a forward incremental word search, type @kbd{M-s w}. If |
| 421 | with @kbd{C-s @key{RET} C-w}. This is followed by the search string, | 434 | incremental search is not already active, this runs the command |
| 422 | which must always be terminated with @key{RET}. Being nonincremental, | 435 | @code{isearch-forward-word}. If incremental search is already active |
| 423 | this search does not start until the argument is terminated. It works | 436 | (whether a forward or backward search), @kbd{M-s w} switches to a word |
| 424 | by constructing a regular expression and searching for that; see | 437 | search while keeping the direction of the search and the current |
| 425 | @ref{Regexp Search}. | 438 | search string unchanged. You can toggle word search back off by |
| 426 | 439 | typing @kbd{M-s w} again. | |
| 427 | Use @kbd{C-r @key{RET} C-w} to do backward word search. | ||
| 428 | |||
| 429 | You can also invoke word search with @kbd{C-s M-e C-w} or @kbd{C-r | ||
| 430 | M-e C-w} followed by the search string and terminated with @key{RET}, | ||
| 431 | @kbd{C-s} or @kbd{C-r}. This puts word search into incremental mode | ||
| 432 | where you can use all keys available for incremental search. However, | ||
| 433 | when you type more words in incremental word search, it will fail | ||
| 434 | until you type complete words. | ||
| 435 | 440 | ||
| 436 | @findex word-search-forward | 441 | @findex word-search-forward |
| 437 | @findex word-search-backward | 442 | @findex word-search-backward |
| 438 | Forward and backward word searches are implemented by the commands | 443 | To begin a nonincremental word search, type @kbd{C-s @key{RET} C-w} |
| 439 | @code{word-search-forward} and @code{word-search-backward}. These | 444 | for a forward search or @kbd{C-r @key{RET} C-w} for a forward search. |
| 440 | commands may be bound to keys in the usual manner. They are available | 445 | These run the commands @code{word-search-forward} and |
| 441 | via the incremental search commands both for historical reasons and | 446 | @code{word-search-backward} respectively. |
| 442 | to avoid the need to find separate key sequences for them. | 447 | |
| 448 | A nonincremental word search differs slightly from the incremental | ||
| 449 | version in the way it finds a match: the last word in the search | ||
| 450 | string must be an exact match for a whole word. In an incremental | ||
| 451 | word search, the last word in the search string can match part of a | ||
| 452 | word; this allows the matching to proceed incrementally as you type. | ||
| 443 | 453 | ||
| 444 | @node Regexp Search | 454 | @node Regexp Search |
| 445 | @section Regular Expression Search | 455 | @section Regular Expression Search |
| 446 | @cindex regular expression | 456 | @cindex regular expression |
| 447 | @cindex regexp | 457 | @cindex regexp |
| 448 | 458 | ||
| 449 | A @dfn{regular expression} (@dfn{regexp}, for short) is a pattern | 459 | A @dfn{regular expression} (or @dfn{regexp} for short) is a pattern |
| 450 | that denotes a class of alternative strings to match, possibly | 460 | that denotes a class of alternative strings to match. GNU Emacs |
| 451 | infinitely many. GNU Emacs provides both incremental and | 461 | provides both incremental and nonincremental ways to search for a |
| 452 | nonincremental ways to search for a match for a regexp. The syntax of | 462 | match for a regexp. The syntax of regular expressions is explained in |
| 453 | regular expressions is explained in the following section. | 463 | the following section. |
| 454 | 464 | ||
| 455 | @kindex C-M-s | 465 | @kindex C-M-s |
| 456 | @findex isearch-forward-regexp | 466 | @findex isearch-forward-regexp |
| @@ -468,12 +478,12 @@ for. To search backward for a regexp, use @kbd{C-M-r} | |||
| 468 | (@code{isearch-backward-regexp}), @kbd{C-r} with a prefix argument, | 478 | (@code{isearch-backward-regexp}), @kbd{C-r} with a prefix argument, |
| 469 | or @kbd{M-r} within a backward incremental search. | 479 | or @kbd{M-r} within a backward incremental search. |
| 470 | 480 | ||
| 471 | All of the control characters that do special things within an | 481 | All of the special key sequences in an ordinary incremental search |
| 472 | ordinary incremental search have the same function in incremental regexp | 482 | do similar things in an incremental regexp search. For instance, |
| 473 | search. Typing @kbd{C-s} or @kbd{C-r} immediately after starting the | 483 | typing @kbd{C-s} immediately after starting the search retrieves the |
| 474 | search retrieves the last incremental search regexp used; that is to | 484 | last incremental search regexp used and searches forward for it. |
| 475 | say, incremental regexp and non-regexp searches have independent | 485 | Incremental regexp and non-regexp searches have independent defaults. |
| 476 | defaults. They also have separate search rings that you can access with | 486 | They also have separate search rings, which you can access with |
| 477 | @kbd{M-p} and @kbd{M-n}. | 487 | @kbd{M-p} and @kbd{M-n}. |
| 478 | 488 | ||
| 479 | @vindex search-whitespace-regexp | 489 | @vindex search-whitespace-regexp |
| @@ -483,10 +493,11 @@ match just a space, type @kbd{C-q @key{SPC}}. You can control what a | |||
| 483 | bare space matches by setting the variable | 493 | bare space matches by setting the variable |
| 484 | @code{search-whitespace-regexp} to the desired regexp. | 494 | @code{search-whitespace-regexp} to the desired regexp. |
| 485 | 495 | ||
| 486 | In some cases, adding characters to the regexp in an incremental regexp | 496 | In some cases, adding characters to the regexp in an incremental |
| 487 | search can make the cursor move back and start again. For example, if | 497 | regexp search can make the cursor move back and start again. For |
| 488 | you have searched for @samp{foo} and you add @samp{\|bar}, the cursor | 498 | example, if you have searched for @samp{foo} and you add @samp{\|bar}, |
| 489 | backs up in case the first @samp{bar} precedes the first @samp{foo}. | 499 | the cursor backs up in case the first @samp{bar} precedes the first |
| 500 | @samp{foo}. @xref{Regexps}. | ||
| 490 | 501 | ||
| 491 | Forward and backward regexp search are not symmetrical, because | 502 | Forward and backward regexp search are not symmetrical, because |
| 492 | regexp matching in Emacs always operates forward, starting with the | 503 | regexp matching in Emacs always operates forward, starting with the |
| @@ -498,10 +509,9 @@ starting position. These search methods are not mirror images. | |||
| 498 | @findex re-search-forward | 509 | @findex re-search-forward |
| 499 | @findex re-search-backward | 510 | @findex re-search-backward |
| 500 | Nonincremental search for a regexp is done by the functions | 511 | Nonincremental search for a regexp is done by the functions |
| 501 | @code{re-search-forward} and @code{re-search-backward}. You can invoke | 512 | @code{re-search-forward} and @code{re-search-backward}. You can |
| 502 | these with @kbd{M-x}, or bind them to keys, or invoke them by way of | 513 | invoke these with @kbd{M-x}, or by way of incremental regexp search |
| 503 | incremental regexp search with @kbd{C-M-s @key{RET}} and @kbd{C-M-r | 514 | with @kbd{C-M-s @key{RET}} and @kbd{C-M-r @key{RET}}. |
| 504 | @key{RET}}. | ||
| 505 | 515 | ||
| 506 | If you use the incremental regexp search commands with a prefix | 516 | If you use the incremental regexp search commands with a prefix |
| 507 | argument, they perform ordinary string search, like | 517 | argument, they perform ordinary string search, like |
| @@ -881,43 +891,30 @@ setting of the syntax table (@pxref{Syntax}). | |||
| 881 | @node Regexp Example | 891 | @node Regexp Example |
| 882 | @section Regular Expression Example | 892 | @section Regular Expression Example |
| 883 | 893 | ||
| 884 | Here is a complicated regexp---a simplified version of the regexp | 894 | Here is an example of a regexp---the regexp that Emacs uses, by |
| 885 | that Emacs uses, by default, to recognize the end of a sentence | 895 | default, to recognize the end of a sentence, not including the |
| 886 | together with any whitespace that follows. We show its Lisp syntax to | 896 | following space (i.e., the variable @code{sentence-end-base}): |
| 887 | distinguish the spaces from the tab characters. In Lisp syntax, the | ||
| 888 | string constant begins and ends with a double-quote. @samp{\"} stands | ||
| 889 | for a double-quote as part of the regexp, @samp{\\} for a backslash as | ||
| 890 | part of the regexp, @samp{\t} for a tab, and @samp{\n} for a newline. | ||
| 891 | 897 | ||
| 892 | @example | 898 | @example |
| 893 | "[.?!][]\"')]*\\($\\| $\\|\t\\| \\)[ \t\n]*" | 899 | @verbatim |
| 900 | [.?!][]\"'””)}]* | ||
| 901 | @end verbatim | ||
| 894 | @end example | 902 | @end example |
| 895 | 903 | ||
| 896 | @noindent | 904 | @noindent |
| 897 | This contains four parts in succession: a character set matching | 905 | This contains two parts in succession: a character set matching |
| 898 | period, @samp{?}, or @samp{!}; a character set matching | 906 | period, @samp{?}, or @samp{!}, and a character set matching |
| 899 | close-brackets, quotes, or parentheses, repeated zero or more times; a | 907 | close-brackets, quotes, or parentheses, repeated zero or more times. |
| 900 | set of alternatives within backslash-parentheses that matches either | ||
| 901 | end-of-line, a space at the end of a line, a tab, or two spaces; and a | ||
| 902 | character set matching whitespace characters, repeated any number of | ||
| 903 | times. | ||
| 904 | |||
| 905 | To enter the same regexp in incremental search, you would type | ||
| 906 | @key{TAB} to enter a tab, and @kbd{C-j} to enter a newline. You would | ||
| 907 | also type single backslashes as themselves, instead of doubling them | ||
| 908 | for Lisp syntax. In commands that use ordinary minibuffer input to | ||
| 909 | read a regexp, you would quote the @kbd{C-j} by preceding it with a | ||
| 910 | @kbd{C-q} to prevent @kbd{C-j} from exiting the minibuffer. | ||
| 911 | 908 | ||
| 912 | @node Search Case | 909 | @node Search Case |
| 913 | @section Searching and Case | 910 | @section Searching and Case |
| 914 | 911 | ||
| 915 | Incremental searches in Emacs normally ignore the case of the text | 912 | Searches in Emacs normally ignore the case of the text they are |
| 916 | they are searching through, if you specify the text in lower case. | 913 | searching through, if you specify the text in lower case. Thus, if |
| 917 | Thus, if you specify searching for @samp{foo}, then @samp{Foo} and | 914 | you specify searching for @samp{foo}, then @samp{Foo} and @samp{foo} |
| 918 | @samp{foo} are also considered a match. Regexps, and in particular | 915 | are also considered a match. Regexps, and in particular character |
| 919 | character sets, are included: @samp{[ab]} would match @samp{a} or | 916 | sets, are included: @samp{[ab]} would match @samp{a} or @samp{A} or |
| 920 | @samp{A} or @samp{b} or @samp{B}.@refill | 917 | @samp{b} or @samp{B}.@refill |
| 921 | 918 | ||
| 922 | An upper-case letter anywhere in the incremental search string makes | 919 | An upper-case letter anywhere in the incremental search string makes |
| 923 | the search case-sensitive. Thus, searching for @samp{Foo} does not find | 920 | the search case-sensitive. Thus, searching for @samp{Foo} does not find |
| @@ -928,7 +925,8 @@ upper-case letter from the search string. | |||
| 928 | Typing @kbd{M-c} within an incremental search toggles the case | 925 | Typing @kbd{M-c} within an incremental search toggles the case |
| 929 | sensitivity of that search. The effect does not extend beyond the | 926 | sensitivity of that search. The effect does not extend beyond the |
| 930 | current incremental search to the next one, but it does override the | 927 | current incremental search to the next one, but it does override the |
| 931 | effect of including an upper-case letter in the current search. | 928 | effect of adding or removing an upper-case letter in the current |
| 929 | search. | ||
| 932 | 930 | ||
| 933 | @vindex case-fold-search | 931 | @vindex case-fold-search |
| 934 | @vindex default-case-fold-search | 932 | @vindex default-case-fold-search |
| @@ -954,18 +952,17 @@ apropos-variable @key{RET} case-fold-search @key{RET}}. | |||
| 954 | @cindex string substitution | 952 | @cindex string substitution |
| 955 | @cindex global substitution | 953 | @cindex global substitution |
| 956 | 954 | ||
| 957 | Global search-and-replace operations are not needed often in Emacs, | 955 | Emacs provides several commands for performing search-and-replace |
| 958 | but they are available. In addition to the simple @kbd{M-x | 956 | operations. In addition to the simple @kbd{M-x replace-string} |
| 959 | replace-string} command which replaces all occurrences, | 957 | command, there is @kbd{M-%} (@code{query-replace}), which presents |
| 960 | there is @kbd{M-%} (@code{query-replace}), which presents each occurrence | 958 | each occurrence of the pattern and asks you whether to replace it. |
| 961 | of the pattern and asks you whether to replace it. | ||
| 962 | 959 | ||
| 963 | The replace commands normally operate on the text from point to the | 960 | The replace commands normally operate on the text from point to the |
| 964 | end of the buffer. When the mark is active, they operate on the | 961 | end of the buffer. When the mark is active, they operate on the |
| 965 | region instead (@pxref{Mark}). The basic replace commands replace one | 962 | region instead (@pxref{Mark}). The basic replace commands replace one |
| 966 | string (or regexp) with one replacement string. It is possible to | 963 | @dfn{search string} (or regexp) with one @dfn{replacement string}. It |
| 967 | perform several replacements in parallel using the command | 964 | is possible to perform several replacements in parallel, using the |
| 968 | @code{expand-region-abbrevs} (@pxref{Expanding Abbrevs}). | 965 | command @code{expand-region-abbrevs} (@pxref{Expanding Abbrevs}). |
| 969 | 966 | ||
| 970 | @menu | 967 | @menu |
| 971 | * Unconditional Replace:: Replacing all matches for a string. | 968 | * Unconditional Replace:: Replacing all matches for a string. |
| @@ -988,10 +985,9 @@ use the command @kbd{M-x replace-string} with the two arguments | |||
| 988 | @samp{foo} and @samp{bar}. Replacement happens only in the text after | 985 | @samp{foo} and @samp{bar}. Replacement happens only in the text after |
| 989 | point, so if you want to cover the whole buffer you must go to the | 986 | point, so if you want to cover the whole buffer you must go to the |
| 990 | beginning first. All occurrences up to the end of the buffer are | 987 | beginning first. All occurrences up to the end of the buffer are |
| 991 | replaced; to limit replacement to part of the buffer, narrow to that | 988 | replaced; to limit replacement to part of the buffer, activate the |
| 992 | part of the buffer before doing the replacement (@pxref{Narrowing}). | 989 | region around that part. When the region is active, replacement is |
| 993 | When the region is active, replacement is limited to the region | 990 | limited to the region (@pxref{Mark}). |
| 994 | (@pxref{Mark}). | ||
| 995 | 991 | ||
| 996 | When @code{replace-string} exits, it leaves point at the last | 992 | When @code{replace-string} exits, it leaves point at the last |
| 997 | occurrence replaced. It adds the prior position of point (where the | 993 | occurrence replaced. It adds the prior position of point (where the |
| @@ -999,24 +995,12 @@ occurrence replaced. It adds the prior position of point (where the | |||
| 999 | activating the mark; use @kbd{C-u C-@key{SPC}} to move back there. | 995 | activating the mark; use @kbd{C-u C-@key{SPC}} to move back there. |
| 1000 | @xref{Mark Ring}. | 996 | @xref{Mark Ring}. |
| 1001 | 997 | ||
| 1002 | A numeric argument restricts replacement to matches that are surrounded | 998 | A prefix argument restricts replacement to matches that are |
| 1003 | by word boundaries. The argument's value doesn't matter. | 999 | surrounded by word boundaries. The argument's value doesn't matter. |
| 1004 | 1000 | ||
| 1005 | @xref{Replacement and Case}, for details about case-sensitivity in | 1001 | @xref{Replacement and Case}, for details about case-sensitivity in |
| 1006 | replace commands. | 1002 | replace commands. |
| 1007 | 1003 | ||
| 1008 | What if you want to exchange @samp{x} and @samp{y}: replace every @samp{x} with a @samp{y} and vice versa? You can do it this way: | ||
| 1009 | |||
| 1010 | @example | ||
| 1011 | M-x replace-string @key{RET} x @key{RET} @@TEMP@@ @key{RET} | ||
| 1012 | M-< M-x replace-string @key{RET} y @key{RET} x @key{RET} | ||
| 1013 | M-< M-x replace-string @key{RET} @@TEMP@@ @key{RET} y @key{RET} | ||
| 1014 | @end example | ||
| 1015 | |||
| 1016 | @noindent | ||
| 1017 | This works provided the string @samp{@@TEMP@@} does not appear | ||
| 1018 | in your text. | ||
| 1019 | |||
| 1020 | @node Regexp Replace, Replacement and Case, Unconditional Replace, Replace | 1004 | @node Regexp Replace, Replacement and Case, Unconditional Replace, Replace |
| 1021 | @subsection Regexp Replacement | 1005 | @subsection Regexp Replacement |
| 1022 | @findex replace-regexp | 1006 | @findex replace-regexp |
| @@ -1316,6 +1300,12 @@ does not select it. | |||
| 1316 | After using @kbd{M-x occur}, you can use @code{next-error} to visit | 1300 | After using @kbd{M-x occur}, you can use @code{next-error} to visit |
| 1317 | the occurrences found, one by one. @ref{Compilation Mode}. | 1301 | the occurrences found, one by one. @ref{Compilation Mode}. |
| 1318 | 1302 | ||
| 1303 | @kindex M-s o | ||
| 1304 | @item M-s o | ||
| 1305 | Run @code{occur} using the search string of the last incremental | ||
| 1306 | string search. You can also run @kbd{M-s o} which an incremental | ||
| 1307 | search is active; this uses the current search string. | ||
| 1308 | |||
| 1319 | @item M-x list-matching-lines | 1309 | @item M-x list-matching-lines |
| 1320 | Synonym for @kbd{M-x occur}. | 1310 | Synonym for @kbd{M-x occur}. |
| 1321 | 1311 | ||