diff options
| author | Eli Zaretskii | 2015-11-25 21:09:29 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2015-11-25 21:09:29 +0200 |
| commit | 8f2a5a8aa487036006b7590c896cde30157ca7e0 (patch) | |
| tree | 488c77404b4d7a40e8a9083745d81a6bd5775800 | |
| parent | 849c1f0180bdadfe695ba0dc2abaf8d060c20328 (diff) | |
| download | emacs-8f2a5a8aa487036006b7590c896cde30157ca7e0.tar.gz emacs-8f2a5a8aa487036006b7590c896cde30157ca7e0.zip | |
Improve and update documentation of search commands
* doc/emacs/search.texi (Lax Search): Renamed from "Search Case";
all references changed. Move the description of lax-whitespace
here. Add description of the new character folding features and
additional customizable options.
(Isearch Yank): Move before "Error in Search".
(Basic Isearch): Improve wording. Add index entries. Add short
description of how to abandon search, making this subsection a
complete introduction to search basics.
(Repeat Isearch): Add index entries. Describe additional
customizable options. Describe mouse clicks.
(Isearch Yank): Add index entries. Describe mouse-2 click in echo
area. Describe more customizable options.
(Error in Isearch): Add index entries.
(Special Isearch): Move actual description of some isearch
commands to other sections, leaving here just the summary of the
commands. Add command that toggles character folding. Describe
commands, like "C-h C-h", that were previously omitted for some
reason.
(Not Exiting Isearch): Describe search-exit-option. Add index
entries.
(Word Search): Describe eww-search-word and eww-search-prefix.
(Symbol Search): Add index entries.
(Regexp Search): Describe regexp-search-ring-max.
(Replacement and Lax Matches): Renamed from "Replacement and
Case"; all references changed. Describe lax-whitespace matching
in replace commands and related options. Describe character
folding in replace commands and related options.
(Query Replace): Describe query-replace-from-to-separator and the
new history features. Add index entries for highlighted text.
Describe query-replace-skip-read-only. Describe more keys
accepted by query-replace.
(Other Repeating Search): More index entries for Occur. Describe
list-matching-lines-default-context-lines.
(Search Customizations): New section, documents customizable
options that were not documented until now.
* doc/emacs/glossary.texi (Glossary): Add "Case Folding" and
"Character Folding".
* etc/NEWS: Move search- and replace-related entries to a single
parent section.
* lisp/replace.el (query-replace-show-replacement): Doc fix.
* lisp/isearch.el (search-nonincremental-instead)
(isearch-hide-immediately): Doc fixes.
| -rw-r--r-- | doc/emacs/abbrevs.texi | 4 | ||||
| -rw-r--r-- | doc/emacs/emacs.texi | 11 | ||||
| -rw-r--r-- | doc/emacs/glossary.texi | 11 | ||||
| -rw-r--r-- | doc/emacs/maintaining.texi | 2 | ||||
| -rw-r--r-- | doc/emacs/mini.texi | 4 | ||||
| -rw-r--r-- | doc/emacs/search.texi | 738 | ||||
| -rw-r--r-- | etc/NEWS | 53 | ||||
| -rw-r--r-- | lisp/isearch.el | 12 | ||||
| -rw-r--r-- | lisp/replace.el | 3 |
9 files changed, 595 insertions, 243 deletions
diff --git a/doc/emacs/abbrevs.texi b/doc/emacs/abbrevs.texi index 23d7e28f4e3..695ffa8d1cd 100644 --- a/doc/emacs/abbrevs.texi +++ b/doc/emacs/abbrevs.texi | |||
| @@ -407,7 +407,7 @@ you are expanding. | |||
| 407 | in this search; if it is @code{nil}, the word and the expansion must | 407 | in this search; if it is @code{nil}, the word and the expansion must |
| 408 | match in case. If the value is @code{case-fold-search} (the default), | 408 | match in case. If the value is @code{case-fold-search} (the default), |
| 409 | then the variable @code{case-fold-search} controls whether to ignore | 409 | then the variable @code{case-fold-search} controls whether to ignore |
| 410 | case while searching for expansions (@pxref{Search Case}). | 410 | case while searching for expansions (@pxref{Lax Search}). |
| 411 | 411 | ||
| 412 | @vindex dabbrev-case-replace | 412 | @vindex dabbrev-case-replace |
| 413 | Normally, dynamic abbrev expansion preserves the case pattern | 413 | Normally, dynamic abbrev expansion preserves the case pattern |
| @@ -421,7 +421,7 @@ the dynamic abbrev's case pattern is preserved in most cases; if it is | |||
| 421 | @code{nil}, the expansion is always copied verbatim. If the value is | 421 | @code{nil}, the expansion is always copied verbatim. If the value is |
| 422 | @code{case-replace} (the default), then the variable | 422 | @code{case-replace} (the default), then the variable |
| 423 | @code{case-replace} controls whether to copy the expansion verbatim | 423 | @code{case-replace} controls whether to copy the expansion verbatim |
| 424 | (@pxref{Replacement and Case}). | 424 | (@pxref{Replacement and Lax Matches}). |
| 425 | 425 | ||
| 426 | However, if the expansion contains a complex mixed case pattern, and | 426 | However, if the expansion contains a complex mixed case pattern, and |
| 427 | the dynamic abbrev matches this pattern as far as it goes, then the | 427 | the dynamic abbrev matches this pattern as far as it goes, then the |
diff --git a/doc/emacs/emacs.texi b/doc/emacs/emacs.texi index 27bb77d5cac..2877be9c6b7 100644 --- a/doc/emacs/emacs.texi +++ b/doc/emacs/emacs.texi | |||
| @@ -392,18 +392,20 @@ Searching and Replacement | |||
| 392 | * Regexps:: Syntax of regular expressions. | 392 | * Regexps:: Syntax of regular expressions. |
| 393 | * Regexp Backslash:: Regular expression constructs starting with `\'. | 393 | * Regexp Backslash:: Regular expression constructs starting with `\'. |
| 394 | * Regexp Example:: A complex regular expression explained. | 394 | * Regexp Example:: A complex regular expression explained. |
| 395 | * Search Case:: To ignore case while searching, or not. | 395 | * Lax Search:: Search ignores some distinctions between |
| 396 | similar characters, like letter-case. | ||
| 396 | * Replace:: Search, and replace some or all matches. | 397 | * Replace:: Search, and replace some or all matches. |
| 397 | * Other Repeating Search:: Operating on all matches for some regexp. | 398 | * Other Repeating Search:: Operating on all matches for some regexp. |
| 399 | * Search Customizations:: Various search customizations. | ||
| 398 | 400 | ||
| 399 | Incremental Search | 401 | Incremental Search |
| 400 | 402 | ||
| 401 | * Basic Isearch:: Basic incremental search commands. | 403 | * Basic Isearch:: Basic incremental search commands. |
| 402 | * Repeat Isearch:: Searching for the same string again. | 404 | * Repeat Isearch:: Searching for the same string again. |
| 403 | * Error in Isearch:: When your string is not found. | ||
| 404 | * Special Isearch:: Special input in incremental search. | ||
| 405 | * Isearch Yank:: Commands that grab text into the search string | 405 | * Isearch Yank:: Commands that grab text into the search string |
| 406 | or else edit the search string. | 406 | or else edit the search string. |
| 407 | * Error in Isearch:: When your string is not found. | ||
| 408 | * Special Isearch:: Special input in incremental search. | ||
| 407 | * Not Exiting Isearch:: Prefix argument and scrolling commands. | 409 | * Not Exiting Isearch:: Prefix argument and scrolling commands. |
| 408 | * Isearch Minibuffer:: Incremental search of the minibuffer history. | 410 | * Isearch Minibuffer:: Incremental search of the minibuffer history. |
| 409 | 411 | ||
| @@ -411,7 +413,8 @@ Replacement Commands | |||
| 411 | 413 | ||
| 412 | * Unconditional Replace:: Replacing all matches for a string. | 414 | * Unconditional Replace:: Replacing all matches for a string. |
| 413 | * Regexp Replace:: Replacing all matches for a regexp. | 415 | * Regexp Replace:: Replacing all matches for a regexp. |
| 414 | * Replacement and Case:: How replacements preserve case of letters. | 416 | * Replacement and Lax Matches:: |
| 417 | Lax searching for text to replace. | ||
| 415 | * Query Replace:: How to use querying. | 418 | * Query Replace:: How to use querying. |
| 416 | 419 | ||
| 417 | Commands for Fixing Typos | 420 | Commands for Fixing Typos |
diff --git a/doc/emacs/glossary.texi b/doc/emacs/glossary.texi index e66cd79e740..cc81101d67a 100644 --- a/doc/emacs/glossary.texi +++ b/doc/emacs/glossary.texi | |||
| @@ -175,11 +175,22 @@ corresponding Control character. @xref{User Input,C-M-}. | |||
| 175 | Case conversion means changing text from upper case to lower case or | 175 | Case conversion means changing text from upper case to lower case or |
| 176 | vice versa. @xref{Case}. | 176 | vice versa. @xref{Case}. |
| 177 | 177 | ||
| 178 | @item Case Folding | ||
| 179 | Case folding means ignoring the differences between case variants of | ||
| 180 | the same letter: upper-case, lower-case, and title-case. Emacs | ||
| 181 | performs case folding by default in text search. @xref{Lax Search}. | ||
| 182 | |||
| 178 | @item Character | 183 | @item Character |
| 179 | Characters form the contents of an Emacs buffer. Also, key sequences | 184 | Characters form the contents of an Emacs buffer. Also, key sequences |
| 180 | (q.v.@:) are usually made up of characters (though they may include | 185 | (q.v.@:) are usually made up of characters (though they may include |
| 181 | other input events as well). @xref{User Input}. | 186 | other input events as well). @xref{User Input}. |
| 182 | 187 | ||
| 188 | @item Character Folding | ||
| 189 | Character folding means ignoring differences between similarly looking | ||
| 190 | characters, such as between @code{a}, and @code{@:a} and @code{@'a}. | ||
| 191 | Emacs performs character folding by default in text search. @xref{Lax | ||
| 192 | Search}. | ||
| 193 | |||
| 183 | @item Character Set | 194 | @item Character Set |
| 184 | Emacs supports a number of character sets, each of which represents a | 195 | Emacs supports a number of character sets, each of which represents a |
| 185 | particular alphabet or script. @xref{International}. | 196 | particular alphabet or script. @xref{International}. |
diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index a571ea7ed67..f1a59f84351 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi | |||
| @@ -2285,7 +2285,7 @@ input. @xref{Query Replace}, for more information on query replace. | |||
| 2285 | You can control the case-sensitivity of tags search commands by | 2285 | You can control the case-sensitivity of tags search commands by |
| 2286 | customizing the value of the variable @code{tags-case-fold-search}. The | 2286 | customizing the value of the variable @code{tags-case-fold-search}. The |
| 2287 | default is to use the same setting as the value of | 2287 | default is to use the same setting as the value of |
| 2288 | @code{case-fold-search} (@pxref{Search Case}). | 2288 | @code{case-fold-search} (@pxref{Lax Search}). |
| 2289 | 2289 | ||
| 2290 | It is possible to get through all the files in the tags table with a | 2290 | It is possible to get through all the files in the tags table with a |
| 2291 | single invocation of @kbd{M-x tags-query-replace}. But often it is | 2291 | single invocation of @kbd{M-x tags-query-replace}. But often it is |
diff --git a/doc/emacs/mini.texi b/doc/emacs/mini.texi index 2493fdadf37..ed339a967a4 100644 --- a/doc/emacs/mini.texi +++ b/doc/emacs/mini.texi | |||
| @@ -642,8 +642,8 @@ expressions. A numeric prefix argument @var{n} means to fetch the | |||
| 642 | @var{n}th matching entry. These commands are unusual, in that they | 642 | @var{n}th matching entry. These commands are unusual, in that they |
| 643 | use the minibuffer to read the regular expression argument, even | 643 | use the minibuffer to read the regular expression argument, even |
| 644 | though they are invoked from the minibuffer. An upper-case letter in | 644 | though they are invoked from the minibuffer. An upper-case letter in |
| 645 | the regular expression makes the search case-sensitive (@pxref{Search | 645 | the regular expression makes the search case-sensitive (@pxref{Lax |
| 646 | Case}). | 646 | Search}). |
| 647 | 647 | ||
| 648 | You can also search through the history using an incremental search. | 648 | You can also search through the history using an incremental search. |
| 649 | @xref{Isearch Minibuffer}. | 649 | @xref{Isearch Minibuffer}. |
diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi index ae275d1ca67..9da9226d3bf 100644 --- a/doc/emacs/search.texi +++ b/doc/emacs/search.texi | |||
| @@ -26,9 +26,11 @@ thing, but search for patterns instead of fixed strings. | |||
| 26 | * Regexps:: Syntax of regular expressions. | 26 | * Regexps:: Syntax of regular expressions. |
| 27 | * Regexp Backslash:: Regular expression constructs starting with `\'. | 27 | * Regexp Backslash:: Regular expression constructs starting with `\'. |
| 28 | * Regexp Example:: A complex regular expression explained. | 28 | * Regexp Example:: A complex regular expression explained. |
| 29 | * Search Case:: To ignore case while searching, or not. | 29 | * Lax Search:: Search ignores some distinctions between |
| 30 | similar characters, like letter-case. | ||
| 30 | * Replace:: Search, and replace some or all matches. | 31 | * Replace:: Search, and replace some or all matches. |
| 31 | * Other Repeating Search:: Operating on all matches for some regexp. | 32 | * Other Repeating Search:: Operating on all matches for some regexp. |
| 33 | * Search Customizations:: Various search customizations. | ||
| 32 | @end menu | 34 | @end menu |
| 33 | 35 | ||
| 34 | @node Incremental Search | 36 | @node Incremental Search |
| @@ -54,10 +56,10 @@ Incremental search backward (@code{isearch-backward}). | |||
| 54 | @menu | 56 | @menu |
| 55 | * Basic Isearch:: Basic incremental search commands. | 57 | * Basic Isearch:: Basic incremental search commands. |
| 56 | * Repeat Isearch:: Searching for the same string again. | 58 | * Repeat Isearch:: Searching for the same string again. |
| 57 | * Error in Isearch:: When your string is not found. | ||
| 58 | * Special Isearch:: Special input in incremental search. | ||
| 59 | * Isearch Yank:: Commands that grab text into the search string | 59 | * Isearch Yank:: Commands that grab text into the search string |
| 60 | or else edit the search string. | 60 | or else edit the search string. |
| 61 | * Error in Isearch:: When your string is not found. | ||
| 62 | * Special Isearch:: Special input in incremental search. | ||
| 61 | * Not Exiting Isearch:: Prefix argument and scrolling commands. | 63 | * Not Exiting Isearch:: Prefix argument and scrolling commands. |
| 62 | * Isearch Minibuffer:: Incremental search of the minibuffer history. | 64 | * Isearch Minibuffer:: Incremental search of the minibuffer history. |
| 63 | @end menu | 65 | @end menu |
| @@ -89,31 +91,46 @@ cursor moves to just after the first @samp{FOO}. | |||
| 89 | @cindex isearch face | 91 | @cindex isearch face |
| 90 | At each step, Emacs highlights the @dfn{current match}---the buffer | 92 | At each step, Emacs highlights the @dfn{current match}---the buffer |
| 91 | text that matches the search string---using the @code{isearch} face | 93 | text that matches the search string---using the @code{isearch} face |
| 92 | (@pxref{Faces}). The current search string is also displayed in the | 94 | (@pxref{Faces}). @xref{Search Customizations}, for various options |
| 93 | echo area. | 95 | that customize this highlighting. The current search string is also |
| 96 | displayed in the echo area. | ||
| 94 | 97 | ||
| 95 | If you make a mistake typing the search string, type @key{DEL}. | 98 | If you make a mistake typing the search string, type @key{DEL}. |
| 96 | Each @key{DEL} cancels the last character of the search string. | 99 | Each @key{DEL} cancels the last character of the search string. |
| 100 | @xref{Error in Isearch}, for more about dealing with unsuccessful | ||
| 101 | search. | ||
| 97 | 102 | ||
| 103 | @cindex exit incremental search | ||
| 104 | @cindex incremental search, exiting | ||
| 98 | When you are satisfied with the place you have reached, type | 105 | When you are satisfied with the place you have reached, type |
| 99 | @key{RET}. This stops searching, leaving the cursor where the search | 106 | @key{RET}. This stops searching, leaving the cursor where the search |
| 100 | brought it. Also, any command not specially meaningful in searches | 107 | brought it. Also, any command not specially meaningful in searches |
| 101 | stops the searching and is then executed. Thus, typing @kbd{C-a} | 108 | stops the searching and is then executed. Thus, typing @kbd{C-a} |
| 102 | exits the search and then moves to the beginning of the line. | 109 | exits the search and then moves to the beginning of the line; typing |
| 103 | @key{RET} is necessary only if the next command you want to type is a | 110 | one of the arrow keys exits the search and performs the respective |
| 104 | printing character, @key{DEL}, @key{RET}, or another character that is | 111 | movement command; etc. @key{RET} is necessary only if the next |
| 105 | special within searches (@kbd{C-q}, @kbd{C-w}, @kbd{C-r}, @kbd{C-s}, | 112 | command you want to type is a printing character, @key{DEL}, |
| 106 | @kbd{C-y}, @kbd{M-y}, @kbd{M-r}, @kbd{M-c}, @kbd{M-e}, and some others | 113 | @key{RET}, or another character that is special within searches |
| 107 | described below). | 114 | (@kbd{C-q}, @kbd{C-w}, @kbd{C-r}, @kbd{C-s}, @kbd{C-y}, @kbd{M-y}, |
| 115 | @kbd{M-r}, @kbd{M-c}, @kbd{M-e}, and some others described below). | ||
| 116 | You can fine-tune the commands that exit the search; see @ref{Not | ||
| 117 | Exiting Isearch}. | ||
| 108 | 118 | ||
| 109 | As a special exception, entering @key{RET} when the search string is | 119 | As a special exception, entering @key{RET} when the search string is |
| 110 | empty launches nonincremental search (@pxref{Nonincremental Search}). | 120 | empty launches nonincremental search (@pxref{Nonincremental Search}). |
| 121 | (This can be customized; see @ref{Search Customizations}.) | ||
| 122 | |||
| 123 | To abandon the search and return to the place where you started, | ||
| 124 | type @kbd{@key{ESC} @key{ESC} @key{ESC}} (@code{isearch-cancel}) or | ||
| 125 | @kbd{C-g C-g} (@code{isearch-abort}). | ||
| 111 | 126 | ||
| 112 | When you exit the incremental search, it adds the original value of | 127 | When you exit the incremental search, it adds the original value of |
| 113 | point to the mark ring, without activating the mark; you can thus use | 128 | point to the mark ring, without activating the mark; you can thus use |
| 114 | @kbd{C-u C-@key{SPC}} to return to where you were before beginning the | 129 | @kbd{C-u C-@key{SPC}} or @kbd{C-x C-x} to return to where you were |
| 115 | search. @xref{Mark Ring}. It only does this if the mark was not | 130 | before beginning the search. @xref{Mark Ring}. (Emacs only does this |
| 116 | already active. | 131 | if the mark was not already active; if the mark was active when you |
| 132 | started the search, both @kbd{C-u C-@key{SPC}} and @kbd{C-x C-x} will | ||
| 133 | go to the mark.) | ||
| 117 | 134 | ||
| 118 | @kindex C-r | 135 | @kindex C-r |
| 119 | @findex isearch-backward | 136 | @findex isearch-backward |
| @@ -134,7 +151,6 @@ characters with @key{DEL}. Similarly, each @kbd{C-r} in a backward | |||
| 134 | incremental search repeats the backward search. | 151 | incremental search repeats the backward search. |
| 135 | 152 | ||
| 136 | @cindex lazy search highlighting | 153 | @cindex lazy search highlighting |
| 137 | @vindex isearch-lazy-highlight | ||
| 138 | If you pause for a little while during incremental search, Emacs | 154 | If you pause for a little while during incremental search, Emacs |
| 139 | highlights all the other possible matches for the search string that | 155 | highlights all the other possible matches for the search string that |
| 140 | are present on the screen. This helps you anticipate where you can | 156 | are present on the screen. This helps you anticipate where you can |
| @@ -142,21 +158,26 @@ 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, | 158 | other matches are highlighted differently from the current match, |
| 143 | using the customizable face @code{lazy-highlight} (@pxref{Faces}). If | 159 | using the customizable face @code{lazy-highlight} (@pxref{Faces}). If |
| 144 | you don't like this feature, you can disable it by setting | 160 | you don't like this feature, you can disable it by setting |
| 145 | @code{isearch-lazy-highlight} to @code{nil}. | 161 | @code{isearch-lazy-highlight} to @code{nil}. For other customizations |
| 162 | related to highlighting matches, see @ref{Search Customizations}. | ||
| 146 | 163 | ||
| 147 | After exiting a search, you can search for the same string again by | 164 | 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 | 165 | 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 to search | 166 | invokes incremental search, and the second @kbd{C-s} means to search |
| 150 | again. Similarly, @kbd{C-r C-r} searches backward for the last | 167 | again for the last search string. Similarly, @kbd{C-r C-r} searches |
| 151 | search string. In determining the last search string, it doesn't | 168 | backward for the last search string. In determining the last search |
| 152 | matter whether the string was searched for with @kbd{C-s} or | 169 | string, it doesn't matter whether that string was searched for with |
| 153 | @kbd{C-r}. | 170 | @kbd{C-s} or @kbd{C-r}. |
| 154 | 171 | ||
| 155 | If you are searching forward but you realize you were looking for | 172 | If you are searching forward but you realize you were looking for |
| 156 | something before the starting point, type @kbd{C-r} to switch to a | 173 | something before the starting point, type @kbd{C-r} to switch to a |
| 157 | backward search, leaving the search string unchanged. Similarly, | 174 | backward search, leaving the search string unchanged. Similarly, |
| 158 | @kbd{C-s} in a backward search switches to a forward search. | 175 | @kbd{C-s} in a backward search switches to a forward search. |
| 159 | 176 | ||
| 177 | @cindex search, wrapping around | ||
| 178 | @cindex search, overwrapped | ||
| 179 | @cindex wrapped search | ||
| 180 | @cindex overwrapped search | ||
| 160 | If a search is failing and you ask to repeat it by typing another | 181 | If a search is failing and you ask to repeat it by typing another |
| 161 | @kbd{C-s}, it starts again from the beginning of the buffer. | 182 | @kbd{C-s}, it starts again from the beginning of the buffer. |
| 162 | Repeating a failing reverse search with @kbd{C-r} starts again from | 183 | Repeating a failing reverse search with @kbd{C-r} starts again from |
| @@ -169,19 +190,86 @@ you have already seen. | |||
| 169 | @cindex search ring | 190 | @cindex search ring |
| 170 | @kindex M-n @r{(Incremental search)} | 191 | @kindex M-n @r{(Incremental search)} |
| 171 | @kindex M-p @r{(Incremental search)} | 192 | @kindex M-p @r{(Incremental search)} |
| 193 | @vindex search-ring-max | ||
| 172 | To reuse earlier search strings, use the @dfn{search ring}. The | 194 | To reuse earlier search strings, use the @dfn{search ring}. The |
| 173 | commands @kbd{M-p} and @kbd{M-n} move through the ring to pick a | 195 | commands @kbd{M-p} and @kbd{M-n} move through the ring to pick a |
| 174 | search string to reuse. These commands leave the selected search ring | 196 | search string to reuse. These commands leave the selected search ring |
| 175 | element in the minibuffer, where you can edit it. | 197 | element in the minibuffer, where you can edit it. Type |
| 176 | 198 | @kbd{C-s}/@kbd{C-r} or @key{RET} to accept the string and start | |
| 199 | searching for it. The number of most recently used search strings | ||
| 200 | saved in the search ring is specified by the variable | ||
| 201 | @code{search-ring-max}, 16 by default. | ||
| 202 | |||
| 203 | @cindex incremental search, edit search string | ||
| 204 | @cindex interactively edit search string | ||
| 177 | @kindex M-e @r{(Incremental search)} | 205 | @kindex M-e @r{(Incremental search)} |
| 206 | @kindex Mouse-1 @r{in the minibuffer (Incremental Search)} | ||
| 178 | To edit the current search string in the minibuffer without | 207 | To edit the current search string in the minibuffer without |
| 179 | replacing it with items from the search ring, type @kbd{M-e}. Type @key{RET}, | 208 | replacing it with items from the search ring, type @kbd{M-e} or click |
| 180 | @kbd{C-s} or @kbd{C-r} to finish editing the string and search for it. | 209 | @kbd{Mouse-1} in the minibuffer. Type @key{RET}, @kbd{C-s} or |
| 210 | @kbd{C-r} to finish editing the string and search for it. Type | ||
| 211 | @kbd{C-f} or @kbd{@key{RIGHT}} to add to the search string characters | ||
| 212 | following point from the buffer from which you started the search. | ||
| 213 | |||
| 214 | @node Isearch Yank | ||
| 215 | @subsection Isearch Yanking | ||
| 216 | |||
| 217 | In many cases, you will want to use text at or near point as your | ||
| 218 | search string. The commands described in this subsection let you do | ||
| 219 | that conveniently. | ||
| 220 | |||
| 221 | @kindex C-w @r{(Incremental search)} | ||
| 222 | @findex isearch-yank-word-or-char | ||
| 223 | @kbd{C-w} (@code{isearch-yank-word-or-char}) appends the next | ||
| 224 | character or word at point to the search string. This is an easy way | ||
| 225 | to search for another occurrence of the text at point. (The decision | ||
| 226 | of whether to copy a character or a word is heuristic.) | ||
| 227 | |||
| 228 | @kindex M-s C-e @r{(Incremental search)} | ||
| 229 | @findex isearch-yank-line | ||
| 230 | Similarly, @kbd{M-s C-e} (@code{isearch-yank-line}) appends the rest | ||
| 231 | of the current line to the search string. If point is already at the | ||
| 232 | end of a line, it appends the next line. With a prefix argument | ||
| 233 | @var{n}, it appends the next @var{n} lines. | ||
| 234 | |||
| 235 | @kindex C-y @r{(Incremental search)} | ||
| 236 | @kindex M-y @r{(Incremental search)} | ||
| 237 | @kindex Mouse-2 @r{in the minibuffer (Incremental search)} | ||
| 238 | @findex isearch-yank-kill | ||
| 239 | @findex isearch-yank-pop | ||
| 240 | @findex isearch-yank-x-selection | ||
| 241 | Within incremental search, @kbd{C-y} (@code{isearch-yank-kill}) | ||
| 242 | appends the current kill to the search string. @kbd{M-y} | ||
| 243 | (@code{isearch-yank-pop}), if called after @kbd{C-y}, replaces that | ||
| 244 | appended text with an earlier kill, similar to the usual @kbd{M-y} | ||
| 245 | (@code{yank-pop}) command (@pxref{Yanking}). Clicking @kbd{Mouse-2} | ||
| 246 | in the echo area appends the current X selection (@pxref{Primary | ||
| 247 | Selection}) to the search string (@code{isearch-yank-x-selection}). | ||
| 248 | |||
| 249 | @kindex C-M-w @r{(Incremental search)} | ||
| 250 | @kindex C-M-y @r{(Incremental search)} | ||
| 251 | @findex isearch-del-char | ||
| 252 | @findex isearch-yank-char | ||
| 253 | @kbd{C-M-w} (@code{isearch-del-char}) deletes the last character | ||
| 254 | from the search string, and @kbd{C-M-y} (@code{isearch-yank-char}) | ||
| 255 | appends the character after point to the search string. An | ||
| 256 | alternative method to add the character after point is to enter the | ||
| 257 | minibuffer with @kbd{M-e} (@pxref{Repeat Isearch}) and type @kbd{C-f} | ||
| 258 | or @kbd{@key{RIGHT}} at the end of the search string in the | ||
| 259 | minibuffer. Each @kbd{C-f} or @kbd{@key{RIGHT}} you type adds another | ||
| 260 | character following point to the search string. | ||
| 261 | |||
| 262 | Normally, when the search is case-insensitive, text yanked into the | ||
| 263 | search string is converted to lower case, so that the search remains | ||
| 264 | case-insensitive (@pxref{Lax Search, case folding}). However, if the | ||
| 265 | value of the variable @code{search-upper-case} (@pxref{Lax Search, | ||
| 266 | search-upper-case}) is other than @code{not-yanks}, that disables this | ||
| 267 | down-casing. | ||
| 181 | 268 | ||
| 182 | @node Error in Isearch | 269 | @node Error in Isearch |
| 183 | @subsection Errors in Incremental Search | 270 | @subsection Errors in Incremental Search |
| 184 | 271 | ||
| 272 | @cindex isearch-fail face | ||
| 185 | If your string is not found at all, the echo area says @samp{Failing | 273 | If your string is not found at all, the echo area says @samp{Failing |
| 186 | I-Search}, and the cursor moves past the place where Emacs found as | 274 | I-Search}, and the cursor moves past the place where Emacs found as |
| 187 | much of your string as it could. Thus, if you search for @samp{FOOT}, | 275 | much of your string as it could. Thus, if you search for @samp{FOOT}, |
| @@ -192,12 +280,13 @@ string that failed to match is highlighted using the face | |||
| 192 | 280 | ||
| 193 | At this point, there are several things you can do. If your string | 281 | At this point, there are several things you can do. If your string |
| 194 | was mistyped, you can use @key{DEL} to erase some of it and correct | 282 | was mistyped, you can use @key{DEL} to erase some of it and correct |
| 195 | it. If you like the place you have found, you can type @key{RET} to | 283 | it, or you can type @kbd{M-e} and edit it. If you like the place you |
| 196 | remain there. Or you can type @kbd{C-g}, which removes from the | 284 | have found, you can type @key{RET} to remain there. Or you can type |
| 197 | search string the characters that could not be found (the @samp{T} in | 285 | @kbd{C-g}, which removes from the search string the characters that |
| 198 | @samp{FOOT}), leaving those that were found (the @samp{FOO} in | 286 | could not be found (the @samp{T} in @samp{FOOT}), leaving those that |
| 199 | @samp{FOOT}). A second @kbd{C-g} at that point cancels the search | 287 | were found (the @samp{FOO} in @samp{FOOT}). A second @kbd{C-g} at |
| 200 | entirely, returning point to where it was when the search started. | 288 | that point cancels the search entirely, returning point to where it |
| 289 | was when the search started. | ||
| 201 | 290 | ||
| 202 | @cindex quitting (in search) | 291 | @cindex quitting (in search) |
| 203 | @kindex C-g @r{(Incremental search)} | 292 | @kindex C-g @r{(Incremental search)} |
| @@ -216,34 +305,21 @@ search. | |||
| 216 | @node Special Isearch | 305 | @node Special Isearch |
| 217 | @subsection Special Input for Incremental Search | 306 | @subsection Special Input for Incremental Search |
| 218 | 307 | ||
| 219 | Some of the characters you type during incremental search have | 308 | In addition to characters described in the previous subsections, |
| 220 | special effects. | 309 | some of the other characters you type during incremental search have |
| 310 | special effects. They are described here. | ||
| 221 | 311 | ||
| 222 | @cindex lax space matching | 312 | To toggle lax space matching (@pxref{Lax Search, lax space |
| 223 | @kindex M-s SPC @r{(Incremental search)} | 313 | matching}), type @kbd{M-s @key{SPC}}. |
| 224 | @kindex SPC @r{(Incremental search)} | 314 | |
| 225 | @findex isearch-toggle-lax-whitespace | 315 | To toggle case sensitivity of the search, type @kbd{M-c} or |
| 226 | @vindex search-whitespace-regexp | 316 | @kbd{M-s c}. @xref{Lax Search, case folding}. If the search string |
| 227 | By default, incremental search performs @dfn{lax space matching}: | 317 | includes upper-case letters, the search is case-sensitive by default. |
| 228 | each space, or sequence of spaces, matches any sequence of one or more | 318 | |
| 229 | spaces in the text. Hence, @samp{foo bar} matches @samp{foo bar}, | 319 | To toggle whether or not the search will consider similar and |
| 230 | @samp{foo@w{ }bar}, @samp{foo@w{ }bar}, and so on (but not | 320 | equivalent characters as a match, type @kbd{M-s '}. @xref{Lax Search, |
| 231 | @samp{foobar}). More precisely, Emacs matches each sequence of space | 321 | character folding}. If the search string includes accented |
| 232 | characters in the search string to a regular expression specified by | 322 | characters, that disables character folding during that search. |
| 233 | the variable @code{search-whitespace-regexp}. For example, to make | ||
| 234 | spaces match sequences of newlines as well as spaces, set it to | ||
| 235 | @samp{"[[:space:]\n]+"}. | ||
| 236 | |||
| 237 | To toggle lax space matching, type @kbd{M-s @key{SPC}} | ||
| 238 | (@code{isearch-toggle-lax-whitespace}). To disable this feature | ||
| 239 | entirely, change @code{search-whitespace-regexp} to @code{nil}; then | ||
| 240 | each space in the search string matches exactly one space. | ||
| 241 | |||
| 242 | If the search string you entered contains only lower-case letters, | ||
| 243 | the search is case-insensitive; as long as an upper-case letter exists | ||
| 244 | in the search string, the search becomes case-sensitive. If you | ||
| 245 | delete the upper-case character from the search string, it ceases to | ||
| 246 | have this effect. @xref{Search Case}. | ||
| 247 | 323 | ||
| 248 | @cindex invisible text, searching for | 324 | @cindex invisible text, searching for |
| 249 | @kindex M-s i @r{(Incremental search)} | 325 | @kindex M-s i @r{(Incremental search)} |
| @@ -251,7 +327,17 @@ have this effect. @xref{Search Case}. | |||
| 251 | To toggle whether or not invisible text is searched, type | 327 | To toggle whether or not invisible text is searched, type |
| 252 | @kbd{M-s i} (@code{isearch-toggle-invisible}). @xref{Outline Search}. | 328 | @kbd{M-s i} (@code{isearch-toggle-invisible}). @xref{Outline Search}. |
| 253 | 329 | ||
| 254 | To search for a newline character, type @kbd{C-j}. | 330 | @kindex M-r @r{(Incremental Search)} |
| 331 | @kindex M-s r @r{(Incremental Search)} | ||
| 332 | @findex isearch-toggle-regexp | ||
| 333 | To toggle between non-regexp and regexp incremental search, type | ||
| 334 | @kbd{M-r} or @kbd{M-s r} (@code{isearch-toggle-regexp}). | ||
| 335 | @xref{Regexp Search}. | ||
| 336 | |||
| 337 | To toggle symbol mode, type @kbd{M-s _}. @xref{Symbol Search}. | ||
| 338 | |||
| 339 | To search for a newline character, type @kbd{C-j} as part of the | ||
| 340 | search string. | ||
| 255 | 341 | ||
| 256 | To search for non-@acronym{ASCII} characters, use one of the | 342 | To search for non-@acronym{ASCII} characters, use one of the |
| 257 | following methods: | 343 | following methods: |
| @@ -265,17 +351,21 @@ example, @kbd{C-q C-s} during incremental search adds the | |||
| 265 | @samp{control-S} character to the search string. | 351 | @samp{control-S} character to the search string. |
| 266 | 352 | ||
| 267 | @item | 353 | @item |
| 268 | Type @kbd{C-x 8 @key{RET}}, followed by a Unicode name or code-point. | 354 | Type @kbd{C-x 8 @key{RET}}, followed by a Unicode name or code-point |
| 269 | This adds the specified character into the search string, similar to | 355 | in hex. This adds the specified character into the search string, |
| 270 | the usual @code{insert-char} command (@pxref{Inserting Text}). | 356 | similar to the usual @code{insert-char} command (@pxref{Inserting |
| 357 | Text}). | ||
| 271 | 358 | ||
| 272 | @item | 359 | @item |
| 360 | @kindex C-^ @r{(Incremental Search)} | ||
| 361 | @findex isearch-toggle-input-method | ||
| 362 | @findex isearch-toggle-specified-input-method | ||
| 273 | Use an input method (@pxref{Input Methods}). If an input method is | 363 | Use an input method (@pxref{Input Methods}). If an input method is |
| 274 | enabled in the current buffer when you start the search, you can use | 364 | enabled in the current buffer when you start the search, the same |
| 275 | it in the search string also. While typing the search string, you can | 365 | method will be active in the minibuffer when you type the search |
| 276 | toggle the input method with @kbd{C-\} | 366 | string. While typing the search string, you can toggle the input |
| 277 | (@code{isearch-toggle-input-method}). You can also turn on a | 367 | method with @kbd{C-\} (@code{isearch-toggle-input-method}). You can |
| 278 | non-default input method with @kbd{C-^} | 368 | also turn on a non-default input method with @kbd{C-^} |
| 279 | (@code{isearch-toggle-specified-input-method}), which prompts for the | 369 | (@code{isearch-toggle-specified-input-method}), which prompts for the |
| 280 | name of the input method. When an input method is active during | 370 | name of the input method. When an input method is active during |
| 281 | incremental search, the search prompt includes the input method | 371 | incremental search, the search prompt includes the input method |
| @@ -286,13 +376,17 @@ I-search [@var{im}]: | |||
| 286 | @end example | 376 | @end example |
| 287 | 377 | ||
| 288 | @noindent | 378 | @noindent |
| 289 | @findex isearch-toggle-input-method | ||
| 290 | @findex isearch-toggle-specified-input-method | ||
| 291 | where @var{im} is the mnemonic of the active input method. Any input | 379 | where @var{im} is the mnemonic of the active input method. Any input |
| 292 | method you enable during incremental search remains enabled in the | 380 | method you enable during incremental search remains enabled in the |
| 293 | current buffer afterwards. | 381 | current buffer afterwards. |
| 294 | @end itemize | 382 | @end itemize |
| 295 | 383 | ||
| 384 | @kindex M-s o @r{(Incremental Search)} | ||
| 385 | @findex isearch-occur | ||
| 386 | Typing @kbd{M-s o} in incremental search invokes | ||
| 387 | @code{isearch-occur}, which runs @code{occur} with the current search | ||
| 388 | string. @xref{Other Repeating Search, occur}. | ||
| 389 | |||
| 296 | @kindex M-% @r{(Incremental search)} | 390 | @kindex M-% @r{(Incremental search)} |
| 297 | Typing @kbd{M-%} in incremental search invokes @code{query-replace} | 391 | Typing @kbd{M-%} in incremental search invokes @code{query-replace} |
| 298 | or @code{query-replace-regexp} (depending on search mode) with the | 392 | or @code{query-replace-regexp} (depending on search mode) with the |
| @@ -302,83 +396,72 @@ prefix argument means to replace backward. @xref{Query Replace}. | |||
| 302 | @kindex M-TAB @r{(Incremental search)} | 396 | @kindex M-TAB @r{(Incremental search)} |
| 303 | Typing @kbd{M-@key{TAB}} in incremental search invokes | 397 | Typing @kbd{M-@key{TAB}} in incremental search invokes |
| 304 | @code{isearch-complete}, which attempts to complete the search string | 398 | @code{isearch-complete}, which attempts to complete the search string |
| 305 | using the search ring as a list of completion alternatives. | 399 | using the search ring (the previous search strings you used) as a list |
| 306 | @xref{Completion}. In many operating systems, the @kbd{M-@key{TAB}} | 400 | of completion alternatives. @xref{Completion}. In many operating |
| 307 | key sequence is captured by the window manager; you then need to | 401 | systems, the @kbd{M-@key{TAB}} key sequence is captured by the window |
| 308 | rebind @code{isearch-complete} to another key sequence if you want to | 402 | manager; you then need to rebind @code{isearch-complete} to another |
| 309 | use it (@pxref{Rebinding}). | 403 | key sequence if you want to use it (@pxref{Rebinding}). |
| 310 | 404 | ||
| 405 | @kindex M-s h r @r{(Incremental Search)} | ||
| 406 | @findex isearch-highlight-regexp | ||
| 407 | You can exit the search while leaving the matches for the last | ||
| 408 | search string highlighted on display. To this end, type @kbd{M-s h r} | ||
| 409 | (@code{isearch-highlight-regexp}), which will run | ||
| 410 | @code{highlight-regexp} (@pxref{Highlight Interactively}) passing | ||
| 411 | it the regexp derived from the last search string and prompting you | ||
| 412 | for the face to use for highlighting. To remove the highlighting, | ||
| 413 | type @kbd{M-s h u} (@code{unhighlight-regexp}). | ||
| 414 | |||
| 415 | @cindex incremental search, help on special keys | ||
| 416 | @kindex C-h C-h @r{(Incremental Search)} | ||
| 417 | @findex isearch-help-map | ||
| 311 | @vindex isearch-mode-map | 418 | @vindex isearch-mode-map |
| 312 | When incremental search is active, you can type @kbd{C-h C-h} to | 419 | When incremental search is active, you can type @kbd{C-h C-h} |
| 313 | access interactive help options, including a list of special key | 420 | (@code{isearch-help-map}) to access interactive help options, |
| 314 | bindings. These key bindings are part of the keymap | 421 | including a list of special key bindings. These key bindings are part |
| 315 | @code{isearch-mode-map} (@pxref{Keymaps}). | 422 | of the keymap @code{isearch-mode-map} (@pxref{Keymaps}). |
| 316 | |||
| 317 | @node Isearch Yank | ||
| 318 | @subsection Isearch Yanking | ||
| 319 | |||
| 320 | @kindex C-y @r{(Incremental search)} | ||
| 321 | @kindex M-y @r{(Incremental search)} | ||
| 322 | @findex isearch-yank-kill | ||
| 323 | @findex isearch-yank-pop | ||
| 324 | Within incremental search, @kbd{C-y} (@code{isearch-yank-kill}) | ||
| 325 | appends the current kill to the search string. @kbd{M-y} | ||
| 326 | (@code{isearch-yank-pop}), if called after @kbd{C-y}, replaces that | ||
| 327 | appended text with an earlier kill, similar to the usual @kbd{M-y} | ||
| 328 | (@code{yank-pop}) command (@pxref{Yanking}). @kbd{Mouse-2} appends | ||
| 329 | the current X selection (@pxref{Primary Selection}). | ||
| 330 | |||
| 331 | @kindex C-w @r{(Incremental search)} | ||
| 332 | @findex isearch-yank-word-or-char | ||
| 333 | @kbd{C-w} (@code{isearch-yank-word-or-char}) appends the next | ||
| 334 | character or word at point to the search string. This is an easy way | ||
| 335 | to search for another occurrence of the text at point. (The decision | ||
| 336 | of whether to copy a character or a word is heuristic.) | ||
| 337 | |||
| 338 | @kindex M-s C-e @r{(Incremental search)} | ||
| 339 | @findex isearch-yank-line | ||
| 340 | Similarly, @kbd{M-s C-e} (@code{isearch-yank-line}) appends the rest | ||
| 341 | of the current line to the search string. If point is already at the | ||
| 342 | end of a line, it appends the next line. With a prefix argument | ||
| 343 | @var{n}, it appends the next @var{n} lines. | ||
| 344 | |||
| 345 | If the search is currently case-insensitive, both @kbd{C-w} and | ||
| 346 | @kbd{M-s C-e} convert the text they copy to lower case, so that the | ||
| 347 | search remains case-insensitive. | ||
| 348 | |||
| 349 | @kindex C-M-w @r{(Incremental search)} | ||
| 350 | @kindex C-M-y @r{(Incremental search)} | ||
| 351 | @findex isearch-del-char | ||
| 352 | @findex isearch-yank-char | ||
| 353 | @kbd{C-M-w} (@code{isearch-del-char}) deletes the last character | ||
| 354 | from the search string, and @kbd{C-M-y} (@code{isearch-yank-char}) | ||
| 355 | appends the character after point to the search string. An | ||
| 356 | alternative method to add the character after point is to enter the | ||
| 357 | minibuffer with @kbd{M-e} (@pxref{Repeat Isearch}) and type @kbd{C-f} | ||
| 358 | at the end of the search string in the minibuffer. | ||
| 359 | 423 | ||
| 360 | @node Not Exiting Isearch | 424 | @node Not Exiting Isearch |
| 361 | @subsection Not Exiting Incremental Search | 425 | @subsection Not Exiting Incremental Search |
| 362 | 426 | ||
| 363 | This subsection describes two categories of commands which you can | 427 | This subsection describes how to control whether typing a command not |
| 364 | type without exiting the current incremental search, even though they | 428 | specifically meaningful is searches exits the search before executing |
| 365 | are not themselves part of incremental search. | 429 | the command. It also describes two categories of commands which you |
| 430 | can type without exiting the current incremental search, even though | ||
| 431 | they are not themselves part of incremental search. | ||
| 432 | |||
| 433 | @vindex search-exit-option | ||
| 434 | Normally, typing a command that is not bound by the incremental | ||
| 435 | search exits the search before executing the command. Thus, the | ||
| 436 | command operates on the buffer from which you invoked the search. | ||
| 437 | However, if you customize the variable @code{search-exit-option} to a | ||
| 438 | @code{nil} value, the characters which you type that are not | ||
| 439 | interpreted by the incremental search are simply appended to the | ||
| 440 | search string. This is so you could include in the search string | ||
| 441 | control characters, such as @kbd{C-a}, that would normally exit the | ||
| 442 | search and invoke the command bound to them on the buffer. | ||
| 366 | 443 | ||
| 367 | @table @asis | 444 | @table @asis |
| 368 | @item Prefix Arguments | 445 | @item Prefix Arguments |
| 446 | @cindex prefix argument commands, during incremental search | ||
| 369 | @vindex isearch-allow-prefix | 447 | @vindex isearch-allow-prefix |
| 370 | In incremental search, when you enter a prefix argument | 448 | In incremental search, when you type a command that specifies a |
| 371 | (@pxref{Arguments}), by default it will apply either to the next | 449 | prefix argument (@pxref{Arguments}), by default it will apply either |
| 372 | action in the search or to the command that exits the search. | 450 | to the next action in the search or to the command that exits the |
| 451 | search. In other words, entering a prefix argument will not by itself | ||
| 452 | terminate the search. | ||
| 373 | 453 | ||
| 374 | In previous versions of Emacs, entering a prefix argument always | 454 | In previous versions of Emacs, entering a prefix argument always |
| 375 | terminated the search. You can revert to this behavior by setting the | 455 | terminated the search. You can revert to this behavior by setting the |
| 376 | variable @code{isearch-allow-prefix} to @code{nil}. | 456 | variable @code{isearch-allow-prefix} to @code{nil}. |
| 377 | 457 | ||
| 378 | When @code{isearch-allow-scroll} is non-@code{nil} (see below), | 458 | When @code{isearch-allow-scroll} is non-@code{nil} (see below), |
| 379 | prefix arguments always have the default behavior described above. | 459 | prefix arguments always have the default behavior described above, |
| 460 | i.e., they don't terminate the search, even if | ||
| 461 | @code{isearch-allow-prefix} is @code{nil}. | ||
| 380 | 462 | ||
| 381 | @item Scrolling Commands | 463 | @item Scrolling Commands |
| 464 | @cindex scrolling commands, during incremental search | ||
| 382 | @vindex isearch-allow-scroll | 465 | @vindex isearch-allow-scroll |
| 383 | Normally, scrolling commands exit incremental search. If you change | 466 | Normally, scrolling commands exit incremental search. If you change |
| 384 | the variable @code{isearch-allow-scroll} to a non-@code{nil} value, | 467 | the variable @code{isearch-allow-scroll} to a non-@code{nil} value, |
| @@ -390,12 +473,14 @@ prefix arguments to these commands in the usual way. This feature | |||
| 390 | won't let you scroll the current match out of visibility, however. | 473 | won't let you scroll the current match out of visibility, however. |
| 391 | 474 | ||
| 392 | The @code{isearch-allow-scroll} feature also affects some other | 475 | The @code{isearch-allow-scroll} feature also affects some other |
| 393 | commands, such as @kbd{C-x 2} (@code{split-window-below}) and @kbd{C-x | 476 | commands, such as @kbd{C-x 2} (@code{split-window-below}) and |
| 394 | ^} (@code{enlarge-window}), which don't exactly scroll but do affect | 477 | @kbd{C-x ^} (@code{enlarge-window}), which don't exactly scroll but do |
| 395 | where the text appears on the screen. It applies to any command whose | 478 | affect where the text appears on the screen. It applies to any |
| 396 | name has a non-@code{nil} @code{isearch-scroll} property. So you can | 479 | command whose name has a non-@code{nil} @code{isearch-scroll} |
| 397 | control which commands are affected by changing these properties. | 480 | property. So you can control which commands are affected by changing |
| 398 | 481 | these properties. | |
| 482 | |||
| 483 | @cindex prevent commands from exiting incremental search | ||
| 399 | For example, to make @kbd{C-h l} usable within an incremental search | 484 | For example, to make @kbd{C-h l} usable within an incremental search |
| 400 | in all future Emacs sessions, use @kbd{C-h c} to find what command it | 485 | in all future Emacs sessions, use @kbd{C-h c} to find what command it |
| 401 | runs (@pxref{Key Help}), which is @code{view-lossage}. Then you can | 486 | runs (@pxref{Key Help}), which is @code{view-lossage}. Then you can |
| @@ -409,7 +494,8 @@ put the following line in your init file (@pxref{Init File}): | |||
| 409 | This feature can be applied to any command that doesn't permanently | 494 | This feature can be applied to any command that doesn't permanently |
| 410 | change point, the buffer contents, the match data, the current buffer, | 495 | change point, the buffer contents, the match data, the current buffer, |
| 411 | or the selected window and frame. The command must not itself attempt | 496 | or the selected window and frame. The command must not itself attempt |
| 412 | an incremental search. | 497 | an incremental search. This feature is disabled if |
| 498 | @code{isearch-allow-scroll} is @code{nil} (which it is by default). | ||
| 413 | @end table | 499 | @end table |
| 414 | 500 | ||
| 415 | @node Isearch Minibuffer | 501 | @node Isearch Minibuffer |
| @@ -475,11 +561,13 @@ search matches any sequence of those two words separated by one or | |||
| 475 | more spaces, newlines, or other punctuation characters. This is | 561 | more spaces, newlines, or other punctuation characters. This is |
| 476 | particularly useful for searching text documents, because you don't | 562 | particularly useful for searching text documents, because you don't |
| 477 | have to worry whether the words you are looking for are separated by | 563 | have to worry whether the words you are looking for are separated by |
| 478 | newlines or spaces. | 564 | newlines or spaces. Note that major modes for programming languages |
| 565 | or other specialized modes can modify the definition of a word to suit | ||
| 566 | their syntactic needs. | ||
| 479 | 567 | ||
| 480 | @table @kbd | 568 | @table @kbd |
| 481 | @item M-s w | 569 | @item M-s w |
| 482 | If incremental search is active, toggle word search mode | 570 | If incremental search is active, toggle word search mode |
| 483 | (@code{isearch-toggle-word}); otherwise, begin an incremental forward | 571 | (@code{isearch-toggle-word}); otherwise, begin an incremental forward |
| 484 | word search (@code{isearch-forward-word}). | 572 | word search (@code{isearch-forward-word}). |
| 485 | @item M-s w @key{RET} @var{words} @key{RET} | 573 | @item M-s w @key{RET} @var{words} @key{RET} |
| @@ -514,6 +602,14 @@ so that the matching can proceed incrementally as you type. This | |||
| 514 | additional laxity does not apply to the lazy highlight | 602 | additional laxity does not apply to the lazy highlight |
| 515 | (@pxref{Incremental Search}), which always matches whole words. | 603 | (@pxref{Incremental Search}), which always matches whole words. |
| 516 | 604 | ||
| 605 | @kindex M-s M-w | ||
| 606 | @findex eww-search-word | ||
| 607 | @vindex eww-search-prefix | ||
| 608 | Search the Web for the text in region. This command performs an | ||
| 609 | Internet search for the words in region using the search engine whose | ||
| 610 | @acronym{URL} is specified by the variable @code{eww-search-prefix}. | ||
| 611 | @xref{Basics, EWW, , eww, The Emacs Web Wowser Manual}. | ||
| 612 | |||
| 517 | @node Symbol Search | 613 | @node Symbol Search |
| 518 | @section Symbol Search | 614 | @section Symbol Search |
| 519 | @cindex symbol search | 615 | @cindex symbol search |
| @@ -529,6 +625,7 @@ searching source code. | |||
| 529 | 625 | ||
| 530 | @table @kbd | 626 | @table @kbd |
| 531 | @item M-s _ | 627 | @item M-s _ |
| 628 | @findex isearch-toggle-symbol | ||
| 532 | If incremental search is active, toggle symbol search mode | 629 | If incremental search is active, toggle symbol search mode |
| 533 | (@code{isearch-toggle-symbol}); otherwise, begin an incremental | 630 | (@code{isearch-toggle-symbol}); otherwise, begin an incremental |
| 534 | forward symbol search (@code{isearch-forward-symbol}). | 631 | forward symbol search (@code{isearch-forward-symbol}). |
| @@ -595,13 +692,16 @@ for. To search backward for a regexp, use @kbd{C-M-r} | |||
| 595 | (@code{isearch-backward-regexp}), @kbd{C-r} with a prefix argument, | 692 | (@code{isearch-backward-regexp}), @kbd{C-r} with a prefix argument, |
| 596 | or @kbd{M-r} within a backward incremental search. | 693 | or @kbd{M-r} within a backward incremental search. |
| 597 | 694 | ||
| 695 | @vindex regexp-search-ring-max | ||
| 598 | All of the special key sequences in an ordinary incremental search | 696 | All of the special key sequences in an ordinary incremental search |
| 599 | do similar things in an incremental regexp search. For instance, | 697 | (@pxref{Special Isearch}) do similar things in an incremental regexp |
| 600 | typing @kbd{C-s} immediately after starting the search retrieves the | 698 | search. For instance, typing @kbd{C-s} immediately after starting the |
| 601 | last incremental search regexp used and searches forward for it. | 699 | search retrieves the last incremental search regexp used and searches |
| 602 | Incremental regexp and non-regexp searches have independent defaults. | 700 | forward for it. Incremental regexp and non-regexp searches have |
| 603 | They also have separate search rings, which you can access with | 701 | independent defaults. They also have separate search rings, which you |
| 604 | @kbd{M-p} and @kbd{M-n}. | 702 | can access with @kbd{M-p} and @kbd{M-n}. The maximum number of search |
| 703 | regexps saved in the search ring is determined by the value of | ||
| 704 | @code{regexp-search-ring-max}, 16 by default. | ||
| 605 | 705 | ||
| 606 | Unlike ordinary incremental search, incremental regexp search | 706 | Unlike ordinary incremental search, incremental regexp search |
| 607 | do not use lax space matching by default. To toggle this feature | 707 | do not use lax space matching by default. To toggle this feature |
| @@ -1030,21 +1130,67 @@ This contains two parts in succession: a character set matching | |||
| 1030 | period, @samp{?}, or @samp{!}, and a character set matching | 1130 | period, @samp{?}, or @samp{!}, and a character set matching |
| 1031 | close-brackets, quotes, or parentheses, repeated zero or more times. | 1131 | close-brackets, quotes, or parentheses, repeated zero or more times. |
| 1032 | 1132 | ||
| 1033 | @node Search Case | 1133 | @node Lax Search |
| 1034 | @section Searching and Case | 1134 | @section Lax Matching During Searching |
| 1135 | |||
| 1136 | @cindex lax search | ||
| 1137 | @cindex character equivalence in search | ||
| 1138 | Normally, you'd want search commands to disregard certain minor | ||
| 1139 | differences between the search string you types and the text being | ||
| 1140 | searched. For example, sequences of whitespace characters of | ||
| 1141 | different length are normally perceived as equivalent; letter-case | ||
| 1142 | differences usually don't matter; etc. This is known as | ||
| 1143 | @dfn{character equivalence}. | ||
| 1144 | |||
| 1145 | This section describes the Emacs lax search features, and how to | ||
| 1146 | tailor them to your needs. | ||
| 1035 | 1147 | ||
| 1148 | @cindex lax space matching in search | ||
| 1149 | @kindex M-s SPC @r{(Incremental search)} | ||
| 1150 | @kindex SPC @r{(Incremental search)} | ||
| 1151 | @findex isearch-toggle-lax-whitespace | ||
| 1152 | @vindex search-whitespace-regexp | ||
| 1153 | By default, search commands perform @dfn{lax space matching}: | ||
| 1154 | each space, or sequence of spaces, matches any sequence of one or more | ||
| 1155 | whitespace characters in the text. (Incremental regexp search has a | ||
| 1156 | separate default; see @ref{Regexp Search}.) Hence, @samp{foo bar} | ||
| 1157 | matches @samp{foo bar}, @samp{foo@w{ }bar}, @samp{foo@w{ }bar}, and so | ||
| 1158 | on (but not @samp{foobar}). More precisely, Emacs matches each | ||
| 1159 | sequence of space characters in the search string to a regular | ||
| 1160 | expression specified by the variable @code{search-whitespace-regexp}. | ||
| 1161 | For example, to make spaces match sequences of newlines as well as | ||
| 1162 | spaces, set it to @samp{"[[:space:]\n]+"}. The default value of this | ||
| 1163 | variable depends on the buffer's major mode; most major modes classify | ||
| 1164 | spaces, tabs, and formfeed characters as whitespace. | ||
| 1165 | |||
| 1166 | If you want whitespace characters to match exactly, you can turn lax | ||
| 1167 | space matching by typing @kbd{M-s @key{SPC}} | ||
| 1168 | (@code{isearch-toggle-lax-whitespace}) within an incremental search. | ||
| 1169 | Another @kbd{M-s @key{SPC}} turns lax space matching back on. To | ||
| 1170 | disable this feature entirely, change @code{search-whitespace-regexp} | ||
| 1171 | to @code{nil}; then each space in the search string matches exactly | ||
| 1172 | one space. | ||
| 1173 | |||
| 1174 | @cindex case folding in search | ||
| 1175 | @cindex case-sensitivity and search | ||
| 1036 | Searches in Emacs normally ignore the case of the text they are | 1176 | Searches in Emacs normally ignore the case of the text they are |
| 1037 | searching through, if you specify the text in lower case. Thus, if | 1177 | searching through, if you specify the search string in lower case. |
| 1038 | you specify searching for @samp{foo}, then @samp{Foo} and @samp{foo} | 1178 | Thus, if you specify searching for @samp{foo}, then @samp{Foo} and |
| 1039 | also match. Regexps, and in particular character sets, behave | 1179 | @samp{foo} also match. Regexps, and in particular character sets, |
| 1040 | likewise: @samp{[ab]} matches @samp{a} or @samp{A} or @samp{b} or | 1180 | behave likewise: @samp{[ab]} matches @samp{a} or @samp{A} or @samp{b} |
| 1041 | @samp{B}. | 1181 | or @samp{B}. This feature is known as @dfn{case folding}, and it is |
| 1042 | 1182 | supported in both incremental and non-incremental search modes. | |
| 1043 | An upper-case letter anywhere in the incremental search string makes | 1183 | |
| 1044 | the search case-sensitive. Thus, searching for @samp{Foo} does not find | 1184 | @vindex search-upper-case |
| 1045 | @samp{foo} or @samp{FOO}. This applies to regular expression search as | 1185 | An upper-case letter anywhere in the search string makes the search |
| 1046 | well as to string search. The effect ceases if you delete the | 1186 | case-sensitive. Thus, searching for @samp{Foo} does not find |
| 1047 | upper-case letter from the search string. | 1187 | @samp{foo} or @samp{FOO}. This applies to regular expression search |
| 1188 | as well as to string search. The effect ceases if you delete the | ||
| 1189 | upper-case letter from the search string. The variable | ||
| 1190 | @code{search-upper-case} controls this: if it is non-@code{nil} (the | ||
| 1191 | default), an upper-case character in the search string make the search | ||
| 1192 | case-sensitive; setting it to @code{nil} disables this effect of | ||
| 1193 | upper-case characters. | ||
| 1048 | 1194 | ||
| 1049 | @vindex case-fold-search | 1195 | @vindex case-fold-search |
| 1050 | If you set the variable @code{case-fold-search} to @code{nil}, then | 1196 | If you set the variable @code{case-fold-search} to @code{nil}, then |
| @@ -1055,12 +1201,14 @@ This variable applies to nonincremental searches also, including those | |||
| 1055 | performed by the replace commands (@pxref{Replace}) and the minibuffer | 1201 | performed by the replace commands (@pxref{Replace}) and the minibuffer |
| 1056 | history matching commands (@pxref{Minibuffer History}). | 1202 | history matching commands (@pxref{Minibuffer History}). |
| 1057 | 1203 | ||
| 1058 | @c isearch-toggle-case-fold | 1204 | @kindex M-c @r{(Incremental search)} |
| 1059 | Typing @kbd{M-c} within an incremental search toggles the case | 1205 | @kindex M-s c @r{(Incremental search)} |
| 1060 | sensitivity of that search. The effect does not extend beyond the | 1206 | @findex isearch-toggle-case-fold |
| 1061 | current incremental search to the next one, but it does override the | 1207 | Typing @kbd{M-c} or @kbd{M-s c} (@code{isearch-toggle-case-fold}) |
| 1062 | effect of adding or removing an upper-case letter in the current | 1208 | within an incremental search toggles the case sensitivity of that |
| 1063 | search. | 1209 | search. The effect does not extend beyond the current incremental |
| 1210 | search to the next one, but it does override the effect of adding or | ||
| 1211 | removing an upper-case letter in the current search. | ||
| 1064 | 1212 | ||
| 1065 | Several related variables control case-sensitivity of searching and | 1213 | Several related variables control case-sensitivity of searching and |
| 1066 | matching for specific commands or activities. For instance, | 1214 | matching for specific commands or activities. For instance, |
| @@ -1068,6 +1216,46 @@ matching for specific commands or activities. For instance, | |||
| 1068 | @code{find-tag}. To find these variables, do @kbd{M-x | 1216 | @code{find-tag}. To find these variables, do @kbd{M-x |
| 1069 | apropos-variable @key{RET} case-fold-search @key{RET}}. | 1217 | apropos-variable @key{RET} case-fold-search @key{RET}}. |
| 1070 | 1218 | ||
| 1219 | @cindex character folding in search | ||
| 1220 | @cindex equivalent character sequences | ||
| 1221 | Case folding disregards case distinctions between characters, making | ||
| 1222 | upper-case characters match lower-case variants, and vice versa. A | ||
| 1223 | generalization of case folding is @dfn{character folding}, which | ||
| 1224 | disregards wider classes of distinctions between similar characters. | ||
| 1225 | For instance, under character folding the letter @code{a} will match | ||
| 1226 | all of its accented cousins like @code{@"a} and @code{@'a}, i.e., the | ||
| 1227 | match disregards the diacriticals that distinguish between these | ||
| 1228 | variants. In addition, @code{a} will match other characters that | ||
| 1229 | resemble it, or have it as part of their graphical representation, | ||
| 1230 | such as @sc{u+249c parenthesized latin small letter a} and @sc{u+2100 | ||
| 1231 | account of} (which looks like a small @code{a} over @code{c}). | ||
| 1232 | Similarly, the @acronym{ASCII} double-quote character @code{"} will | ||
| 1233 | match all the other variants of double quotes defined by the Unicode | ||
| 1234 | standard. | ||
| 1235 | @ignore @c FIXME: This doesn't work. Should it? | ||
| 1236 | Finally, character folding can make a sequence of one or | ||
| 1237 | more characters match another sequence of a different length: for | ||
| 1238 | example, the sequence of two characters @code{ae} matches the ligature | ||
| 1239 | @code{@ae{}}. | ||
| 1240 | @end ignore | ||
| 1241 | Character sequences that match under character folding are called | ||
| 1242 | @dfn{equivalent}. | ||
| 1243 | |||
| 1244 | @kindex M-s ' @r{(Incremental Search)} | ||
| 1245 | @findex isearch-toggle-character-fold | ||
| 1246 | Searches in Emacs normally perform character folding, thus matching | ||
| 1247 | equivalent character sequences. You can disable this behavior by | ||
| 1248 | customizing the variable @code{search-default-regexp-mode} to the | ||
| 1249 | @code{nil} value. @xref{Search Customizations}. Within an | ||
| 1250 | incremental search, typing @kbd{M-s '} | ||
| 1251 | (@code{isearch-toggle-character-fold}) toggles character folding, but | ||
| 1252 | only for that search. | ||
| 1253 | |||
| 1254 | Like with case folding, typing an explicit variant of a character, | ||
| 1255 | such as @code{@"a}, as part of the search string disables character | ||
| 1256 | folding for that search. If you delete such a character from the | ||
| 1257 | search string, this effect ceases. | ||
| 1258 | |||
| 1071 | @node Replace | 1259 | @node Replace |
| 1072 | @section Replacement Commands | 1260 | @section Replacement Commands |
| 1073 | @cindex replacement | 1261 | @cindex replacement |
| @@ -1078,7 +1266,8 @@ apropos-variable @key{RET} case-fold-search @key{RET}}. | |||
| 1078 | Emacs provides several commands for performing search-and-replace | 1266 | Emacs provides several commands for performing search-and-replace |
| 1079 | operations. In addition to the simple @kbd{M-x replace-string} | 1267 | operations. In addition to the simple @kbd{M-x replace-string} |
| 1080 | command, there is @kbd{M-%} (@code{query-replace}), which presents | 1268 | command, there is @kbd{M-%} (@code{query-replace}), which presents |
| 1081 | each occurrence of the pattern and asks you whether to replace it. | 1269 | each occurrence of the search pattern and asks you whether to replace |
| 1270 | it. | ||
| 1082 | 1271 | ||
| 1083 | The replace commands normally operate on the text from point to the | 1272 | The replace commands normally operate on the text from point to the |
| 1084 | end of the buffer. When the region is active, they operate on it | 1273 | end of the buffer. When the region is active, they operate on it |
| @@ -1087,17 +1276,11 @@ instead (@pxref{Mark}). The basic replace commands replace one | |||
| 1087 | is possible to perform several replacements in parallel, using the | 1276 | is possible to perform several replacements in parallel, using the |
| 1088 | command @code{expand-region-abbrevs} (@pxref{Expanding Abbrevs}). | 1277 | command @code{expand-region-abbrevs} (@pxref{Expanding Abbrevs}). |
| 1089 | 1278 | ||
| 1090 | @vindex replace-lax-whitespace | ||
| 1091 | Unlike incremental search, the replacement commands do not use lax | ||
| 1092 | space matching (@pxref{Special Isearch}) by default. To enable lax | ||
| 1093 | space matching for replacement, change the variable | ||
| 1094 | @code{replace-lax-whitespace} to @code{t}. (This only affects how | ||
| 1095 | Emacs finds the text to replace, not the replacement text.) | ||
| 1096 | |||
| 1097 | @menu | 1279 | @menu |
| 1098 | * Unconditional Replace:: Replacing all matches for a string. | 1280 | * Unconditional Replace:: Replacing all matches for a string. |
| 1099 | * Regexp Replace:: Replacing all matches for a regexp. | 1281 | * Regexp Replace:: Replacing all matches for a regexp. |
| 1100 | * Replacement and Case:: How replacements preserve case of letters. | 1282 | * Replacement and Lax Matches:: |
| 1283 | Lax searching for text to replace. | ||
| 1101 | * Query Replace:: How to use querying. | 1284 | * Query Replace:: How to use querying. |
| 1102 | @end menu | 1285 | @end menu |
| 1103 | 1286 | ||
| @@ -1128,8 +1311,8 @@ activating the mark; use @kbd{C-u C-@key{SPC}} to move back there. | |||
| 1128 | A prefix argument restricts replacement to matches that are | 1311 | A prefix argument restricts replacement to matches that are |
| 1129 | surrounded by word boundaries. | 1312 | surrounded by word boundaries. |
| 1130 | 1313 | ||
| 1131 | @xref{Replacement and Case}, for details about case-sensitivity in | 1314 | @xref{Replacement and Lax Matches}, for details about |
| 1132 | replace commands. | 1315 | case-sensitivity in replace commands. |
| 1133 | 1316 | ||
| 1134 | @node Regexp Replace | 1317 | @node Regexp Replace |
| 1135 | @subsection Regexp Replacement | 1318 | @subsection Regexp Replacement |
| @@ -1137,7 +1320,7 @@ replace commands. | |||
| 1137 | 1320 | ||
| 1138 | The @kbd{M-x replace-string} command replaces exact matches for a | 1321 | The @kbd{M-x replace-string} command replaces exact matches for a |
| 1139 | single string. The similar command @kbd{M-x replace-regexp} replaces | 1322 | single string. The similar command @kbd{M-x replace-regexp} replaces |
| 1140 | any match for a specified pattern. | 1323 | any match for a specified regular expression pattern (@pxref{Regexps}). |
| 1141 | 1324 | ||
| 1142 | @table @kbd | 1325 | @table @kbd |
| 1143 | @item M-x replace-regexp @key{RET} @var{regexp} @key{RET} @var{newstring} @key{RET} | 1326 | @item M-x replace-regexp @key{RET} @var{regexp} @key{RET} @var{newstring} @key{RET} |
| @@ -1218,9 +1401,28 @@ M-x replace-regexp @key{RET} ^.\@{0,72\@}$ @key{RET} | |||
| 1218 | \,(format "%-72sABC%05d" \& \#) @key{RET} | 1401 | \,(format "%-72sABC%05d" \& \#) @key{RET} |
| 1219 | @end example | 1402 | @end example |
| 1220 | 1403 | ||
| 1221 | @node Replacement and Case | 1404 | @node Replacement and Lax Matches |
| 1222 | @subsection Replace Commands and Case | 1405 | @subsection Replace Commands and Lax Matches |
| 1406 | |||
| 1407 | This subsection describes the behavior of replace commands with | ||
| 1408 | respect to lax matches (@pxref{Lax Search}) and how to customize it. | ||
| 1409 | In general, replace commands mostly default to stricter matching than | ||
| 1410 | their search counterparts. | ||
| 1223 | 1411 | ||
| 1412 | @cindex lax space matching in replace commands | ||
| 1413 | @vindex replace-lax-whitespace | ||
| 1414 | Unlike incremental search, the replacement commands do not use lax | ||
| 1415 | space matching (@pxref{Lax Search, lax space matching}) by default. | ||
| 1416 | To enable lax space matching for replacement, change the variable | ||
| 1417 | @code{replace-lax-whitespace} to non-@code{nil}. (This only affects | ||
| 1418 | how Emacs finds the text to replace, not the replacement text.) | ||
| 1419 | |||
| 1420 | @vindex replace-regexp-lax-whitespace | ||
| 1421 | A companion variable @code{replace-regexp-lax-whitespace} controls | ||
| 1422 | whether @code{query-replace-regexp} uses lax whitespace matching when | ||
| 1423 | searching for patterns. | ||
| 1424 | |||
| 1425 | @cindex case folding in replace commands | ||
| 1224 | If the first argument of a replace command is all lower case, the | 1426 | If the first argument of a replace command is all lower case, the |
| 1225 | command ignores case while searching for occurrences to | 1427 | command ignores case while searching for occurrences to |
| 1226 | replace---provided @code{case-fold-search} is non-@code{nil}. If | 1428 | replace---provided @code{case-fold-search} is non-@code{nil}. If |
| @@ -1250,6 +1452,14 @@ exactly as given, with no case conversion. Likewise, if either | |||
| 1250 | @code{case-replace} or @code{case-fold-search} is set to @code{nil}, | 1452 | @code{case-replace} or @code{case-fold-search} is set to @code{nil}, |
| 1251 | replacement is done without case conversion. | 1453 | replacement is done without case conversion. |
| 1252 | 1454 | ||
| 1455 | @cindex character folding in replace commands | ||
| 1456 | The replacement commands by default do not use character folding | ||
| 1457 | (@pxref{Lax Search, character folding}) when looking for the text to | ||
| 1458 | replace. To enable character folding for matching, set the variable | ||
| 1459 | @code{replace-character-fold} to a non-@code{nil} value. (This | ||
| 1460 | setting does not affect the replacement text, only how Emacs finds the | ||
| 1461 | text to replace.) | ||
| 1462 | |||
| 1253 | @node Query Replace | 1463 | @node Query Replace |
| 1254 | @subsection Query Replace | 1464 | @subsection Query Replace |
| 1255 | @cindex query replace | 1465 | @cindex query replace |
| @@ -1270,9 +1480,9 @@ occurrence and asks you whether to replace it. Aside from querying, | |||
| 1270 | @code{query-replace} works just like @code{replace-string} | 1480 | @code{query-replace} works just like @code{replace-string} |
| 1271 | (@pxref{Unconditional Replace}). In particular, it preserves case | 1481 | (@pxref{Unconditional Replace}). In particular, it preserves case |
| 1272 | provided @code{case-replace} is non-@code{nil}, as it normally is | 1482 | provided @code{case-replace} is non-@code{nil}, as it normally is |
| 1273 | (@pxref{Replacement and Case}). A numeric argument means to consider | 1483 | (@pxref{Replacement and Lax Matches}). A numeric argument means to |
| 1274 | only occurrences that are bounded by word-delimiter characters. A | 1484 | consider only occurrences that are bounded by word-delimiter |
| 1275 | negative prefix argument replaces backward. | 1485 | characters. A negative prefix argument replaces backward. |
| 1276 | 1486 | ||
| 1277 | @kindex C-M-% | 1487 | @kindex C-M-% |
| 1278 | @findex query-replace-regexp | 1488 | @findex query-replace-regexp |
| @@ -1280,18 +1490,38 @@ negative prefix argument replaces backward. | |||
| 1280 | It works like @code{replace-regexp} except that it queries | 1490 | It works like @code{replace-regexp} except that it queries |
| 1281 | like @code{query-replace}. | 1491 | like @code{query-replace}. |
| 1282 | 1492 | ||
| 1493 | @vindex query-replace-from-to-separator | ||
| 1494 | You can reuse earlier replacements with these commands. When | ||
| 1495 | @code{query-replace} or @code{query-replace-regexp} prompts for the | ||
| 1496 | search string, use @kbd{M-p} and @kbd{M-n} to show previous | ||
| 1497 | replacements in the form @samp{@var{from} -> @var{to}}, where | ||
| 1498 | @var{from} is the search pattern, @var{to} is its replacement, and the | ||
| 1499 | separator between them is determined by the value of the variable | ||
| 1500 | @code{query-replace-from-to-separator}. Type @key{RET} to select the | ||
| 1501 | desired replacement. | ||
| 1502 | |||
| 1283 | @cindex faces for highlighting query replace | 1503 | @cindex faces for highlighting query replace |
| 1284 | @cindex query-replace face | 1504 | @cindex query-replace face |
| 1285 | @cindex lazy-highlight face | 1505 | @cindex lazy-highlight face, in replace |
| 1506 | @vindex query-replace-highlight | ||
| 1507 | @vindex query-replace-lazy-highlight | ||
| 1508 | @vindex query-replace-show-replacement | ||
| 1286 | These commands highlight the current match using the face | 1509 | These commands highlight the current match using the face |
| 1287 | @code{query-replace}. They highlight other matches using | 1510 | @code{query-replace}. You can disable this highlight by setting the |
| 1288 | @code{lazy-highlight} just like incremental search (@pxref{Incremental | 1511 | variable @code{query-replace-highlight} to @code{nil}. They highlight |
| 1289 | Search}). By default, @code{query-replace-regexp} will show the | 1512 | other matches using @code{lazy-highlight} just like incremental search |
| 1290 | substituted replacement string for the current match in the | 1513 | (@pxref{Incremental Search}); this can be disabled by setting |
| 1291 | minibuffer. If you want to keep special sequences @samp{\&} and | 1514 | @code{query-replace-lazy-highlight} to @code{nil}. By default, |
| 1292 | @samp{\@var{n}} unexpanded, customize | 1515 | @code{query-replace-regexp} will show the substituted replacement |
| 1516 | string for the current match in the minibuffer. If you want to keep | ||
| 1517 | special sequences @samp{\&} and @samp{\@var{n}} unexpanded, customize | ||
| 1293 | @code{query-replace-show-replacement} variable. | 1518 | @code{query-replace-show-replacement} variable. |
| 1294 | 1519 | ||
| 1520 | @vindex query-replace-skip-read-only | ||
| 1521 | The variable @code{query-replace-skip-read-only}, if set | ||
| 1522 | non-@code{nil}, will cause replacement commands to ignore matches in | ||
| 1523 | read-only text. The default is not to ignore them. | ||
| 1524 | |||
| 1295 | The characters you can type when you are shown a match for the string | 1525 | The characters you can type when you are shown a match for the string |
| 1296 | or regexp are: | 1526 | or regexp are: |
| 1297 | 1527 | ||
| @@ -1311,9 +1541,13 @@ or regexp are: | |||
| 1311 | @c WideCommands | 1541 | @c WideCommands |
| 1312 | @table @kbd | 1542 | @table @kbd |
| 1313 | @item @key{SPC} | 1543 | @item @key{SPC} |
| 1544 | @itemx y | ||
| 1314 | to replace the occurrence with @var{newstring}. | 1545 | to replace the occurrence with @var{newstring}. |
| 1315 | 1546 | ||
| 1316 | @item @key{DEL} | 1547 | @item @key{DEL} |
| 1548 | @itemx @key{Delete} | ||
| 1549 | @itemx @key{BACKSPACE} | ||
| 1550 | @itemx n | ||
| 1317 | to skip to the next occurrence without replacing this one. | 1551 | to skip to the next occurrence without replacing this one. |
| 1318 | 1552 | ||
| 1319 | @item , @r{(Comma)} | 1553 | @item , @r{(Comma)} |
| @@ -1329,6 +1563,7 @@ must use @kbd{C-x @key{ESC} @key{ESC} @key{RET}} to restart | |||
| 1329 | (@pxref{Repetition}). | 1563 | (@pxref{Repetition}). |
| 1330 | 1564 | ||
| 1331 | @item @key{RET} | 1565 | @item @key{RET} |
| 1566 | @itemx q | ||
| 1332 | to exit without doing any more replacements. | 1567 | to exit without doing any more replacements. |
| 1333 | 1568 | ||
| 1334 | @item .@: @r{(Period)} | 1569 | @item .@: @r{(Period)} |
| @@ -1338,19 +1573,6 @@ occurrences. | |||
| 1338 | @item ! | 1573 | @item ! |
| 1339 | to replace all remaining occurrences without asking again. | 1574 | to replace all remaining occurrences without asking again. |
| 1340 | 1575 | ||
| 1341 | @item Y @r{(Upper-case)} | ||
| 1342 | to replace all remaining occurrences in all remaining buffers in | ||
| 1343 | multi-buffer replacements (like the Dired @key{Q} command that performs | ||
| 1344 | query replace on selected files). It answers this question and all | ||
| 1345 | subsequent questions in the series with ``yes'', without further | ||
| 1346 | user interaction. | ||
| 1347 | |||
| 1348 | @item N @r{(Upper-case)} | ||
| 1349 | to skip to the next buffer in multi-buffer replacements without | ||
| 1350 | replacing remaining occurrences in the current buffer. It answers | ||
| 1351 | this question ``no'', gives up on the questions for the current buffer, | ||
| 1352 | and continues to the next buffer in the sequence. | ||
| 1353 | |||
| 1354 | @item ^ | 1576 | @item ^ |
| 1355 | to go back to the position of the previous occurrence (or what used to | 1577 | to go back to the position of the previous occurrence (or what used to |
| 1356 | be an occurrence), in case you changed it by mistake or want to | 1578 | be an occurrence), in case you changed it by mistake or want to |
| @@ -1378,19 +1600,30 @@ replacement string for any further occurrences. | |||
| 1378 | to redisplay the screen. Then you must type another character to | 1600 | to redisplay the screen. Then you must type another character to |
| 1379 | specify what to do with this occurrence. | 1601 | specify what to do with this occurrence. |
| 1380 | 1602 | ||
| 1603 | @item Y @r{(Upper-case)} | ||
| 1604 | to replace all remaining occurrences in all remaining buffers in | ||
| 1605 | multi-buffer replacements (like the Dired @key{Q} command that performs | ||
| 1606 | query replace on selected files). It answers this question and all | ||
| 1607 | subsequent questions in the series with ``yes'', without further | ||
| 1608 | user interaction. | ||
| 1609 | |||
| 1610 | @item N @r{(Upper-case)} | ||
| 1611 | to skip to the next buffer in multi-buffer replacements without | ||
| 1612 | replacing remaining occurrences in the current buffer. It answers | ||
| 1613 | this question ``no'', gives up on the questions for the current buffer, | ||
| 1614 | and continues to the next buffer in the sequence. | ||
| 1615 | |||
| 1381 | @item C-h | 1616 | @item C-h |
| 1617 | @itemx ? | ||
| 1618 | @itemx @key{F1} | ||
| 1382 | to display a message summarizing these options. Then you must type | 1619 | to display a message summarizing these options. Then you must type |
| 1383 | another character to specify what to do with this occurrence. | 1620 | another character to specify what to do with this occurrence. |
| 1384 | @end table | 1621 | @end table |
| 1385 | 1622 | ||
| 1386 | Some other characters are aliases for the ones listed above: @kbd{y}, | ||
| 1387 | @kbd{n} and @kbd{q} are equivalent to @key{SPC}, @key{DEL} and | ||
| 1388 | @key{RET}. | ||
| 1389 | |||
| 1390 | Aside from this, any other character exits the @code{query-replace}, | 1623 | Aside from this, any other character exits the @code{query-replace}, |
| 1391 | and is then reread as part of a key sequence. Thus, if you type | 1624 | and is then reread as part of a key sequence. Thus, if you type |
| 1392 | @kbd{C-k}, it exits the @code{query-replace} and then kills to end of | 1625 | @kbd{C-k}, it exits the @code{query-replace} and then kills to end of |
| 1393 | line. | 1626 | line. In particular, @kbd{C-g} simply exits the @code{query-replace}. |
| 1394 | 1627 | ||
| 1395 | To restart a @code{query-replace} once it is exited, use @kbd{C-x | 1628 | To restart a @code{query-replace} once it is exited, use @kbd{C-x |
| 1396 | @key{ESC} @key{ESC}}, which repeats the @code{query-replace} because it | 1629 | @key{ESC} @key{ESC}}, which repeats the @code{query-replace} because it |
| @@ -1454,12 +1687,17 @@ a multi-file incremental search is activated automatically. | |||
| 1454 | 1687 | ||
| 1455 | @cindex Occur mode | 1688 | @cindex Occur mode |
| 1456 | @cindex mode, Occur | 1689 | @cindex mode, Occur |
| 1690 | @cindex match (face name) | ||
| 1691 | @vindex list-matching-lines-default-context-lines | ||
| 1457 | @item M-x occur | 1692 | @item M-x occur |
| 1458 | Prompt for a regexp, and display a list showing each line in the | 1693 | Prompt for a regexp, and display a list showing each line in the |
| 1459 | buffer that contains a match for it. To limit the search to part of | 1694 | buffer that contains a match for it. The text that matched is |
| 1460 | the buffer, narrow to that part (@pxref{Narrowing}). A numeric | 1695 | highlighted using the @code{match} face. To limit the search to part |
| 1696 | of the buffer, narrow to that part (@pxref{Narrowing}). A numeric | ||
| 1461 | argument @var{n} specifies that @var{n} lines of context are to be | 1697 | argument @var{n} specifies that @var{n} lines of context are to be |
| 1462 | displayed before and after each matching line. | 1698 | displayed before and after each matching line. The default number of |
| 1699 | context lines is specified by the variable | ||
| 1700 | @code{list-matching-lines-default-context-lines}. | ||
| 1463 | 1701 | ||
| 1464 | @kindex RET @r{(Occur mode)} | 1702 | @kindex RET @r{(Occur mode)} |
| 1465 | @kindex o @r{(Occur mode)} | 1703 | @kindex o @r{(Occur mode)} |
| @@ -1526,3 +1764,89 @@ it never deletes lines that are only partially contained in the region | |||
| 1526 | 1764 | ||
| 1527 | If a match is split across lines, this command keeps all those lines. | 1765 | If a match is split across lines, this command keeps all those lines. |
| 1528 | @end table | 1766 | @end table |
| 1767 | |||
| 1768 | @node Search Customizations | ||
| 1769 | @section Tailoring Search to Your Needs | ||
| 1770 | @cindex search customizations | ||
| 1771 | |||
| 1772 | This section describes miscellaneous search-related customizations | ||
| 1773 | not described elsewhere. | ||
| 1774 | |||
| 1775 | @cindex default search mode | ||
| 1776 | @cindex search mode, default | ||
| 1777 | The default search mode for the incremental search is specified by | ||
| 1778 | the variable @code{search-default-regexp-mode}. It can be @code{nil}, | ||
| 1779 | @code{t}, or a function. If it is @code{nil}, the default mode is to | ||
| 1780 | do literal searches without character folding, but with case folding | ||
| 1781 | and lax-whitespace matches as determined by @code{case-fold-search} | ||
| 1782 | and @code{search-whitespace-regexp}, respectively (@pxref{Lax | ||
| 1783 | Search}). If the value is @code{t}, incremental search defaults to | ||
| 1784 | regexp searches. The default value specifies a function that causes | ||
| 1785 | the default search mode to perform character folding in addition to | ||
| 1786 | case folding and lax-whitespace matching. | ||
| 1787 | |||
| 1788 | @vindex search-highlight | ||
| 1789 | The current match of an on-going incremental search is highlighted | ||
| 1790 | using the @code{isearch} face. This highlighting can be disabled by | ||
| 1791 | setting the variable @code{search-highlight} to a @code{nil} value. | ||
| 1792 | |||
| 1793 | @cindex lazy highlighting customizations | ||
| 1794 | @vindex isearch-lazy-highlight | ||
| 1795 | @cindex lazy-highlight face | ||
| 1796 | The other matches for the search string that are visible on display | ||
| 1797 | are highlighted using the @code{lazy-highlight} face. Setting the | ||
| 1798 | variable @code{isearch-lazy-highlight} to a @code{nil} value disables | ||
| 1799 | this highlighting. Here are some other variables that customize the | ||
| 1800 | lazy highlighting: | ||
| 1801 | |||
| 1802 | @table @code | ||
| 1803 | @item lazy-highlight-initial-delay | ||
| 1804 | Time in seconds to wait before highlighting visible matches. | ||
| 1805 | |||
| 1806 | @item lazy-highlight-interval | ||
| 1807 | Time in seconds between highlighting successive matches. | ||
| 1808 | |||
| 1809 | @item lazy-highlight-max-at-a-time | ||
| 1810 | The maximum number of matches to highlight before checking for input. | ||
| 1811 | A large number can take some time to highlight, so if you want to | ||
| 1812 | continue searching and type @kbd{C-s} or @kbd{C-r} during that time, | ||
| 1813 | Emacs will not respond until it finishes highlighting all those | ||
| 1814 | matches. Thus, smaller values make Emacs more responsive. | ||
| 1815 | @end table | ||
| 1816 | |||
| 1817 | @vindex search-nonincremental-instead | ||
| 1818 | Normally, entering @key{RET} within incremental search when the | ||
| 1819 | search string is empty launches a nonincremental search. (Actually, | ||
| 1820 | it lets you edit the search string, and the next @key{RET} does the | ||
| 1821 | search.) However, if you customize the variable | ||
| 1822 | @code{search-nonincremental-instead} to a @code{nil} value, typing | ||
| 1823 | @key{RET} will always exit the incremental search, even if the search | ||
| 1824 | string is empty. | ||
| 1825 | |||
| 1826 | @vindex isearch-hide-immediately | ||
| 1827 | By default, incremental search and query-replace commands match | ||
| 1828 | invisible text, but hide any such matches as soon as the current match | ||
| 1829 | moves off the invisible text. If you customize the variable | ||
| 1830 | @code{isearch-hide-immediately} to a @code{nil} value, any invisible | ||
| 1831 | text where matches were found stays on display until the search or the | ||
| 1832 | replace command exits. | ||
| 1833 | |||
| 1834 | @cindex search display on slow terminals | ||
| 1835 | @vindex search-slow-speed | ||
| 1836 | @vindex search-slow-window-lines | ||
| 1837 | Searching incrementally on slow terminals, such as displays | ||
| 1838 | connected to remote machines over slow connection, could be annoying | ||
| 1839 | due to the need to redraw large portions of the display as the search | ||
| 1840 | proceeds. Emacs provides a special display mode for slow terminals, | ||
| 1841 | whereby search pops up a separate small window and displays the text | ||
| 1842 | surrounding the match in that window. Small windows display faster, | ||
| 1843 | so the annoying effect of slow speed is alleviated. The variable | ||
| 1844 | @code{search-slow-speed} determines the baud rate threshold below | ||
| 1845 | which Emacs will use this display mode. The variable | ||
| 1846 | @code{search-slow-window-lines} controls the number of lines in the | ||
| 1847 | window Emacs pops up for displaying the search results; the default is | ||
| 1848 | 1 line. Normally, this window will pop up at the bottom of the window | ||
| 1849 | that displays the buffer where you start searching, bit if the value | ||
| 1850 | of @code{search-slow-window-lines} is negative, that means to put the | ||
| 1851 | window at the top and give it the number of lines that is the absolute | ||
| 1852 | value of that value. | ||
| @@ -135,25 +135,6 @@ frames. | |||
| 135 | Works for functions, variables, faces, etc. It is bound to `C-h o' by | 135 | Works for functions, variables, faces, etc. It is bound to `C-h o' by |
| 136 | default. | 136 | default. |
| 137 | 137 | ||
| 138 | ** New user option `search-default-regexp-mode' | ||
| 139 | specifies the default mode for I-search. | ||
| 140 | |||
| 141 | ** `isearch' and `query-replace' now perform character folding in matches. | ||
| 142 | This is analogous to case folding, but instead of disregarding case | ||
| 143 | variants, it disregards wider classes of distinctions between similar | ||
| 144 | characters. (Case folding is a special case of character folding.) | ||
| 145 | This means many characters in the search string will match entire | ||
| 146 | groups of characters instead of just themselves. | ||
| 147 | |||
| 148 | For instance, the " will match all variants of double quotes (like “ | ||
| 149 | and ”), and the letter a will match all of its accented cousins, even | ||
| 150 | those composed of multiple characters, as well as many other symbols | ||
| 151 | like ℀, ℁, ⒜, and ⓐ. | ||
| 152 | |||
| 153 | ** New function `character-fold-to-regexp' can be used | ||
| 154 | by searching commands to produce a regexp matching anything that | ||
| 155 | character-folds into STRING. | ||
| 156 | |||
| 157 | ** New command `checkdoc-package-keywords' checks if the | 138 | ** New command `checkdoc-package-keywords' checks if the |
| 158 | current package keywords are recognized. Set the new option | 139 | current package keywords are recognized. Set the new option |
| 159 | `checkdoc-package-keywords-flag' to non-nil to make | 140 | `checkdoc-package-keywords-flag' to non-nil to make |
| @@ -175,10 +156,6 @@ the `network-security-level' variable. | |||
| 175 | 156 | ||
| 176 | ** C-h l now also lists the commands that were run. | 157 | ** C-h l now also lists the commands that were run. |
| 177 | 158 | ||
| 178 | --- | ||
| 179 | ** The new M-s M-w key binding uses eww to search the web for the | ||
| 180 | text in the region. | ||
| 181 | |||
| 182 | ** M-x suggests shorthands and ignores obsolete commands for completion. | 159 | ** M-x suggests shorthands and ignores obsolete commands for completion. |
| 183 | ** x-select-enable-clipboard is renamed select-enable-clipboard. | 160 | ** x-select-enable-clipboard is renamed select-enable-clipboard. |
| 184 | x-select-enable-primary and renamed select-enable-primary. | 161 | x-select-enable-primary and renamed select-enable-primary. |
| @@ -532,6 +509,36 @@ element. The new commands bound to <up> and <down> in the minibuffer: | |||
| 532 | 509 | ||
| 533 | ** Search and Replace | 510 | ** Search and Replace |
| 534 | 511 | ||
| 512 | +++ | ||
| 513 | *** New user option `search-default-regexp-mode' | ||
| 514 | specifies the default mode for I-search. | ||
| 515 | |||
| 516 | +++ | ||
| 517 | *** `isearch' and `query-replace' can now perform character folding in matches. | ||
| 518 | Isearch does that by default, while `query-replace' will do that if | ||
| 519 | the new variable `replace-character-fold' is customized to a non-nil | ||
| 520 | value. This is analogous to case folding, but instead of disregarding | ||
| 521 | case variants, it disregards wider classes of distinctions between | ||
| 522 | similar characters. (Case folding is a special case of character | ||
| 523 | folding.) This means many characters in the search string will match | ||
| 524 | entire groups of characters instead of just themselves. | ||
| 525 | |||
| 526 | For instance, the " will match all variants of double quotes (like “ | ||
| 527 | and ”), and the letter a will match all of its accented cousins, even | ||
| 528 | those composed of multiple characters, as well as many other symbols | ||
| 529 | like ℀, ℁, ⒜, and ⓐ. | ||
| 530 | |||
| 531 | +++ | ||
| 532 | *** New function `character-fold-to-regexp' can be used | ||
| 533 | by searching commands to produce a regexp matching anything that | ||
| 534 | character-folds into STRING. | ||
| 535 | |||
| 536 | +++ | ||
| 537 | *** The new M-s M-w key binding uses eww to search the web for the | ||
| 538 | text in the region. The search engine to use for this is specified by | ||
| 539 | the customizable variable `eww-search-prefix'. | ||
| 540 | |||
| 541 | +++ | ||
| 535 | *** Query-replace history is enhanced. | 542 | *** Query-replace history is enhanced. |
| 536 | When query-replace reads the FROM string from the minibuffer, typing | 543 | When query-replace reads the FROM string from the minibuffer, typing |
| 537 | `M-p' will now show previous replacements as "FROM SEP TO", where FROM | 544 | `M-p' will now show previous replacements as "FROM SEP TO", where FROM |
diff --git a/lisp/isearch.el b/lisp/isearch.el index 080eb578aa7..0a6b925d03e 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el | |||
| @@ -96,8 +96,12 @@ in Isearch mode is always downcased." | |||
| 96 | 96 | ||
| 97 | (defcustom search-nonincremental-instead t | 97 | (defcustom search-nonincremental-instead t |
| 98 | "If non-nil, do a nonincremental search instead of exiting immediately. | 98 | "If non-nil, do a nonincremental search instead of exiting immediately. |
| 99 | Actually, `isearch-edit-string' is called to let you enter the search | 99 | This affects the behavior of `isearch-exit' and any key bound to that |
| 100 | string, and RET terminates editing and does a nonincremental search." | 100 | command: if this variable is nil, `isearch-exit' always exits the search; |
| 101 | if the value is non-nil, and the search string is empty, `isearch-exit' | ||
| 102 | starts a nonincremental search instead. (Actually, `isearch-edit-string' | ||
| 103 | is called to let you enter the search string, and RET terminates editing | ||
| 104 | and does a nonincremental search.)" | ||
| 101 | :type 'boolean) | 105 | :type 'boolean) |
| 102 | 106 | ||
| 103 | (defcustom search-whitespace-regexp (purecopy "\\s-+") | 107 | (defcustom search-whitespace-regexp (purecopy "\\s-+") |
| @@ -142,9 +146,11 @@ whenever point is in one of them." | |||
| 142 | (defcustom isearch-hide-immediately t | 146 | (defcustom isearch-hide-immediately t |
| 143 | "If non-nil, re-hide an invisible match right away. | 147 | "If non-nil, re-hide an invisible match right away. |
| 144 | This variable makes a difference when `search-invisible' is set to `open'. | 148 | This variable makes a difference when `search-invisible' is set to `open'. |
| 149 | If non-nil, invisible matches are re-hidden as soon as the match moves | ||
| 150 | off the invisible text surrounding the match. | ||
| 145 | If nil then do not re-hide opened invisible text when the match moves. | 151 | If nil then do not re-hide opened invisible text when the match moves. |
| 146 | Whatever the value, all opened invisible text is hidden again after exiting | 152 | Whatever the value, all opened invisible text is hidden again after exiting |
| 147 | the search." | 153 | the search, with the exception of the last successful match, if any." |
| 148 | :type 'boolean) | 154 | :type 'boolean) |
| 149 | 155 | ||
| 150 | (defcustom isearch-resume-in-command-history nil | 156 | (defcustom isearch-resume-in-command-history nil |
diff --git a/lisp/replace.el b/lisp/replace.el index 7727562cf31..a671a98b7a0 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -111,7 +111,8 @@ strings or patterns." | |||
| 111 | :version "22.1") | 111 | :version "22.1") |
| 112 | 112 | ||
| 113 | (defcustom query-replace-show-replacement t | 113 | (defcustom query-replace-show-replacement t |
| 114 | "Non-nil means to show what actual replacement text will be." | 114 | "Non-nil means show substituted replacement text in the minibuffer. |
| 115 | This variable affects only `query-replace-regexp'." | ||
| 115 | :type 'boolean | 116 | :type 'boolean |
| 116 | :group 'matching | 117 | :group 'matching |
| 117 | :version "23.1") | 118 | :version "23.1") |