Subject: bug#23937: closed (Re: bug#23937: 25.0.95; Search functions doc fixes/improvements)

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 12 Jul 2016 20:14:02 +0000

Your bug report

#23937: 25.0.95; Search functions doc fixes/improvements

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
23937: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23937
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#23937: 25.0.95; Search functions doc fixes/improvements
From: Stephen Berman <[email-masked]>
To: Eli Zaretskii <[email-masked]>
Cc: Stephen Berman <[email-masked]>, [email-masked]
Date: Tue, 12 Jul 2016 22:13:38 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

On Tue, 12 Jul 2016 18:23:26 +0300 Eli Zaretskii <[email-masked]> wrote:

>> From: Stephen Berman <[email-masked]>
>> Cc: Stephen Berman <[email-masked]>,  [email-masked]
>> Date: Tue, 12 Jul 2016 17:14:19 +0200
>> 
>>    With COUNT positive, the match found is the COUNTth to last one (or
>>      last, if COUNT is 1 or nil) in the buffer located entirely before
>>      the origin of the search; correspondingly with COUNT negative.
>
> OK.

Pushed to emacs-25 as commit 069fc05 and closing the bug; thanks for the
feedback.

Steve Berman

Subject: 25.0.95; Search functions doc fixes/improvements
From: Stephen Berman <[email-masked]>
To: [email-masked]
Date: Sun, 10 Jul 2016 20:21:34 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

In GNU Emacs 25.0.95.9 (x86_64-suse-linux-gnu, GTK+ Version 3.14.15)
 of 2016-07-10 built on rosalinde
Repository revision: 4069b716ad3422f2d7f595699220c39297427387

Bug#10507 was about missing documentation for the fact that the fourth
argument of search-{for,back}ward can be a negative number, reversing
the search direction.  This lack was fixed in commit acc28cb, but that
commit didn't correspondingly augment the doc of the other search
functions (word-search-*, re-search-*, posix-search-*), which have the
same behavior.  The patch below does this.  In addition, the
documentation in the Lisp reference uses the word "repeat" instead of
"count" for that argument, and says the search is repeated N times,
where N is the argument's value; but strictly speaking, it's repeated
N-1 times.  It may be clear what's intended, but there's no need for the
manual to differ from (and be strictly less accurate than) the doc
strings on this point, so the patch changes the manual accordingly.
Finally, the patch also adds the information about the nil value of the
bound/limit argument to those doc strings/manual entries where it's
missing.  In short the patch makes the doc of all these functions more
uniform.

diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi
index 1243d72..8d0e4ca 100644
--- a/doc/lispref/searching.texi
+++ b/doc/lispref/searching.texi
@@ -44,7 +44,7 @@ String Search
 buffer is multibyte; they convert the search string to unibyte if the
 buffer is unibyte.  @xref{Text Representations}.
 
-@deffn Command search-forward string &optional limit noerror repeat
+@deffn Command search-forward string &optional limit noerror count
 This function searches forward from point for an exact match for
 @var{string}.  If successful, it sets point to the end of the occurrence
 found, and returns the new value of point.  If no match is found, the
@@ -95,24 +95,24 @@ String Search
 find a match.  Invalid arguments cause errors regardless of
 @var{noerror}.
 
-If @var{repeat} is a positive number @var{n}, it serves as a repeat
-count: the search is repeated @var{n} times, each time starting at the
-end of the previous time's match.  If these successive searches
-succeed, the function succeeds, moving point and returning its new
-value.  Otherwise the search fails, with results depending on the
-value of @var{noerror}, as described above.  If @var{repeat} is a
-negative number -@var{n}, it serves as a repeat count of @var{n} for a
-search in the opposite (backward) direction.
+If @var{count} is a positive number @var{n}, the search is done
+@var{n} times; each repetition starts at the end of the previous
+match.  If all these successive searches succeed, the function call
+succeeds, moving point and returning its new value.  Otherwise the
+function call fails, with results depending on the value of
+@var{noerror}, as described above.  If @var{count} is a negative
+number -@var{n}, the search is done @var{n} times in the opposite
+(backward) direction.
 @end deffn
 
