]> code.delx.au - gnu-emacs/blobdiff - man/search.texi
Entry corrected.
[gnu-emacs] / man / search.texi
index a9ed7a969699fe79955a4c2ebc4b54892d7e47d5..a9d5b5e9ba5262d0b3712bebf2e3632df71f8e04 100644 (file)
@@ -53,7 +53,7 @@ Incremental search backward (@code{isearch-backward}).
   @kbd{C-s} starts a forward incremental search.  It reads characters
 from the keyboard, and moves point past the next occurrence of those
 characters.  If you type @kbd{C-s} and then @kbd{F}, that puts the
-cursor after the first @samp{F} (following the starting point, since
+cursor after the first @samp{F} (the first following the starting point, since
 this is a forward search).  Then if you type an @kbd{O}, you will see
 the cursor move just after the first @samp{FO} (the @samp{F} in that
 @samp{FO} may or may not be the first @samp{F}).  After another
@@ -125,7 +125,7 @@ octal code: enter @kbd{C-q} followed by a sequence of octal digits.
 @cindex searching for non-ASCII characters
 @cindex input method, during incremental search
   To search for non-ASCII characters, you must use an input method
-(@pxref{Input Methods}).  If an input method is turned on in the
+(@pxref{Input Methods}).  If an input method is enabled in the
 current buffer when you start the search, you can use it while you
 type the search string also.  Emacs indicates that by including the
 input method mnemonic in its prompt, like this:
@@ -142,8 +142,8 @@ toggle (enable or disable) the input method while you type the search
 string with @kbd{C-\} (@code{isearch-toggle-input-method}).  You can
 turn on a certain (non-default) input method with @kbd{C-^}
 (@code{isearch-toggle-specified-input-method}), which prompts for the
-name of the input method.  Note that the input method you turn on
-during incremental search remains enabled in the current buffer as well.
+name of the input method.  The input method you enable during
+incremental search remains enabled in the current buffer afterwards.
 
   If a search is failing and you ask to repeat it by typing another
 @kbd{C-s}, it starts again from the beginning of the buffer.
@@ -181,15 +181,18 @@ backward search finds matches that are entirely before the starting
 point, just as a forward search finds matches that begin after it.
 
   The characters @kbd{C-y} and @kbd{C-w} can be used in incremental
-search to grab text from the buffer into the search string.  This makes
-it convenient to search for another occurrence of text at point.
-@kbd{C-w} copies the word after point as part of the search string,
-advancing point over that word.  Another @kbd{C-s} to repeat the search
-will then search for a string including that word.  @kbd{C-y} is similar
-to @kbd{C-w} but copies all the rest of the current line into the search
-string.  Both @kbd{C-y} and @kbd{C-w} convert the text they copy to
-lower case if the search is currently not case-sensitive; this is so the
-search remains case-insensitive.
+search to grab text from the buffer into the search string.  This
+makes it convenient to search for another occurrence of text at point.
+@kbd{C-w} copies the character or word after point as part of the
+search string, advancing point over it.  (The decision, whether to
+copy a character or a word, is heuristic.)  Another @kbd{C-s} to
+repeat the search will then search for a string including that
+character or word.
+
+  @kbd{C-y} is similar to @kbd{C-w} but copies all the rest of the
+current line into the search string.  Both @kbd{C-y} and @kbd{C-w}
+convert the text they copy to lower case if the search is currently
+not case-sensitive; this is so the search remains case-insensitive.
 
   The character @kbd{M-y} copies text from the kill ring into the search
 string.  It uses the same text that @kbd{C-y} as a command would yank.
@@ -463,6 +466,13 @@ the text @samp{abbb}, @samp{ab*} will match it all (the longest valid
 match), while @samp{ab*?}  will match just @samp{a} (the shortest
 valid match).
 
+Non-greedy operators match the shortest possible string starting at a
+given starting point; in a forward search, though, the earliest
+possible starting point for match is always the one chosen.  Thus, if
+you search for @samp{a.*?$} against the text @samp{abbab} followed by
+a newline, it matches the whole string.  Since it @emph{can} match
+starting at the first @samp{a}, it does.
+
 @item \@{@var{n}\@}
 is a postfix operator that specifies repetition @var{n} times---that
 is, the preceding regular expression must match exactly @var{n} times
@@ -632,12 +642,12 @@ If a particular @samp{\( @dots{} \)} construct matches more than once
 match is recorded.
 
 @item \`
-matches the empty string, but only at the beginning
-of the buffer or string being matched against.
+matches the empty string, but only at the beginning of the string or
+buffer (or its accessible portion) being matched against.
 
 @item \'
-matches the empty string, but only at the end of
-the buffer or string being matched against.
+matches the empty string, but only at the end of the string or buffer
+(or its accessible portion) being matched against.
 
 @item \=
 matches the empty string, but only at point.
@@ -719,9 +729,12 @@ end-of-line, a space at the end of a line, a tab, or two spaces; and a
 character set matching whitespace characters, repeated any number of
 times.
 
-  To enter the same regexp interactively, you would type @key{TAB} to
-enter a tab, and @kbd{C-j} to enter a newline.  You would also type
-single backslashes as themselves, instead of doubling them for Lisp syntax.
+  To enter the same regexp in incremental search, you would type
+@key{TAB} to enter a tab, and @kbd{C-j} to enter a newline.  You would
+also type single backslashes as themselves, instead of doubling them
+for Lisp syntax.  In commands that use ordinary minibuffer input to
+read a regexp, you would quote the @kbd{C-j} by preceding it with a
+@kbd{C-q} to prevent @kbd{C-j} from exiting the minibuffer.
 
 @ignore
 @c I commented this out because it is missing vital information
@@ -788,11 +801,12 @@ there is a @kbd{M-x query-replace} command which finds each occurrence
 of the pattern and asks you whether to replace it.
 
   The replace commands normally operate on the text from point to the
-end of the buffer; however, in Transient Mark mode, when the mark is
-active, they operate on the region.  The replace commands all replace
-one string (or regexp) with one replacement string.  It is possible to
-perform several replacements in parallel using the command
-@code{expand-region-abbrevs} (@pxref{Expanding Abbrevs}).
+end of the buffer; however, in Transient Mark mode (@pxref{Transient
+Mark}), when the mark is active, they operate on the region.  The
+replace commands all replace one string (or regexp) with one
+replacement string.  It is possible to perform several replacements in
+parallel using the command @code{expand-region-abbrevs}
+(@pxref{Expanding Abbrevs}).
 
 @menu
 * Unconditional Replace::  Replacing all matches for a string.
@@ -831,6 +845,18 @@ C-@key{SPC}} to move back there.
   A numeric argument restricts replacement to matches that are surrounded
 by word boundaries.  The argument's value doesn't matter.
 
+  What if you want to exchange @samp{x} and @samp{y}: replace every @samp{x} with a @samp{y} and vice versa?  You can do it this way:
+
+@example
+M-x query-replace @key{RET} x @key{RET} @@TEMP@@ @key{RET}
+M-x query-replace @key{RET} y @key{RET} x @key{RET}
+M-x query-replace @key{RET} @@TEMP@@ @key{RET} y @key{RET}
+@end example
+
+@noindent
+This works provided the string @samp{@@TEMP@@} does not appear
+in your text.
+
 @node Regexp Replace, Replacement and Case, Unconditional Replace, Replace
 @subsection Regexp Replacement
 
@@ -1025,11 +1051,14 @@ copy, or link files by replacing regexp matches in file names.
   Here are some other commands that find matches for a regular
 expression.  They all ignore case in matching, if the pattern contains
 no upper-case letters and @code{case-fold-search} is non-@code{nil}.
-Aside from @code{occur}, all operate on the text from point to the end
-of the buffer, or on the active region in Transient Mark mode.
+Aside from @code{occur} and its variants, all operate on the text from
+point to the end of the buffer, or on the active region in Transient
+Mark mode.
 
 @findex list-matching-lines
 @findex occur
+@findex multi-occur
+@findex multi-occur-by-filename-regexp
 @findex how-many
 @findex delete-non-matching-lines
 @findex delete-matching-lines
@@ -1045,15 +1074,27 @@ specifies that @var{n} lines of context are to be displayed before and
 after each matching line.
 
 @kindex RET @r{(Occur mode)}
+@kindex o @r{(Occur mode)}
+@kindex C-o @r{(Occur mode)}
 The buffer @samp{*Occur*} containing the output serves as a menu for
-finding the occurrences in their original context.  Click @kbd{Mouse-2}
-on an occurrence listed in @samp{*Occur*}, or position point there and
-type @key{RET}; this switches to the buffer that was searched and
-moves point to the original of the chosen occurrence.
+finding the occurrences in their original context.  Click
+@kbd{Mouse-2} on an occurrence listed in @samp{*Occur*}, or position
+point there and type @key{RET}; this switches to the buffer that was
+searched and moves point to the original of the chosen occurrence.
+@kbd{o} and @kbd{C-o} display the match in another window; @kbd{C-o}
+does not select it.
 
 @item M-x list-matching-lines
 Synonym for @kbd{M-x occur}.
 
+@item M-x multi-occur @key{RET} @var{buffers} @key{RET} @var{regexp} @key{RET}
+This function is just like @code{occur}, except it is able to search
+through multiple buffers.
+
+@item M-x multi-occur-by-filename-regexp @key{RET} @var{bufregexp} @key{RET} @var{regexp} @key{RET}
+This function is similar to @code{multi-occur}, except the buffers to
+search are specified by a regexp on their filename.
+
 @item M-x how-many @key{RET} @var{regexp} @key{RET}
 Print the number of matches for @var{regexp} that exist in the buffer
 after point.  In Transient Mark mode, if the region is active, the