]> code.delx.au - gnu-emacs/blobdiff - doc/lispref/searching.texi
(Common Keywords): It's not necessary to use :tag
[gnu-emacs] / doc / lispref / searching.texi
index 9b54aa18b088a5f85cb4b419c0d73d3188def404..eea165d1c1f1a11c20b5682056fccc98a37de46a 100644 (file)
@@ -1,7 +1,7 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001,
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001,
-@c   2002, 2003, 2004, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
+@c   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
 @c See the file elisp.texi for copying conditions.
 @setfilename ../../info/searching
 @node Searching and Matching, Syntax Tables, Non-ASCII Characters, Top
 @c See the file elisp.texi for copying conditions.
 @setfilename ../../info/searching
 @node Searching and Matching, Syntax Tables, Non-ASCII Characters, Top
@@ -334,6 +334,7 @@ preceding expression either once or not at all.  For example,
 @samp{ca?r} matches @samp{car} or @samp{cr}; nothing else.
 
 @item @samp{*?}, @samp{+?}, @samp{??}
 @samp{ca?r} matches @samp{car} or @samp{cr}; nothing else.
 
 @item @samp{*?}, @samp{+?}, @samp{??}
+@cindex non-greedy repetition characters in regexp
 These are ``non-greedy'' variants of the operators @samp{*}, @samp{+}
 and @samp{?}.  Where those operators match the largest possible
 substring (consistent with matching the entire containing expression),
 These are ``non-greedy'' variants of the operators @samp{*}, @samp{+}
 and @samp{?}.  Where those operators match the largest possible
 substring (consistent with matching the entire containing expression),
@@ -1060,6 +1061,11 @@ the match is available as @code{(match-end 0)}.  @xref{Match Data}.
 @end example
 @end defun
 
 @end example
 @end defun
 
+@defun string-match-p regexp string &optional start
+This predicate function does what @code{string-match} does, but it
+avoids modifying the match data.
+@end defun
+
 @defun looking-at regexp
 This function determines whether the text in the current buffer directly
 following point matches the regular expression @var{regexp}.  ``Directly
 @defun looking-at regexp
 This function determines whether the text in the current buffer directly
 following point matches the regular expression @var{regexp}.  ``Directly
@@ -1069,7 +1075,8 @@ result is @code{t} if so, @code{nil} otherwise.
 
 This function does not move point, but it updates the match data, which
 you can access using @code{match-beginning} and @code{match-end}.
 
 This function does not move point, but it updates the match data, which
 you can access using @code{match-beginning} and @code{match-end}.
-@xref{Match Data}.
+@xref{Match Data}.  If you need to test for a match without modifying
+the match data, use @code{looking-at-p}, described below.
 
 In this example, point is located directly before the @samp{T}.  If it
 were anywhere else, the result would be @code{nil}.
 
 In this example, point is located directly before the @samp{T}.  If it
 were anywhere else, the result would be @code{nil}.
@@ -1087,7 +1094,7 @@ comes back" twice.
 @end example
 @end defun
 
 @end example
 @end defun
 
-@defun looking-back regexp &optional limit
+@defun looking-back regexp &optional limit greedy
 This function returns @code{t} if @var{regexp} matches text before
 point, ending at point, and @code{nil} otherwise.
 
 This function returns @code{t} if @var{regexp} matches text before
 point, ending at point, and @code{nil} otherwise.
 
@@ -1098,6 +1105,12 @@ You can bound the time required by specifying @var{limit}, which says
 not to search before @var{limit}.  In this case, the match that is
 found must begin at or after @var{limit}.
 
 not to search before @var{limit}.  In this case, the match that is
 found must begin at or after @var{limit}.
 
+If @var{greedy} is non-@code{nil}, this function extends the match
+backwards as far as possible, stopping when a single additional
+previous character cannot be part of a match for regexp.  When the
+match is extended, its starting position is allowed to occur before
+@var{limit}.
+
 @example
 @group
 ---------- Buffer: foo ----------
 @example
 @group
 ---------- Buffer: foo ----------
@@ -1113,6 +1126,11 @@ comes back" twice.
 @end example
 @end defun
 
 @end example
 @end defun
 