-@deffn Command search-backward string &optional limit noerror repeat
+@deffn Command search-backward string &optional limit noerror count
 This function searches backward from point for @var{string}.  It is
 like @code{search-forward}, except that it searches backwards rather
 than forwards.  Backward searches leave point at the beginning of the
 match.
 @end deffn
 
-@deffn Command word-search-forward string &optional limit noerror repeat
+@deffn Command word-search-forward string &optional limit noerror count
 This function searches forward from point for a word match for
 @var{string}.  If it finds a match, it sets point to the end of the
 match found, and returns the new value of point.
@@ -156,8 +156,10 @@ String Search
 neither @code{nil} nor @code{t}, it moves point to @var{limit} (or the
 end of the accessible portion of the buffer) and returns @code{nil}.
 
-If @var{repeat} is non-@code{nil}, then the search is repeated that many
-times.  Point is positioned at the end of the last match.
+If @var{count} is a positive number, it specifies how many successive
+occurrences to search for.  Point is positioned at the end of the last
+match.  If @var{count} is a negative number, the search is backward
+and point is positioned at the beginning of the last match.
 
 @findex word-search-regexp
 Internally, @code{word-search-forward} and related functions use the
@@ -165,7 +167,7 @@ String Search
 regular expression that ignores punctuation.
 @end deffn
 
-@deffn Command word-search-forward-lax string &optional limit noerror repeat
+@deffn Command word-search-forward-lax string &optional limit noerror count
 This command is identical to @code{word-search-forward}, except that
 the beginning or the end of @var{string} need not match a word
 boundary, unless @var{string} begins or ends in whitespace.
@@ -173,14 +175,14 @@ String Search
 but does not match @samp{balls boy}.
 @end deffn
 
-@deffn Command word-search-backward string &optional limit noerror repeat
+@deffn Command word-search-backward string &optional limit noerror count
 This function searches backward from point for a word match to
 @var{string}.  This function is just like @code{word-search-forward}
 except that it searches backward and normally leaves point at the
 beginning of the match.
 @end deffn
 
-@deffn Command word-search-backward-lax string &optional limit noerror repeat
+@deffn Command word-search-backward-lax string &optional limit noerror count
 This command is identical to @code{word-search-backward}, except that
 the beginning or the end of @var{string} need not match a word
 boundary, unless @var{string} begins or ends in whitespace.
@@ -1005,7 +1007,7 @@ Regexp Search
 the buffer is multibyte; they convert the regular expression to unibyte
 if the buffer is unibyte.  @xref{Text Representations}.
 
-@deffn Command re-search-forward regexp &optional limit noerror repeat
+@deffn Command re-search-forward regexp &optional limit noerror count
 This function searches forward in the current buffer for a string of
 text that is matched by the regular expression @var{regexp}.  The
 function skips over any amount of text that is not matched by
@@ -1014,14 +1016,12 @@ Regexp Search
 
 If @var{limit} is non-@code{nil}, it must be a position in the current
 buffer.  It specifies the upper bound to the search.  No match
-extending after that position is accepted.
+extending after that position is accepted.  If @var{limit} is omitted
+or @code{nil}, it defaults to the end of the accessible portion of the
+buffer.
 
-If @var{repeat} is supplied, it must be a positive number; the search
-is repeated that many times; each repetition starts at the end of the
-previous match.  If all these successive searches succeed, the search
-succeeds, moving point and returning its new value.  Otherwise the
-search fails.  What @code{re-search-forward} does when the search
-fails depends on the value of @var{noerror}:
+What @code{re-search-forward} does when the search fails depends on
+the value of @var{noerror}:
 
 @table @asis
 @item @code{nil}
@@ -1033,6 +1033,19 @@ Regexp Search
 buffer) and return @code{nil}.
 @end table
 
