diff options
Diffstat (limited to 'lispref/searching.texi')
| -rw-r--r-- | lispref/searching.texi | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/lispref/searching.texi b/lispref/searching.texi index 1f4a82d3f1f..15037068dd2 100644 --- a/lispref/searching.texi +++ b/lispref/searching.texi | |||
| @@ -1485,13 +1485,14 @@ character of the buffer counts as 1.) | |||
| 1485 | The functions @code{match-data} and @code{set-match-data} read or | 1485 | The functions @code{match-data} and @code{set-match-data} read or |
| 1486 | write the entire match data, all at once. | 1486 | write the entire match data, all at once. |
| 1487 | 1487 | ||
| 1488 | @defun match-data &optional integers reuse | 1488 | @defun match-data &optional integers reuse reseat |
| 1489 | This function returns a newly constructed list containing all the | 1489 | This function returns a list of positions (markers or integers) that |
| 1490 | information on what text the last search matched. Element zero is the | 1490 | record all the information on what text the last search matched. |
| 1491 | position of the beginning of the match for the whole expression; element | 1491 | Element zero is the position of the beginning of the match for the |
| 1492 | one is the position of the end of the match for the expression. The | 1492 | whole expression; element one is the position of the end of the match |
| 1493 | next two elements are the positions of the beginning and end of the | 1493 | for the expression. The next two elements are the positions of the |
| 1494 | match for the first subexpression, and so on. In general, element | 1494 | beginning and end of the match for the first subexpression, and so on. |
| 1495 | In general, element | ||
| 1495 | @ifnottex | 1496 | @ifnottex |
| 1496 | number 2@var{n} | 1497 | number 2@var{n} |
| 1497 | @end ifnottex | 1498 | @end ifnottex |
| @@ -1508,15 +1509,13 @@ number {\mathsurround=0pt $2n+1$} | |||
| 1508 | @end tex | 1509 | @end tex |
| 1509 | corresponds to @code{(match-end @var{n})}. | 1510 | corresponds to @code{(match-end @var{n})}. |
| 1510 | 1511 | ||
| 1511 | All the elements are markers or @code{nil} if matching was done on a | 1512 | Normally all the elements are markers or @code{nil}, but if |
| 1512 | buffer and all are integers or @code{nil} if matching was done on a | 1513 | @var{integers} is non-@code{nil}, that means to use integers instead |
| 1513 | string with @code{string-match}. If @var{integers} is | 1514 | of markers. (In that case, the buffer itself is appended as an |
| 1514 | non-@code{nil}, then the elements are integers or @code{nil}, even if | 1515 | additional element at the end of the list, to facilitate complete |
| 1515 | matching was done on a buffer. In that case, the buffer itself is | 1516 | restoration of the match data.) If the last match was done on a |
| 1516 | appended as an additional element at the end of the list | 1517 | string with @code{string-match}, then integers are always used, |
| 1517 | to facilitate complete restoration of the match data. Also, | 1518 | since markers can't point into a string. |
| 1518 | @code{match-beginning} and | ||
| 1519 | @code{match-end} always return integers or @code{nil}. | ||
| 1520 | 1519 | ||
| 1521 | If @var{reuse} is non-@code{nil}, it should be a list. In that case, | 1520 | If @var{reuse} is non-@code{nil}, it should be a list. In that case, |
| 1522 | @code{match-data} stores the match data in @var{reuse}. That is, | 1521 | @code{match-data} stores the match data in @var{reuse}. That is, |
| @@ -1524,8 +1523,16 @@ If @var{reuse} is non-@code{nil}, it should be a list. In that case, | |||
| 1524 | have the right length. If it is not long enough to contain the match | 1523 | have the right length. If it is not long enough to contain the match |
| 1525 | data, it is extended. If it is too long, the length of @var{reuse} | 1524 | data, it is extended. If it is too long, the length of @var{reuse} |
| 1526 | stays the same, but the elements that were not used are set to | 1525 | stays the same, but the elements that were not used are set to |
| 1527 | @code{nil}. The purpose of this feature is to avoid producing too | 1526 | @code{nil}. The purpose of this feature is to reduce the need for |
| 1528 | much garbage, that would later have to be collected. | 1527 | garbage collection. |
| 1528 | |||
| 1529 | If @var{reseat} is non-@code{nil}, all markers on the @var{reuse} list | ||
| 1530 | are reseated to point to nowhere, and if the value is @code{evaporate}, | ||
| 1531 | the markers are put back on the free list. | ||
| 1532 | |||
| 1533 | @strong{Warning:} When @code{evaporate} is specified for @var{reseat}, | ||
| 1534 | no other references to the markers on the @var{reuse} list; otherwise, | ||
| 1535 | Emacs may crash during the next garbage collection. | ||
| 1529 | 1536 | ||
| 1530 | As always, there must be no possibility of intervening searches between | 1537 | As always, there must be no possibility of intervening searches between |
| 1531 | the call to a search function and the call to @code{match-data} that is | 1538 | the call to a search function and the call to @code{match-data} that is |
| @@ -1542,7 +1549,7 @@ intended to access the match data for that search. | |||
| 1542 | @end example | 1549 | @end example |
| 1543 | @end defun | 1550 | @end defun |
| 1544 | 1551 | ||
| 1545 | @defun set-match-data match-list | 1552 | @defun set-match-data match-list &optional reseat |
| 1546 | This function sets the match data from the elements of @var{match-list}, | 1553 | This function sets the match data from the elements of @var{match-list}, |
| 1547 | which should be a list that was the value of a previous call to | 1554 | which should be a list that was the value of a previous call to |
| 1548 | @code{match-data}. (More precisely, anything that has the same format | 1555 | @code{match-data}. (More precisely, anything that has the same format |
| @@ -1551,6 +1558,14 @@ will work.) | |||
| 1551 | If @var{match-list} refers to a buffer that doesn't exist, you don't get | 1558 | If @var{match-list} refers to a buffer that doesn't exist, you don't get |
| 1552 | an error; that sets the match data in a meaningless but harmless way. | 1559 | an error; that sets the match data in a meaningless but harmless way. |
| 1553 | 1560 | ||
| 1561 | If @var{reseat} is non-@code{nil}, all markers on the @var{match-list} list | ||
| 1562 | are reseated to point to nowhere, and if the value is @code{evaporate}, | ||
| 1563 | the markers are put back on the free list. | ||
| 1564 | |||
| 1565 | @strong{Warning:} When @code{evaporate} is specified for @var{reseat}, | ||
| 1566 | no other references to the markers on the @var{match-list} list; otherwise, | ||
| 1567 | Emacs may crash during the next garbage collection. | ||
| 1568 | |||
| 1554 | @findex store-match-data | 1569 | @findex store-match-data |
| 1555 | @code{store-match-data} is a semi-obsolete alias for @code{set-match-data}. | 1570 | @code{store-match-data} is a semi-obsolete alias for @code{set-match-data}. |
| 1556 | @end defun | 1571 | @end defun |