diff options
| author | Richard M. Stallman | 1996-12-18 23:35:48 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-12-18 23:35:48 +0000 |
| commit | 56256c2a0c7c52a4543ca4f6c4758c2fa8288631 (patch) | |
| tree | 4bab0c9d5b1aeec77c3b952069f814a3f21c8b51 /src | |
| parent | a50388f82077f843c70bd5f74ee97abd9c41989a (diff) | |
| download | emacs-56256c2a0c7c52a4543ca4f6c4758c2fa8288631.tar.gz emacs-56256c2a0c7c52a4543ca4f6c4758c2fa8288631.zip | |
(Fmatch_data): New args INTEGERS and REUSE.
Diffstat (limited to 'src')
| -rw-r--r-- | src/search.c | 40 |
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.") | |||
| 1829 | return match_limit (subexp, 0); | 1829 | return match_limit (subexp, 0); |
| 1830 | } | 1830 | } |
| 1831 | 1831 | ||
| 1832 | DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 0, 0, | 1832 | DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 2, 0, |
| 1833 | "Return a list containing all info on what the last search matched.\n\ | 1833 | "Return a list containing all info on what the last search matched.\n\ |
| 1834 | Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'.\n\ | 1834 | Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'.\n\ |
| 1835 | All the elements are markers or nil (nil if the Nth pair didn't match)\n\ | 1835 | All the elements are markers or nil (nil if the Nth pair didn't match)\n\ |
| 1836 | if the last match was on a buffer; integers or nil if a string was matched.\n\ | 1836 | if the last match was on a buffer; integers or nil if a string was matched.\n\ |
| 1837 | Use `store-match-data' to reinstate the data in this list.") | 1837 | Use `store-match-data' to reinstate the data in this list.\n\ |
| 1838 | () | 1838 | \n\ |
| 1839 | If INTEGERS (the optional first argument) is non-nil, always use integers\n\ | ||
| 1840 | (rather than markers) to represent buffer positions.\n\ | ||
| 1841 | If REUSE is a list, reuse it as part of the value. If REUSE is long enough\n\ | ||
| 1842 | to hold all the values, and if INTEGERS is non-nil, no consing is done.") | ||
| 1843 | (integers, reuse) | ||
| 1844 | Lisp_Object integers, reuse; | ||
| 1839 | { | 1845 | { |
| 1846 | Lisp_Object tail, prev; | ||
| 1840 | Lisp_Object *data; | 1847 | Lisp_Object *data; |
| 1841 | int i, len; | 1848 | int i, len; |
| 1842 | 1849 | ||
| @@ -1852,7 +1859,8 @@ Use `store-match-data' to reinstate the data in this list.") | |||
| 1852 | int start = search_regs.start[i]; | 1859 | int start = search_regs.start[i]; |
| 1853 | if (start >= 0) | 1860 | if (start >= 0) |
| 1854 | { | 1861 | { |
| 1855 | if (EQ (last_thing_searched, Qt)) | 1862 | if (EQ (last_thing_searched, Qt) |
| 1863 | || ! NILP (integers)) | ||
| 1856 | { | 1864 | { |
| 1857 | XSETFASTINT (data[2 * i], start); | 1865 | XSETFASTINT (data[2 * i], start); |
| 1858 | XSETFASTINT (data[2 * i + 1], search_regs.end[i]); | 1866 | XSETFASTINT (data[2 * i + 1], search_regs.end[i]); |
| @@ -1877,7 +1885,29 @@ Use `store-match-data' to reinstate the data in this list.") | |||
| 1877 | else | 1885 | else |
| 1878 | data[2 * i] = data [2 * i + 1] = Qnil; | 1886 | data[2 * i] = data [2 * i + 1] = Qnil; |
| 1879 | } | 1887 | } |
| 1880 | return Flist (2 * len + 2, data); | 1888 | |
| 1889 | /* If REUSE is not usable, cons up the values and return them. */ | ||
| 1890 | if (! CONSP (reuse)) | ||
| 1891 | return Flist (2 * len + 2, data); | ||
| 1892 | |||
| 1893 | /* If REUSE is a list, store as many value elements as will fit | ||
| 1894 | into the elements of REUSE. */ | ||
| 1895 | for (i = 0, tail = reuse; CONSP (tail); | ||
| 1896 | i++, tail = XCONS (tail)->cdr) | ||
| 1897 | { | ||
| 1898 | if (i < 2 * len + 2) | ||
| 1899 | XCONS (tail)->car = data[i]; | ||
| 1900 | else | ||
| 1901 | XCONS (tail)->car = Qnil; | ||
| 1902 | prev = tail; | ||
| 1903 | } | ||
| 1904 | |||
| 1905 | /* If we couldn't fit all value elements into REUSE, | ||
| 1906 | cons up the rest of them and add them to the end of REUSE. */ | ||
| 1907 | if (i < 2 * len + 2) | ||
| 1908 | XCONS (prev)->cdr = Flist (2 * len + 2 - i, data + i); | ||
| 1909 | |||
| 1910 | return reuse; | ||
| 1881 | } | 1911 | } |
| 1882 | 1912 | ||
| 1883 | 1913 | ||