+The argument @var{noerror} only affects valid searches which fail to
+find a match.  Invalid arguments cause errors regardless of
+@var{noerror}.
+
+If @var{count} is a positive number @var{n}, the search is done
+@var{n} times; each repetition starts at the end of the previous
+match.  If all these successive searches succeed, the function call
+succeeds, moving point and returning its new value.  Otherwise the
+function call fails, with results depending on the value of
+@var{noerror}, as described above.  If @var{count} is a negative
+number -@var{n}, the search is done @var{n} times in the opposite
+(backward) direction.
+
 In the following example, point is initially before the @samp{T}.
 Evaluating the search call moves point to the end of that line (between
 the @samp{t} of @samp{hat} and the newline).
@@ -1057,7 +1070,7 @@ Regexp Search
 @end example
 @end deffn
 
-@deffn Command re-search-backward regexp &optional limit noerror repeat
+@deffn Command re-search-backward regexp &optional limit noerror count
 This function searches backward in the current buffer for a string of
 text that is matched by the regular expression @var{regexp}, leaving
 point at the beginning of the first text found.
@@ -1228,13 +1241,13 @@ POSIX Regexps
 This is because POSIX backtracking conflicts with the semantics of
 non-greedy repetition.
 
-@deffn Command posix-search-forward regexp &optional limit noerror repeat
+@deffn Command posix-search-forward regexp &optional limit noerror count
 This is like @code{re-search-forward} except that it performs the full
 backtracking specified by the POSIX standard for regular expression
 matching.
 @end deffn
 
-@deffn Command posix-search-backward regexp &optional limit noerror repeat
+@deffn Command posix-search-backward regexp &optional limit noerror count
 This is like @code{re-search-backward} except that it performs the full
 backtracking specified by the POSIX standard for regular expression
 matching.
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 7360a0b..322f2aa 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1627,7 +1627,8 @@ word-search-backward
 The match found must not extend before that position.
 Optional third argument, if t, means if fail just return nil (no error).
   If not nil and not t, move to limit of search and return nil.
-Optional fourth argument is repeat count--search for successive occurrences.
+Optional fourth argument specifies how many successive occurrences to
+  search for.
 
 Relies on the function `word-search-regexp' to convert a sequence
 of words in STRING to a regexp used to search words without regard
@@ -1644,7 +1645,8 @@ word-search-forward
 The match found must not extend after that position.
 Optional third argument, if t, means if fail just return nil (no error).
   If not nil and not t, move to limit of search and return nil.
-Optional fourth argument is repeat count--search for successive occurrences.
+Optional fourth argument specifies how many successive occurrences to
+  search for.
 
 Relies on the function `word-search-regexp' to convert a sequence
 of words in STRING to a regexp used to search words without regard
@@ -1665,7 +1667,8 @@ word-search-backward-lax
 The match found must not extend before that position.
 Optional third argument, if t, means if fail just return nil (no error).
   If not nil and not t, move to limit of search and return nil.
-Optional fourth argument is repeat count--search for successive occurrences.
+Optional fourth argument specifies how many successive occurrences to
+  search for.
 
 Relies on the function `word-search-regexp' to convert a sequence
 of words in STRING to a regexp used to search words without regard
@@ -1686,7 +1689,8 @@ word-search-forward-lax
 The match found must not extend after that position.
 Optional third argument, if t, means if fail just return nil (no error).
   If not nil and not t, move to limit of search and return nil.
-Optional fourth argument is repeat count--search for successive occurrences.
+Optional fourth argument specifies how many successive occurrences to
+  search for.
 
 Relies on the function `word-search-regexp' to convert a sequence
 of words in STRING to a regexp used to search words without regard
