summaryrefslogtreecommitdiff
path: root/src/search.c
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1996-12-18 23:35:48 +0000
committerRichard M. Stallman <rms@gnu.org>1996-12-18 23:35:48 +0000
commit480e0d05670912d3ea879a58c598dd1023ef3cf5 (patch)
tree5715e77273bc0ccb5702068b9c11db26ce1ffa5b /src/search.c
parent43e22f2e1e7f17135d0e369a6a9f6204eabde9b1 (diff)
downloademacs-480e0d05670912d3ea879a58c598dd1023ef3cf5.tar.gz
(Fmatch_data): New args INTEGERS and REUSE.
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/search.c b/src/search.c
index 5713e53fd90..4adb3572698 100644
--- a/src/search.c
+++ b/src/search.c
@@ -1829,14 +1829,21 @@ Zero means the entire text matched by the whole regexp or whole string.")
return match_limit (subexp, 0);
}
-DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 0, 0,
+DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 2, 0,
"Return a list containing all info on what the last search matched.\n\
Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'.\n\
All the elements are markers or nil (nil if the Nth pair didn't match)\n\
if the last match was on a buffer; integers or nil if a string was matched.\n\
-Use `store-match-data' to reinstate the data in this list.")
- ()
+Use `store-match-data' to reinstate the data in this list.\n\
+\n\
+If INTEGERS (the optional first argument) is non-nil, always use integers\n\
+(rather than markers) to represent buffer positions.\n\
+If REUSE is a list, reuse it as part of the value. If REUSE is long enough\n\
+to hold all the values, and if INTEGERS is non-nil, no consing is done.")
+ (integers, reuse)
+ Lisp_Object integers, reuse;
{
+ Lisp_Object tail, prev;
Lisp_Object *data;
int i, len;
@@ -1852,7 +1859,8 @@ Use `store-match-data' to reinstate the data in this list.")
int start = search_regs.start[i];
if (start >= 0)
{
- if (EQ (last_thing_searched, Qt))
+ if (EQ (last_thing_searched, Qt)
+ || ! NILP (integers))
{
XSETFASTINT (data[2 * i], start);
XSETFASTINT (data[2 * i + 1], search_regs.end[i]);
@@ -1877,7 +1885,29 @@ Use `store-match-data' to reinstate the data in this list.")
else
data[2 * i] = data [2 * i + 1] = Qnil;
}
- return Flist (2 * len + 2, data);
+
+ /* If REUSE is not usable, cons up the values and return them. */
+ if (! CONSP (reuse))
+ return Flist (2 * len + 2, data);
+
+ /* If REUSE is a list, store as many value elements as will fit
+ into the elements of REUSE. */
+ for (i = 0, tail = reuse; CONSP (tail);
+ i++, tail = XCONS (tail)->cdr)
+ {
+ if (i < 2 * len + 2)
+ XCONS (tail)->car = data[i];
+ else
+ XCONS (tail)->car = Qnil;
+ prev = tail;
+ }
+
+ /* If we couldn't fit all value elements into REUSE,
+ cons up the rest of them and add them to the end of REUSE. */
+ if (i < 2 * len + 2)
+ XCONS (prev)->cdr = Flist (2 * len + 2 - i, data + i);
+
+ return reuse;
}