diff options
| author | Jim Blandy | 1992-06-24 05:09:26 +0000 |
|---|---|---|
| committer | Jim Blandy | 1992-06-24 05:09:26 +0000 |
| commit | daa3760289bd389e8c174c8d24b375cd875cd911 (patch) | |
| tree | 0abe3e6108e0e5a7c98f4c4aa68a495b0ecef09a /src/search.c | |
| parent | a4275ad1c8f60239b0bad43cef97ca86d35a51a3 (diff) | |
| download | emacs-daa3760289bd389e8c174c8d24b375cd875cd911.tar.gz emacs-daa3760289bd389e8c174c8d24b375cd875cd911.zip | |
*** empty log message ***
Diffstat (limited to 'src/search.c')
| -rw-r--r-- | src/search.c | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/src/search.c b/src/search.c index 88eb72ab1f4..5e2a96c87fa 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -59,9 +59,10 @@ Lisp_Object last_regexp; | |||
| 59 | able to free or re-allocate it properly. */ | 59 | able to free or re-allocate it properly. */ |
| 60 | static struct re_registers search_regs; | 60 | static struct re_registers search_regs; |
| 61 | 61 | ||
| 62 | /* Nonzero if search_regs are indices in a string; 0 if in a buffer. */ | 62 | /* The buffer in which the last search was performed, or |
| 63 | 63 | Qt if the last search was done in a string; | |
| 64 | static int search_regs_from_string; | 64 | Qnil if no searching has been done yet. */ |
| 65 | static Lisp_Object last_thing_searched; | ||
| 65 | 66 | ||
| 66 | /* error condition signalled when regexp compile_pattern fails */ | 67 | /* error condition signalled when regexp compile_pattern fails */ |
| 67 | 68 | ||
| @@ -178,7 +179,7 @@ data if you want to preserve them.") | |||
| 178 | search_regs.start[i] += BEGV; | 179 | search_regs.start[i] += BEGV; |
| 179 | search_regs.end[i] += BEGV; | 180 | search_regs.end[i] += BEGV; |
| 180 | } | 181 | } |
| 181 | search_regs_from_string = 0; | 182 | XSET (last_thing_searched, Lisp_Buffer, current_buffer); |
| 182 | immediate_quit = 0; | 183 | immediate_quit = 0; |
| 183 | return val; | 184 | return val; |
| 184 | } | 185 | } |
| @@ -219,7 +220,7 @@ matched by parenthesis constructs in the pattern.") | |||
| 219 | XSTRING (string)->size, s, XSTRING (string)->size - s, | 220 | XSTRING (string)->size, s, XSTRING (string)->size - s, |
| 220 | &search_regs); | 221 | &search_regs); |
| 221 | immediate_quit = 0; | 222 | immediate_quit = 0; |
| 222 | search_regs_from_string = 1; | 223 | last_thing_searched = Qt; |
| 223 | if (val == -2) | 224 | if (val == -2) |
| 224 | matcher_overflow (); | 225 | matcher_overflow (); |
| 225 | if (val < 0) return Qnil; | 226 | if (val < 0) return Qnil; |
| @@ -587,7 +588,7 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt) | |||
| 587 | search_regs.start[i] += j; | 588 | search_regs.start[i] += j; |
| 588 | search_regs.end[i] += j; | 589 | search_regs.end[i] += j; |
| 589 | } | 590 | } |
| 590 | search_regs_from_string = 0; | 591 | XSET (last_thing_searched, Lisp_Buffer, current_buffer); |
| 591 | /* Set pos to the new position. */ | 592 | /* Set pos to the new position. */ |
| 592 | pos = search_regs.start[0]; | 593 | pos = search_regs.start[0]; |
| 593 | } | 594 | } |
| @@ -614,7 +615,7 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt) | |||
| 614 | search_regs.start[i] += j; | 615 | search_regs.start[i] += j; |
| 615 | search_regs.end[i] += j; | 616 | search_regs.end[i] += j; |
| 616 | } | 617 | } |
| 617 | search_regs_from_string = 0; | 618 | XSET (last_thing_searched, Lisp_Buffer, current_buffer); |
| 618 | pos = search_regs.end[0]; | 619 | pos = search_regs.end[0]; |
| 619 | } | 620 | } |
| 620 | else | 621 | else |
| @@ -804,7 +805,7 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt) | |||
| 804 | = pos + cursor - p2 + ((direction > 0) | 805 | = pos + cursor - p2 + ((direction > 0) |
| 805 | ? 1 - len : 0); | 806 | ? 1 - len : 0); |
| 806 | search_regs.end[0] = len + search_regs.start[0]; | 807 | search_regs.end[0] = len + search_regs.start[0]; |
| 807 | search_regs_from_string = 0; | 808 | XSET (last_thing_searched, Lisp_Buffer, current_buffer); |
| 808 | if ((n -= direction) != 0) | 809 | if ((n -= direction) != 0) |
| 809 | cursor += dirlen; /* to resume search */ | 810 | cursor += dirlen; /* to resume search */ |
| 810 | else | 811 | else |
| @@ -878,7 +879,7 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt) | |||
| 878 | search_regs.start[0] | 879 | search_regs.start[0] |
| 879 | = pos + ((direction > 0) ? 1 - len : 0); | 880 | = pos + ((direction > 0) ? 1 - len : 0); |
| 880 | search_regs.end[0] = len + search_regs.start[0]; | 881 | search_regs.end[0] = len + search_regs.start[0]; |
| 881 | search_regs_from_string = 0; | 882 | XSET (last_thing_searched, Lisp_Buffer, current_buffer); |
| 882 | if ((n -= direction) != 0) | 883 | if ((n -= direction) != 0) |
| 883 | pos += dirlen; /* to resume search */ | 884 | pos += dirlen; /* to resume search */ |
| 884 | else | 885 | else |
| @@ -1221,6 +1222,9 @@ Use `store-match-data' to reinstate the data in this list.") | |||
| 1221 | Lisp_Object *data; | 1222 | Lisp_Object *data; |
| 1222 | int i, len; | 1223 | int i, len; |
| 1223 | 1224 | ||
| 1225 | if (NILP (last_thing_searched)) | ||
| 1226 | error ("match-data called before any match found"); | ||
| 1227 | |||
| 1224 | data = (Lisp_Object *) alloca ((2 * search_regs.num_regs) | 1228 | data = (Lisp_Object *) alloca ((2 * search_regs.num_regs) |
| 1225 | * sizeof (Lisp_Object)); | 1229 | * sizeof (Lisp_Object)); |
| 1226 | 1230 | ||
| @@ -1230,19 +1234,26 @@ Use `store-match-data' to reinstate the data in this list.") | |||
| 1230 | int start = search_regs.start[i]; | 1234 | int start = search_regs.start[i]; |
| 1231 | if (start >= 0) | 1235 | if (start >= 0) |
| 1232 | { | 1236 | { |
| 1233 | if (search_regs_from_string) | 1237 | if (EQ (last_thing_searched, Qt)) |
| 1234 | { | 1238 | { |
| 1235 | XFASTINT (data[2 * i]) = start; | 1239 | XFASTINT (data[2 * i]) = start; |
| 1236 | XFASTINT (data[2 * i + 1]) = search_regs.end[i]; | 1240 | XFASTINT (data[2 * i + 1]) = search_regs.end[i]; |
| 1237 | } | 1241 | } |
| 1238 | else | 1242 | else if (XTYPE (last_thing_searched) == Lisp_Buffer) |
| 1239 | { | 1243 | { |
| 1240 | data[2 * i] = Fmake_marker (); | 1244 | data[2 * i] = Fmake_marker (); |
| 1241 | Fset_marker (data[2 * i], make_number (start), Qnil); | 1245 | Fset_marker (data[2 * i], |
| 1246 | make_number (start), | ||
| 1247 | last_thing_searched); | ||
| 1242 | data[2 * i + 1] = Fmake_marker (); | 1248 | data[2 * i + 1] = Fmake_marker (); |
| 1243 | Fset_marker (data[2 * i + 1], | 1249 | Fset_marker (data[2 * i + 1], |
| 1244 | make_number (search_regs.end[i]), Qnil); | 1250 | make_number (search_regs.end[i]), |
| 1251 | last_thing_searched); | ||
| 1245 | } | 1252 | } |
| 1253 | else | ||
| 1254 | /* last_thing_searched must always be Qt, a buffer, or Qnil. */ | ||
| 1255 | abort (); | ||
| 1256 | |||
| 1246 | len = i; | 1257 | len = i; |
| 1247 | } | 1258 | } |
| 1248 | else | 1259 | else |
| @@ -1264,6 +1275,10 @@ LIST should have been created by calling `match-data' previously.") | |||
| 1264 | if (!CONSP (list) && !NILP (list)) | 1275 | if (!CONSP (list) && !NILP (list)) |
| 1265 | list = wrong_type_argument (Qconsp, list, 0); | 1276 | list = wrong_type_argument (Qconsp, list, 0); |
| 1266 | 1277 | ||
| 1278 | /* Unless we find a marker with a buffer in LIST, assume that this | ||
| 1279 | match data came from a string. */ | ||
| 1280 | last_thing_searched = Qt; | ||
| 1281 | |||
| 1267 | /* Allocate registers if they don't already exist. */ | 1282 | /* Allocate registers if they don't already exist. */ |
| 1268 | { | 1283 | { |
| 1269 | int length = Flength (list) / 2; | 1284 | int length = Flength (list) / 2; |
| @@ -1302,9 +1317,14 @@ LIST should have been created by calling `match-data' previously.") | |||
| 1302 | } | 1317 | } |
| 1303 | else | 1318 | else |
| 1304 | { | 1319 | { |
| 1305 | if (XTYPE (marker) == Lisp_Marker | 1320 | if (XTYPE (marker) == Lisp_Marker) |
| 1306 | && XMARKER (marker)->buffer == 0) | 1321 | { |
| 1307 | XFASTINT (marker) = 0; | 1322 | if (XMARKER (marker)->buffer == 0) |
| 1323 | XFASTINT (marker) = 0; | ||
| 1324 | else | ||
| 1325 | XSET (last_thing_searched, Lisp_Buffer, | ||
| 1326 | XMARKER (marker)->buffer); | ||
| 1327 | } | ||
| 1308 | 1328 | ||
| 1309 | CHECK_NUMBER_COERCE_MARKER (marker, 0); | 1329 | CHECK_NUMBER_COERCE_MARKER (marker, 0); |
| 1310 | search_regs.start[i] = XINT (marker); | 1330 | search_regs.start[i] = XINT (marker); |
| @@ -1383,6 +1403,9 @@ syms_of_search () | |||
| 1383 | last_regexp = Qnil; | 1403 | last_regexp = Qnil; |
| 1384 | staticpro (&last_regexp); | 1404 | staticpro (&last_regexp); |
| 1385 | 1405 | ||
| 1406 | last_thing_searched = Qnil; | ||
| 1407 | staticpro (&last_thing_searched); | ||
| 1408 | |||
| 1386 | defsubr (&Sstring_match); | 1409 | defsubr (&Sstring_match); |
| 1387 | defsubr (&Slooking_at); | 1410 | defsubr (&Slooking_at); |
| 1388 | defsubr (&Sskip_chars_forward); | 1411 | defsubr (&Sskip_chars_forward); |