diff --git a/src/search.c b/src/search.c
index bcdd8f1..6614781 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2164,7 +2164,8 @@ DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4,
        doc: /* Search backward from point for STRING.
 Set point to the beginning of the occurrence found, and return point.
 An optional second argument bounds the search; it is a buffer position.
-The match found must not extend before that position.
+The match found must not extend before that position.  A value of nil is
+  equivalent to (point-min).
 Optional third argument, if t, means if fail just return nil (no error).
  If not nil and not t, position at limit of search and return nil.
 Optional fourth argument COUNT, if non-nil, means to search for COUNT
@@ -2204,14 +2205,15 @@ See also the functions `match-beginning', `match-end' and `replace-match'.  */)
 DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4,
        "sRE search backward: ",
        doc: /* Search backward from point for match for regular expression REGEXP.
-Set point to the beginning of the match, and return point.
-The match found is the one starting last in the buffer
-and yet ending before the origin of the search.
+Set point to the beginning of the occurrence found, and return point.
 An optional second argument bounds the search; it is a buffer position.
-The match found must start at or after that position.
+The match found must not extend before that position.  A value of nil is
+  equivalent to (point-min).
 Optional third argument, if t, means if fail just return nil (no error).
   If not nil and not t, move to limit of search and return nil.
-Optional fourth argument is repeat count--search for successive occurrences.
+Optional fourth argument COUNT, if non-nil, means to search for COUNT
+ successive occurrences.  If COUNT is negative, search forward,
+ instead of backward, for -COUNT occurrences.
 
 Search case-sensitivity is determined by the value of the variable
 `case-fold-search', which see.
@@ -2228,10 +2230,13 @@ DEFUN ("re-search-forward", Fre_search_forward, Sre_search_forward, 1, 4,
        doc: /* Search forward from point for regular expression REGEXP.
 Set point to the end of the occurrence found, and return point.
 An optional second argument bounds the search; it is a buffer position.
-The match found must not extend after that position.
+The match found must not extend after that position.  A value of nil is
+  equivalent to (point-max).
 Optional third argument, if t, means if fail just return nil (no error).
   If not nil and not t, move to limit of search and return nil.
-Optional fourth argument is repeat count--search for successive occurrences.
+Optional fourth argument COUNT, if non-nil, means to search for COUNT
+ successive occurrences.  If COUNT is negative, search backward,
+ instead of forward, for -COUNT occurrences.
 
 Search case-sensitivity is determined by the value of the variable
 `case-fold-search', which see.
@@ -2247,14 +2252,15 @@ DEFUN ("posix-search-backward", Fposix_search_backward, Sposix_search_backward,
        "sPosix search backward: ",
        doc: /* Search backward from point for match for regular expression REGEXP.
 Find the longest match in accord with Posix regular expression rules.
-Set point to the beginning of the match, and return point.
-The match found is the one starting last in the buffer
-and yet ending before the origin of the search.
+Set point to the beginning of the occurrence found, and return point.
 An optional second argument bounds the search; it is a buffer position.
-The match found must start at or after that position.
+The match found must start at or after that position.  A value of nil is
+  equivalent to (point-min).
 Optional third argument, if t, means if fail just return nil (no error).
   If not nil and not t, move to limit of search and return nil.
-Optional fourth argument is repeat count--search for successive occurrences.
+Optional fourth argument COUNT, if non-nil, means to search for COUNT
+ successive occurrences.  If COUNT is negative, search forward,
+ instead of backward, for -COUNT occurrences.
 
 Search case-sensitivity is determined by the value of the variable
 `case-fold-search', which see.
@@ -2272,10 +2278,13 @@ DEFUN ("posix-search-forward", Fposix_search_forward, Sposix_search_forward, 1,
 Find the longest match in accord with Posix regular expression rules.
 Set point to the end of the occurrence found, and return point.
 An optional second argument bounds the search; it is a buffer position.
-The match found must not extend after that position.
+The match found must not extend after that position.  A value of nil is
+  equivalent to (point-max).
 Optional third argument, if t, means if fail just return nil (no error).
   If not nil and not t, move to limit of search and return nil.
-Optional fourth argument is repeat count--search for successive occurrences.
+Optional fourth argument COUNT, if non-nil, means to search for COUNT
+ successive occurrences.  If COUNT is negative, search backward,
+ instead of forward, for -COUNT occurrences.
 
 Search case-sensitivity is determined by the value of the variable
 `case-fold-search', which see.