diff options
| author | Paul Eggert | 2015-08-17 23:46:38 -0700 |
|---|---|---|
| committer | Paul Eggert | 2015-08-17 23:47:46 -0700 |
| commit | 7a68ebe0485d049a3fbbfd77d0ba5773e8e6ae87 (patch) | |
| tree | 74c44f9cd2bedff09c0b6746078608b1c1be8fd2 | |
| parent | 9a1175cb0a33aeb13601ae8997931a853cb45249 (diff) | |
| download | emacs-7a68ebe0485d049a3fbbfd77d0ba5773e8e6ae87.tar.gz emacs-7a68ebe0485d049a3fbbfd77d0ba5773e8e6ae87.zip | |
Clarify what happens to match data on failure
Problem reported by Ernesto Alfonso (Bug#21279).
* doc/lispref/searching.texi (Regexp Search, Simple Match Data):
Document more carefully what happens to match data after a failed
search.
* src/search.c (Fmatch_beginning, Fmatch_end): Document that
the return value is undefined if the last search failed.
(Fmatch_data): Simplify doc string line 1.
| -rw-r--r-- | doc/lispref/searching.texi | 7 | ||||
| -rw-r--r-- | src/search.c | 10 |
2 files changed, 11 insertions, 6 deletions
diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi index 5a05c7c729d..60360cb98a9 100644 --- a/doc/lispref/searching.texi +++ b/doc/lispref/searching.texi | |||
| @@ -1102,7 +1102,7 @@ For example, | |||
| 1102 | The index of the first character of the | 1102 | The index of the first character of the |
| 1103 | string is 0, the index of the second character is 1, and so on. | 1103 | string is 0, the index of the second character is 1, and so on. |
| 1104 | 1104 | ||
| 1105 | After this function returns, the index of the first character beyond | 1105 | If this function finds a match, the index of the first character beyond |
| 1106 | the match is available as @code{(match-end 0)}. @xref{Match Data}. | 1106 | the match is available as @code{(match-end 0)}. @xref{Match Data}. |
| 1107 | 1107 | ||
| 1108 | @example | 1108 | @example |
| @@ -1425,8 +1425,9 @@ has no text properties. | |||
| 1425 | @end defun | 1425 | @end defun |
| 1426 | 1426 | ||
| 1427 | @defun match-beginning count | 1427 | @defun match-beginning count |
| 1428 | This function returns the position of the start of the text matched by the | 1428 | If the last regular expression search found a match, this function |
| 1429 | last regular expression searched for, or a subexpression of it. | 1429 | returns the position of the start of the matching text or of a |
| 1430 | subexpression of it. | ||
| 1430 | 1431 | ||
| 1431 | If @var{count} is zero, then the value is the position of the start of | 1432 | If @var{count} is zero, then the value is the position of the start of |
| 1432 | the entire match. Otherwise, @var{count} specifies a subexpression in | 1433 | the entire match. Otherwise, @var{count} specifies a subexpression in |
diff --git a/src/search.c b/src/search.c index 5da99c408a5..106a462f804 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -2754,7 +2754,9 @@ SUBEXP, a number, specifies which parenthesized expression in the last | |||
| 2754 | regexp. | 2754 | regexp. |
| 2755 | Value is nil if SUBEXPth pair didn't match, or there were less than | 2755 | Value is nil if SUBEXPth pair didn't match, or there were less than |
| 2756 | SUBEXP pairs. | 2756 | SUBEXP pairs. |
| 2757 | Zero means the entire text matched by the whole regexp or whole string. */) | 2757 | Zero means the entire text matched by the whole regexp or whole string. |
| 2758 | |||
| 2759 | Return value is undefined if the last search failed. */) | ||
| 2758 | (Lisp_Object subexp) | 2760 | (Lisp_Object subexp) |
| 2759 | { | 2761 | { |
| 2760 | return match_limit (subexp, 1); | 2762 | return match_limit (subexp, 1); |
| @@ -2766,14 +2768,16 @@ SUBEXP, a number, specifies which parenthesized expression in the last | |||
| 2766 | regexp. | 2768 | regexp. |
| 2767 | Value is nil if SUBEXPth pair didn't match, or there were less than | 2769 | Value is nil if SUBEXPth pair didn't match, or there were less than |
| 2768 | SUBEXP pairs. | 2770 | SUBEXP pairs. |
| 2769 | Zero means the entire text matched by the whole regexp or whole string. */) | 2771 | Zero means the entire text matched by the whole regexp or whole string. |
| 2772 | |||
| 2773 | Return value is undefined if the last search failed. */) | ||
| 2770 | (Lisp_Object subexp) | 2774 | (Lisp_Object subexp) |
| 2771 | { | 2775 | { |
| 2772 | return match_limit (subexp, 0); | 2776 | return match_limit (subexp, 0); |
| 2773 | } | 2777 | } |
| 2774 | 2778 | ||
| 2775 | DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 3, 0, | 2779 | DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 3, 0, |
| 2776 | doc: /* Return a list containing all info on what the last search matched. | 2780 | doc: /* Return a list describing what the last search matched. |
| 2777 | Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'. | 2781 | Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'. |
| 2778 | All the elements are markers or nil (nil if the Nth pair didn't match) | 2782 | All the elements are markers or nil (nil if the Nth pair didn't match) |
| 2779 | if the last match was on a buffer; integers or nil if a string was matched. | 2783 | if the last match was on a buffer; integers or nil if a string was matched. |