+@defun looking-at-p regexp
+This predicate function works like @code{looking-at}, but without
+updating the match data.
+@end defun
+
 @defvar search-spaces-regexp
 If this variable is non-@code{nil}, it should be a regular expression
 that says how to search for whitespace.  In that case, any group of
 @defvar search-spaces-regexp
 If this variable is non-@code{nil}, it should be a regular expression
 that says how to search for whitespace.  In that case, any group of
@@ -1142,8 +1160,9 @@ match, as required by POSIX.  This is much slower, so use these
 functions only when you really need the longest match.
 
   The POSIX search and match functions do not properly support the
 functions only when you really need the longest match.
 
   The POSIX search and match functions do not properly support the
-non-greedy repetition operators.  This is because POSIX backtracking
-conflicts with the semantics of non-greedy repetition.
+non-greedy repetition operators (@pxref{Regexp Special, non-greedy}).
+This is because POSIX backtracking conflicts with the semantics of
+non-greedy repetition.
 
 @defun posix-search-forward regexp &optional limit noerror repeat
 This is like @code{re-search-forward} except that it performs the full
 
 @defun posix-search-forward regexp &optional limit noerror repeat
 This is like @code{re-search-forward} except that it performs the full
@@ -1395,7 +1414,7 @@ subexpression is at the 13th character (@samp{c}).
   (re-search-forward "The \\(cat \\)")
   (match-beginning 0)
   (match-beginning 1))
   (re-search-forward "The \\(cat \\)")
   (match-beginning 0)
   (match-beginning 1))
-    @result{} (9 9 13)
+    @result{} (17 9 13)
 @end group
 
 @group
 @end group
 
 @group
@@ -1625,8 +1644,8 @@ The argument @var{replacements} specifies what to replace occurrences
 with.  If it is a string, that string is used.  It can also be a list of
 strings, to be used in cyclic order.
 
 with.  If it is a string, that string is used.  It can also be a list of
 strings, to be used in cyclic order.
 
-If @var{replacements} is a cons cell, @code{(@var{function}
-. @var{data})}, this means to call @var{function} after each match to
+If @var{replacements} is a cons cell, @w{@code{(@var{function}
+. @var{data})}}, this means to call @var{function} after each match to
 get the replacement text.  This function is called with two arguments:
 @var{data}, and the number of replacements already made.
 
 get the replacement text.  This function is called with two arguments:
 @var{data}, and the number of replacements already made.
 
@@ -1642,6 +1661,13 @@ Normally, the keymap @code{query-replace-map} defines the possible
 user responses for queries.  The argument @var{map}, if
 non-@code{nil}, specifies a keymap to use instead of
 @code{query-replace-map}.
 user responses for queries.  The argument @var{map}, if
 non-@code{nil}, specifies a keymap to use instead of
 @code{query-replace-map}.
+
+This function uses one of two functions to search for the next
+occurrence of @var{from-string}.  These functions are specified by the
+values of two variables: @code{replace-re-search-function} and
+@code{replace-search-function}.  The former is called when the
+argument @var{regexp-flag} is non-@code{nil}, the latter when it is
+@code{nil}.
 @end defun
 
 @defvar query-replace-map
 @end defun
 
 @defvar query-replace-map
@@ -1712,6 +1738,28 @@ use this answer.
 Display some help, then ask again.
 @end table
 
 Display some help, then ask again.
 @end table
 
+@defvar multi-query-replace-map
+This variable holds a keymap that extends @code{query-replace-map} by
+providing additional keybindings that are useful in multi-buffer
+replacements.
+@end defvar
+
+@defvar replace-search-function
+This variable specifies a function that @code{perform-replace} calls
+to search for the next string to replace.  Its default value is
+@code{search-forward}.  Any other value should name a function of 3
+arguments: the first 3 arguments of @code{search-forward}
+(@pxref{String Search}).
+@end defvar
+
+@defvar replace-re-search-function
+This variable specifies a function that @code{perform-replace} calls
+to search for the next regexp to replace.  Its default value is
+@code{re-search-forward}.  Any other value should name a function of 3
+arguments: the first 3 arguments of @code{re-search-forward}
+(@pxref{Regexp Search}).
+@end defvar
+
 @node Standard Regexps
 @section Standard Regular Expressions Used in Editing
 @cindex regexps used standardly in editing
 @node Standard Regexps
 @section Standard Regular Expressions Used in Editing
 @cindex regexps used standardly in editing