Mercurial > emacs
annotate src/search.c @ 6018:51d9a0c72a29
(single_keymap_panes): Properly skip help-string if any.
Rename item2 to item_string.
GCPRO some things.
(menu_item_equiv_key): Use either VECTORP or STRINGP, not both.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 21 Feb 1994 06:46:09 +0000 |
parents | a54c236b43c6 |
children | 390dfe557c7d |
rev | line source |
---|---|
603 | 1 /* String search routines for GNU Emacs. |
2961 | 2 Copyright (C) 1985, 1986, 1987, 1993 Free Software Foundation, Inc. |
603 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 1, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4635
diff
changeset
|
21 #include <config.h> |
603 | 22 #include "lisp.h" |
23 #include "syntax.h" | |
24 #include "buffer.h" | |
25 #include "commands.h" | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2393
diff
changeset
|
26 #include "blockinput.h" |
621 | 27 |
603 | 28 #include <sys/types.h> |
29 #include "regex.h" | |
30 | |
31 #define max(a, b) ((a) > (b) ? (a) : (b)) | |
32 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
33 | |
34 /* We compile regexps into this buffer and then use it for searching. */ | |
35 | |
36 struct re_pattern_buffer searchbuf; | |
37 | |
38 char search_fastmap[0400]; | |
39 | |
40 /* Last regexp we compiled */ | |
41 | |
42 Lisp_Object last_regexp; | |
43 | |
621 | 44 /* Every call to re_match, etc., must pass &search_regs as the regs |
45 argument unless you can show it is unnecessary (i.e., if re_match | |
46 is certainly going to be called again before region-around-match | |
47 can be called). | |
48 | |
49 Since the registers are now dynamically allocated, we need to make | |
50 sure not to refer to the Nth register before checking that it has | |
708 | 51 been allocated by checking search_regs.num_regs. |
603 | 52 |
708 | 53 The regex code keeps track of whether it has allocated the search |
54 buffer using bits in searchbuf. This means that whenever you | |
55 compile a new pattern, it completely forgets whether it has | |
56 allocated any registers, and will allocate new registers the next | |
57 time you call a searching or matching function. Therefore, we need | |
58 to call re_set_registers after compiling a new pattern or after | |
59 setting the match registers, so that the regex functions will be | |
60 able to free or re-allocate it properly. */ | |
603 | 61 static struct re_registers search_regs; |
62 | |
727 | 63 /* The buffer in which the last search was performed, or |
64 Qt if the last search was done in a string; | |
65 Qnil if no searching has been done yet. */ | |
66 static Lisp_Object last_thing_searched; | |
603 | 67 |
68 /* error condition signalled when regexp compile_pattern fails */ | |
69 | |
70 Lisp_Object Qinvalid_regexp; | |
71 | |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
72 static void set_search_regs (); |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
73 |
603 | 74 static void |
75 matcher_overflow () | |
76 { | |
77 error ("Stack overflow in regexp matcher"); | |
78 } | |
79 | |
80 #ifdef __STDC__ | |
81 #define CONST const | |
82 #else | |
83 #define CONST | |
84 #endif | |
85 | |
86 /* Compile a regexp and signal a Lisp error if anything goes wrong. */ | |
87 | |
708 | 88 compile_pattern (pattern, bufp, regp, translate) |
603 | 89 Lisp_Object pattern; |
90 struct re_pattern_buffer *bufp; | |
708 | 91 struct re_registers *regp; |
603 | 92 char *translate; |
93 { | |
94 CONST char *val; | |
95 Lisp_Object dummy; | |
96 | |
97 if (EQ (pattern, last_regexp) | |
98 && translate == bufp->translate) | |
99 return; | |
708 | 100 |
603 | 101 last_regexp = Qnil; |
102 bufp->translate = translate; | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2393
diff
changeset
|
103 BLOCK_INPUT; |
4635
ad4add779dac
(compile_pattern): Cast result of re_compile_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
4299
diff
changeset
|
104 val = (CONST char *) re_compile_pattern ((char *) XSTRING (pattern)->data, |
ad4add779dac
(compile_pattern): Cast result of re_compile_pattern.
Richard M. Stallman <rms@gnu.org>
parents:
4299
diff
changeset
|
105 XSTRING (pattern)->size, bufp); |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2393
diff
changeset
|
106 UNBLOCK_INPUT; |
603 | 107 if (val) |
108 { | |
109 dummy = build_string (val); | |
110 while (1) | |
111 Fsignal (Qinvalid_regexp, Fcons (dummy, Qnil)); | |
112 } | |
708 | 113 |
603 | 114 last_regexp = pattern; |
708 | 115 |
116 /* Advise the searching functions about the space we have allocated | |
117 for register data. */ | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2393
diff
changeset
|
118 BLOCK_INPUT; |
808 | 119 if (regp) |
120 re_set_registers (bufp, regp, regp->num_regs, regp->start, regp->end); | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2393
diff
changeset
|
121 UNBLOCK_INPUT; |
708 | 122 |
603 | 123 return; |
124 } | |
125 | |
126 /* Error condition used for failing searches */ | |
127 Lisp_Object Qsearch_failed; | |
128 | |
129 Lisp_Object | |
130 signal_failure (arg) | |
131 Lisp_Object arg; | |
132 { | |
133 Fsignal (Qsearch_failed, Fcons (arg, Qnil)); | |
134 return Qnil; | |
135 } | |
136 | |
137 DEFUN ("looking-at", Flooking_at, Slooking_at, 1, 1, 0, | |
638 | 138 "Return t if text after point matches regular expression PAT.\n\ |
139 This function modifies the match data that `match-beginning',\n\ | |
140 `match-end' and `match-data' access; save and restore the match\n\ | |
635
197f38dd0105
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
621
diff
changeset
|
141 data if you want to preserve them.") |
603 | 142 (string) |
143 Lisp_Object string; | |
144 { | |
145 Lisp_Object val; | |
146 unsigned char *p1, *p2; | |
147 int s1, s2; | |
148 register int i; | |
149 | |
150 CHECK_STRING (string, 0); | |
708 | 151 compile_pattern (string, &searchbuf, &search_regs, |
603 | 152 !NILP (current_buffer->case_fold_search) ? DOWNCASE_TABLE : 0); |
153 | |
154 immediate_quit = 1; | |
155 QUIT; /* Do a pending quit right away, to avoid paradoxical behavior */ | |
156 | |
157 /* Get pointers and sizes of the two strings | |
158 that make up the visible portion of the buffer. */ | |
159 | |
160 p1 = BEGV_ADDR; | |
161 s1 = GPT - BEGV; | |
162 p2 = GAP_END_ADDR; | |
163 s2 = ZV - GPT; | |
164 if (s1 < 0) | |
165 { | |
166 p2 = p1; | |
167 s2 = ZV - BEGV; | |
168 s1 = 0; | |
169 } | |
170 if (s2 < 0) | |
171 { | |
172 s1 = ZV - BEGV; | |
173 s2 = 0; | |
174 } | |
175 | |
176 i = re_match_2 (&searchbuf, (char *) p1, s1, (char *) p2, s2, | |
177 point - BEGV, &search_regs, | |
178 ZV - BEGV); | |
179 if (i == -2) | |
180 matcher_overflow (); | |
181 | |
182 val = (0 <= i ? Qt : Qnil); | |
621 | 183 for (i = 0; i < search_regs.num_regs; i++) |
603 | 184 if (search_regs.start[i] >= 0) |
185 { | |
186 search_regs.start[i] += BEGV; | |
187 search_regs.end[i] += BEGV; | |
188 } | |
727 | 189 XSET (last_thing_searched, Lisp_Buffer, current_buffer); |
603 | 190 immediate_quit = 0; |
191 return val; | |
192 } | |
193 | |
194 DEFUN ("string-match", Fstring_match, Sstring_match, 2, 3, 0, | |
195 "Return index of start of first match for REGEXP in STRING, or nil.\n\ | |
196 If third arg START is non-nil, start search at that index in STRING.\n\ | |
197 For index of first char beyond the match, do (match-end 0).\n\ | |
198 `match-end' and `match-beginning' also give indices of substrings\n\ | |
199 matched by parenthesis constructs in the pattern.") | |
200 (regexp, string, start) | |
201 Lisp_Object regexp, string, start; | |
202 { | |
203 int val; | |
204 int s; | |
205 | |
206 CHECK_STRING (regexp, 0); | |
207 CHECK_STRING (string, 1); | |
208 | |
209 if (NILP (start)) | |
210 s = 0; | |
211 else | |
212 { | |
213 int len = XSTRING (string)->size; | |
214 | |
215 CHECK_NUMBER (start, 2); | |
216 s = XINT (start); | |
217 if (s < 0 && -s <= len) | |
218 s = len - s; | |
219 else if (0 > s || s > len) | |
220 args_out_of_range (string, start); | |
221 } | |
222 | |
708 | 223 compile_pattern (regexp, &searchbuf, &search_regs, |
603 | 224 !NILP (current_buffer->case_fold_search) ? DOWNCASE_TABLE : 0); |
225 immediate_quit = 1; | |
226 val = re_search (&searchbuf, (char *) XSTRING (string)->data, | |
227 XSTRING (string)->size, s, XSTRING (string)->size - s, | |
228 &search_regs); | |
229 immediate_quit = 0; | |
727 | 230 last_thing_searched = Qt; |
603 | 231 if (val == -2) |
232 matcher_overflow (); | |
233 if (val < 0) return Qnil; | |
234 return make_number (val); | |
235 } | |
842 | 236 |
237 /* Match REGEXP against STRING, searching all of STRING, | |
238 and return the index of the match, or negative on failure. | |
239 This does not clobber the match data. */ | |
240 | |
241 int | |
242 fast_string_match (regexp, string) | |
243 Lisp_Object regexp, string; | |
244 { | |
245 int val; | |
246 | |
247 compile_pattern (regexp, &searchbuf, 0, 0); | |
248 immediate_quit = 1; | |
249 val = re_search (&searchbuf, (char *) XSTRING (string)->data, | |
250 XSTRING (string)->size, 0, XSTRING (string)->size, | |
251 0); | |
252 immediate_quit = 0; | |
253 return val; | |
254 } | |
603 | 255 |
648 | 256 /* Search for COUNT instances of the character TARGET, starting at START. |
257 If COUNT is negative, search backwards. | |
258 | |
259 If we find COUNT instances, set *SHORTAGE to zero, and return the | |
1413 | 260 position after the COUNTth match. Note that for reverse motion |
261 this is not the same as the usual convention for Emacs motion commands. | |
648 | 262 |
263 If we don't find COUNT instances before reaching the end of the | |
264 buffer (or the beginning, if scanning backwards), set *SHORTAGE to | |
265 the number of TARGETs left unfound, and return the end of the | |
5756
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
266 buffer we bumped up against. |
648 | 267 |
5756
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
268 If ALLOW_QUIT is non-zero, set immediate_quit. That's good to do |
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
269 except when inside redisplay. */ |
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
270 |
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
271 scan_buffer (target, start, count, shortage, allow_quit) |
648 | 272 int *shortage, start; |
273 register int count, target; | |
5756
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
274 int allow_quit; |
603 | 275 { |
648 | 276 int limit = ((count > 0) ? ZV - 1 : BEGV); |
277 int direction = ((count > 0) ? 1 : -1); | |
278 | |
279 register unsigned char *cursor; | |
603 | 280 unsigned char *base; |
648 | 281 |
282 register int ceiling; | |
283 register unsigned char *ceiling_addr; | |
603 | 284 |
285 if (shortage != 0) | |
286 *shortage = 0; | |
287 | |
5756
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
288 immediate_quit = allow_quit; |
603 | 289 |
648 | 290 if (count > 0) |
291 while (start != limit + 1) | |
603 | 292 { |
648 | 293 ceiling = BUFFER_CEILING_OF (start); |
294 ceiling = min (limit, ceiling); | |
295 ceiling_addr = &FETCH_CHAR (ceiling) + 1; | |
296 base = (cursor = &FETCH_CHAR (start)); | |
603 | 297 while (1) |
298 { | |
648 | 299 while (*cursor != target && ++cursor != ceiling_addr) |
603 | 300 ; |
648 | 301 if (cursor != ceiling_addr) |
603 | 302 { |
648 | 303 if (--count == 0) |
603 | 304 { |
305 immediate_quit = 0; | |
648 | 306 return (start + cursor - base + 1); |
603 | 307 } |
308 else | |
648 | 309 if (++cursor == ceiling_addr) |
603 | 310 break; |
311 } | |
312 else | |
313 break; | |
314 } | |
648 | 315 start += cursor - base; |
603 | 316 } |
317 else | |
318 { | |
648 | 319 start--; /* first character we scan */ |
320 while (start > limit - 1) | |
321 { /* we WILL scan under start */ | |
322 ceiling = BUFFER_FLOOR_OF (start); | |
323 ceiling = max (limit, ceiling); | |
324 ceiling_addr = &FETCH_CHAR (ceiling) - 1; | |
325 base = (cursor = &FETCH_CHAR (start)); | |
603 | 326 cursor++; |
327 while (1) | |
328 { | |
648 | 329 while (--cursor != ceiling_addr && *cursor != target) |
603 | 330 ; |
648 | 331 if (cursor != ceiling_addr) |
603 | 332 { |
648 | 333 if (++count == 0) |
603 | 334 { |
335 immediate_quit = 0; | |
648 | 336 return (start + cursor - base + 1); |
603 | 337 } |
338 } | |
339 else | |
340 break; | |
341 } | |
648 | 342 start += cursor - base; |
603 | 343 } |
344 } | |
345 immediate_quit = 0; | |
346 if (shortage != 0) | |
648 | 347 *shortage = count * direction; |
348 return (start + ((direction == 1 ? 0 : 1))); | |
603 | 349 } |
350 | |
351 int | |
352 find_next_newline (from, cnt) | |
353 register int from, cnt; | |
354 { | |
5756
a54c236b43c6
(scan_buffer): New arg ALLOW_QUIT.
Richard M. Stallman <rms@gnu.org>
parents:
5556
diff
changeset
|
355 return scan_buffer ('\n', from, cnt, (int *) 0, 1); |
603 | 356 } |
357 | |
1684
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
358 Lisp_Object skip_chars (); |
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
359 |
603 | 360 DEFUN ("skip-chars-forward", Fskip_chars_forward, Sskip_chars_forward, 1, 2, 0, |
4954
dc4d4f874b5c
(Fskip_chars_backward, Fskip_chars_forward): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4951
diff
changeset
|
361 "Move point forward, stopping before a char not in STRING, or at pos LIM.\n\ |
dc4d4f874b5c
(Fskip_chars_backward, Fskip_chars_forward): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4951
diff
changeset
|
362 STRING is like the inside of a `[...]' in a regular expression\n\ |
603 | 363 except that `]' is never special and `\\' quotes `^', `-' or `\\'.\n\ |
364 Thus, with arg \"a-zA-Z\", this skips letters stopping before first nonletter.\n\ | |
1684
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
365 With arg \"^a-zA-Z\", skips nonletters stopping before first letter.\n\ |
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
366 Returns the distance traveled, either zero or positive.") |
603 | 367 (string, lim) |
368 Lisp_Object string, lim; | |
369 { | |
1896
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
370 return skip_chars (1, 0, string, lim); |
603 | 371 } |
372 | |
373 DEFUN ("skip-chars-backward", Fskip_chars_backward, Sskip_chars_backward, 1, 2, 0, | |
4954
dc4d4f874b5c
(Fskip_chars_backward, Fskip_chars_forward): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4951
diff
changeset
|
374 "Move point backward, stopping after a char not in STRING, or at pos LIM.\n\ |
1684
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
375 See `skip-chars-forward' for details.\n\ |
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
376 Returns the distance traveled, either zero or negative.") |
603 | 377 (string, lim) |
378 Lisp_Object string, lim; | |
379 { | |
1896
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
380 return skip_chars (0, 0, string, lim); |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
381 } |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
382 |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
383 DEFUN ("skip-syntax-forward", Fskip_syntax_forward, Sskip_syntax_forward, 1, 2, 0, |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
384 "Move point forward across chars in specified syntax classes.\n\ |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
385 SYNTAX is a string of syntax code characters.\n\ |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
386 Stop before a char whose syntax is not in SYNTAX, or at position LIM.\n\ |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
387 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.\n\ |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
388 This function returns the distance traveled, either zero or positive.") |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
389 (syntax, lim) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
390 Lisp_Object syntax, lim; |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
391 { |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
392 return skip_chars (1, 1, syntax, lim); |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
393 } |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
394 |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
395 DEFUN ("skip-syntax-backward", Fskip_syntax_backward, Sskip_syntax_backward, 1, 2, 0, |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
396 "Move point backward across chars in specified syntax classes.\n\ |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
397 SYNTAX is a string of syntax code characters.\n\ |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
398 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.\n\ |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
399 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.\n\ |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
400 This function returns the distance traveled, either zero or negative.") |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
401 (syntax, lim) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
402 Lisp_Object syntax, lim; |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
403 { |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
404 return skip_chars (0, 1, syntax, lim); |
603 | 405 } |
406 | |
1684
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
407 Lisp_Object |
1896
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
408 skip_chars (forwardp, syntaxp, string, lim) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
409 int forwardp, syntaxp; |
603 | 410 Lisp_Object string, lim; |
411 { | |
412 register unsigned char *p, *pend; | |
413 register unsigned char c; | |
414 unsigned char fastmap[0400]; | |
415 int negate = 0; | |
416 register int i; | |
417 | |
418 CHECK_STRING (string, 0); | |
419 | |
420 if (NILP (lim)) | |
421 XSET (lim, Lisp_Int, forwardp ? ZV : BEGV); | |
422 else | |
423 CHECK_NUMBER_COERCE_MARKER (lim, 1); | |
424 | |
4831
66a523672100
(skip_chars): Reinstate check for end of buffer, ignoring cryptic
Brian Fox <bfox@gnu.org>
parents:
4713
diff
changeset
|
425 /* In any case, don't allow scan outside bounds of buffer. */ |
4951
be690aaa7194
(skip_chars): Finish reenabling checks for buffer bounds.
Richard M. Stallman <rms@gnu.org>
parents:
4882
diff
changeset
|
426 /* jla turned this off, for no known reason. |
be690aaa7194
(skip_chars): Finish reenabling checks for buffer bounds.
Richard M. Stallman <rms@gnu.org>
parents:
4882
diff
changeset
|
427 bfox turned the ZV part on, and rms turned the |
be690aaa7194
(skip_chars): Finish reenabling checks for buffer bounds.
Richard M. Stallman <rms@gnu.org>
parents:
4882
diff
changeset
|
428 BEGV part back on. */ |
be690aaa7194
(skip_chars): Finish reenabling checks for buffer bounds.
Richard M. Stallman <rms@gnu.org>
parents:
4882
diff
changeset
|
429 if (XINT (lim) > ZV) |
603 | 430 XFASTINT (lim) = ZV; |
4951
be690aaa7194
(skip_chars): Finish reenabling checks for buffer bounds.
Richard M. Stallman <rms@gnu.org>
parents:
4882
diff
changeset
|
431 if (XINT (lim) < BEGV) |
603 | 432 XFASTINT (lim) = BEGV; |
433 | |
434 p = XSTRING (string)->data; | |
435 pend = p + XSTRING (string)->size; | |
436 bzero (fastmap, sizeof fastmap); | |
437 | |
438 if (p != pend && *p == '^') | |
439 { | |
440 negate = 1; p++; | |
441 } | |
442 | |
1896
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
443 /* Find the characters specified and set their elements of fastmap. |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
444 If syntaxp, each character counts as itself. |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
445 Otherwise, handle backslashes and ranges specially */ |
603 | 446 |
447 while (p != pend) | |
448 { | |
449 c = *p++; | |
1896
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
450 if (syntaxp) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
451 fastmap[c] = 1; |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
452 else |
603 | 453 { |
1896
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
454 if (c == '\\') |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
455 { |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
456 if (p == pend) break; |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
457 c = *p++; |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
458 } |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
459 if (p != pend && *p == '-') |
603 | 460 { |
1896
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
461 p++; |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
462 if (p == pend) break; |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
463 while (c <= *p) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
464 { |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
465 fastmap[c] = 1; |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
466 c++; |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
467 } |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
468 p++; |
603 | 469 } |
1896
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
470 else |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
471 fastmap[c] = 1; |
603 | 472 } |
473 } | |
474 | |
475 /* If ^ was the first character, complement the fastmap. */ | |
476 | |
477 if (negate) | |
478 for (i = 0; i < sizeof fastmap; i++) | |
479 fastmap[i] ^= 1; | |
480 | |
1684
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
481 { |
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
482 int start_point = point; |
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
483 |
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
484 immediate_quit = 1; |
1896
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
485 if (syntaxp) |
1684
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
486 { |
1896
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
487 |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
488 if (forwardp) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
489 { |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
490 while (point < XINT (lim) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
491 && fastmap[(unsigned char) syntax_code_spec[(int) SYNTAX (FETCH_CHAR (point))]]) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
492 SET_PT (point + 1); |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
493 } |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
494 else |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
495 { |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
496 while (point > XINT (lim) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
497 && fastmap[(unsigned char) syntax_code_spec[(int) SYNTAX (FETCH_CHAR (point - 1))]]) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
498 SET_PT (point - 1); |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
499 } |
1684
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
500 } |
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
501 else |
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
502 { |
1896
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
503 if (forwardp) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
504 { |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
505 while (point < XINT (lim) && fastmap[FETCH_CHAR (point)]) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
506 SET_PT (point + 1); |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
507 } |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
508 else |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
509 { |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
510 while (point > XINT (lim) && fastmap[FETCH_CHAR (point - 1)]) |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
511 SET_PT (point - 1); |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
512 } |
1684
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
513 } |
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
514 immediate_quit = 0; |
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
515 |
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
516 return make_number (point - start_point); |
f4d848dea8ff
* search.c (Fskip_chars_forward, Fskip_chars_backward): Return the
Jim Blandy <jimb@redhat.com>
parents:
1523
diff
changeset
|
517 } |
603 | 518 } |
519 | |
520 /* Subroutines of Lisp buffer search functions. */ | |
521 | |
522 static Lisp_Object | |
523 search_command (string, bound, noerror, count, direction, RE) | |
524 Lisp_Object string, bound, noerror, count; | |
525 int direction; | |
526 int RE; | |
527 { | |
528 register int np; | |
529 int lim; | |
530 int n = direction; | |
531 | |
532 if (!NILP (count)) | |
533 { | |
534 CHECK_NUMBER (count, 3); | |
535 n *= XINT (count); | |
536 } | |
537 | |
538 CHECK_STRING (string, 0); | |
539 if (NILP (bound)) | |
540 lim = n > 0 ? ZV : BEGV; | |
541 else | |
542 { | |
543 CHECK_NUMBER_COERCE_MARKER (bound, 1); | |
544 lim = XINT (bound); | |
545 if (n > 0 ? lim < point : lim > point) | |
546 error ("Invalid search bound (wrong side of point)"); | |
547 if (lim > ZV) | |
548 lim = ZV; | |
549 if (lim < BEGV) | |
550 lim = BEGV; | |
551 } | |
552 | |
553 np = search_buffer (string, point, lim, n, RE, | |
554 (!NILP (current_buffer->case_fold_search) | |
555 ? XSTRING (current_buffer->case_canon_table)->data : 0), | |
556 (!NILP (current_buffer->case_fold_search) | |
557 ? XSTRING (current_buffer->case_eqv_table)->data : 0)); | |
558 if (np <= 0) | |
559 { | |
560 if (NILP (noerror)) | |
561 return signal_failure (string); | |
562 if (!EQ (noerror, Qt)) | |
563 { | |
564 if (lim < BEGV || lim > ZV) | |
565 abort (); | |
1878
1c26d0049d4f
(search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1877
diff
changeset
|
566 SET_PT (lim); |
1c26d0049d4f
(search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1877
diff
changeset
|
567 return Qnil; |
1c26d0049d4f
(search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1877
diff
changeset
|
568 #if 0 /* This would be clean, but maybe programs depend on |
1c26d0049d4f
(search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1877
diff
changeset
|
569 a value of nil here. */ |
1877
7786f61ec635
(search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents:
1684
diff
changeset
|
570 np = lim; |
1878
1c26d0049d4f
(search_command): #if 0 previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1877
diff
changeset
|
571 #endif |
603 | 572 } |
1877
7786f61ec635
(search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents:
1684
diff
changeset
|
573 else |
7786f61ec635
(search_command): When moving to LIM on failure, return LIM.
Richard M. Stallman <rms@gnu.org>
parents:
1684
diff
changeset
|
574 return Qnil; |
603 | 575 } |
576 | |
577 if (np < BEGV || np > ZV) | |
578 abort (); | |
579 | |
580 SET_PT (np); | |
581 | |
582 return make_number (np); | |
583 } | |
584 | |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
585 /* Search for the n'th occurrence of STRING in the current buffer, |
603 | 586 starting at position POS and stopping at position LIM, |
587 treating PAT as a literal string if RE is false or as | |
588 a regular expression if RE is true. | |
589 | |
590 If N is positive, searching is forward and LIM must be greater than POS. | |
591 If N is negative, searching is backward and LIM must be less than POS. | |
592 | |
593 Returns -x if only N-x occurrences found (x > 0), | |
594 or else the position at the beginning of the Nth occurrence | |
595 (if searching backward) or the end (if searching forward). */ | |
596 | |
597 search_buffer (string, pos, lim, n, RE, trt, inverse_trt) | |
598 Lisp_Object string; | |
599 int pos; | |
600 int lim; | |
601 int n; | |
602 int RE; | |
603 register unsigned char *trt; | |
604 register unsigned char *inverse_trt; | |
605 { | |
606 int len = XSTRING (string)->size; | |
607 unsigned char *base_pat = XSTRING (string)->data; | |
608 register int *BM_tab; | |
609 int *BM_tab_base; | |
610 register int direction = ((n > 0) ? 1 : -1); | |
611 register int dirlen; | |
612 int infinity, limit, k, stride_for_teases; | |
613 register unsigned char *pat, *cursor, *p_limit; | |
614 register int i, j; | |
615 unsigned char *p1, *p2; | |
616 int s1, s2; | |
617 | |
618 /* Null string is found at starting position. */ | |
4299
7a2e1d7362c5
(search_buffer): If n is 0, just return POS.
Richard M. Stallman <rms@gnu.org>
parents:
3615
diff
changeset
|
619 if (len == 0) |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
620 { |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
621 set_search_regs (pos, 0); |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
622 return pos; |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
623 } |
4299
7a2e1d7362c5
(search_buffer): If n is 0, just return POS.
Richard M. Stallman <rms@gnu.org>
parents:
3615
diff
changeset
|
624 |
7a2e1d7362c5
(search_buffer): If n is 0, just return POS.
Richard M. Stallman <rms@gnu.org>
parents:
3615
diff
changeset
|
625 /* Searching 0 times means don't move. */ |
7a2e1d7362c5
(search_buffer): If n is 0, just return POS.
Richard M. Stallman <rms@gnu.org>
parents:
3615
diff
changeset
|
626 if (n == 0) |
603 | 627 return pos; |
628 | |
629 if (RE) | |
708 | 630 compile_pattern (string, &searchbuf, &search_regs, (char *) trt); |
603 | 631 |
632 if (RE /* Here we detect whether the */ | |
633 /* generality of an RE search is */ | |
634 /* really needed. */ | |
635 /* first item is "exact match" */ | |
621 | 636 && *(searchbuf.buffer) == (char) RE_EXACTN_VALUE |
603 | 637 && searchbuf.buffer[1] + 2 == searchbuf.used) /*first is ONLY item */ |
638 { | |
639 RE = 0; /* can do straight (non RE) search */ | |
640 pat = (base_pat = (unsigned char *) searchbuf.buffer + 2); | |
641 /* trt already applied */ | |
642 len = searchbuf.used - 2; | |
643 } | |
644 else if (!RE) | |
645 { | |
646 pat = (unsigned char *) alloca (len); | |
647 | |
648 for (i = len; i--;) /* Copy the pattern; apply trt */ | |
649 *pat++ = (((int) trt) ? trt [*base_pat++] : *base_pat++); | |
650 pat -= len; base_pat = pat; | |
651 } | |
652 | |
653 if (RE) | |
654 { | |
655 immediate_quit = 1; /* Quit immediately if user types ^G, | |
656 because letting this function finish | |
657 can take too long. */ | |
658 QUIT; /* Do a pending quit right away, | |
659 to avoid paradoxical behavior */ | |
660 /* Get pointers and sizes of the two strings | |
661 that make up the visible portion of the buffer. */ | |
662 | |
663 p1 = BEGV_ADDR; | |
664 s1 = GPT - BEGV; | |
665 p2 = GAP_END_ADDR; | |
666 s2 = ZV - GPT; | |
667 if (s1 < 0) | |
668 { | |
669 p2 = p1; | |
670 s2 = ZV - BEGV; | |
671 s1 = 0; | |
672 } | |
673 if (s2 < 0) | |
674 { | |
675 s1 = ZV - BEGV; | |
676 s2 = 0; | |
677 } | |
678 while (n < 0) | |
679 { | |
2475
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
680 int val; |
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
681 val = re_search_2 (&searchbuf, (char *) p1, s1, (char *) p2, s2, |
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
682 pos - BEGV, lim - pos, &search_regs, |
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
683 /* Don't allow match past current point */ |
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
684 pos - BEGV); |
603 | 685 if (val == -2) |
686 matcher_overflow (); | |
687 if (val >= 0) | |
688 { | |
689 j = BEGV; | |
621 | 690 for (i = 0; i < search_regs.num_regs; i++) |
603 | 691 if (search_regs.start[i] >= 0) |
692 { | |
693 search_regs.start[i] += j; | |
694 search_regs.end[i] += j; | |
695 } | |
727 | 696 XSET (last_thing_searched, Lisp_Buffer, current_buffer); |
603 | 697 /* Set pos to the new position. */ |
698 pos = search_regs.start[0]; | |
699 } | |
700 else | |
701 { | |
702 immediate_quit = 0; | |
703 return (n); | |
704 } | |
705 n++; | |
706 } | |
707 while (n > 0) | |
708 { | |
2475
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
709 int val; |
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
710 val = re_search_2 (&searchbuf, (char *) p1, s1, (char *) p2, s2, |
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
711 pos - BEGV, lim - pos, &search_regs, |
052bbdf1b817
(search_buffer): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
712 lim - BEGV); |
603 | 713 if (val == -2) |
714 matcher_overflow (); | |
715 if (val >= 0) | |
716 { | |
717 j = BEGV; | |
621 | 718 for (i = 0; i < search_regs.num_regs; i++) |
603 | 719 if (search_regs.start[i] >= 0) |
720 { | |
721 search_regs.start[i] += j; | |
722 search_regs.end[i] += j; | |
723 } | |
727 | 724 XSET (last_thing_searched, Lisp_Buffer, current_buffer); |
603 | 725 pos = search_regs.end[0]; |
726 } | |
727 else | |
728 { | |
729 immediate_quit = 0; | |
730 return (0 - n); | |
731 } | |
732 n--; | |
733 } | |
734 immediate_quit = 0; | |
735 return (pos); | |
736 } | |
737 else /* non-RE case */ | |
738 { | |
739 #ifdef C_ALLOCA | |
740 int BM_tab_space[0400]; | |
741 BM_tab = &BM_tab_space[0]; | |
742 #else | |
743 BM_tab = (int *) alloca (0400 * sizeof (int)); | |
744 #endif | |
745 /* The general approach is that we are going to maintain that we know */ | |
746 /* the first (closest to the present position, in whatever direction */ | |
747 /* we're searching) character that could possibly be the last */ | |
748 /* (furthest from present position) character of a valid match. We */ | |
749 /* advance the state of our knowledge by looking at that character */ | |
750 /* and seeing whether it indeed matches the last character of the */ | |
751 /* pattern. If it does, we take a closer look. If it does not, we */ | |
752 /* move our pointer (to putative last characters) as far as is */ | |
753 /* logically possible. This amount of movement, which I call a */ | |
754 /* stride, will be the length of the pattern if the actual character */ | |
755 /* appears nowhere in the pattern, otherwise it will be the distance */ | |
756 /* from the last occurrence of that character to the end of the */ | |
757 /* pattern. */ | |
758 /* As a coding trick, an enormous stride is coded into the table for */ | |
759 /* characters that match the last character. This allows use of only */ | |
760 /* a single test, a test for having gone past the end of the */ | |
761 /* permissible match region, to test for both possible matches (when */ | |
762 /* the stride goes past the end immediately) and failure to */ | |
763 /* match (where you get nudged past the end one stride at a time). */ | |
764 | |
765 /* Here we make a "mickey mouse" BM table. The stride of the search */ | |
766 /* is determined only by the last character of the putative match. */ | |
767 /* If that character does not match, we will stride the proper */ | |
768 /* distance to propose a match that superimposes it on the last */ | |
769 /* instance of a character that matches it (per trt), or misses */ | |
770 /* it entirely if there is none. */ | |
771 | |
772 dirlen = len * direction; | |
773 infinity = dirlen - (lim + pos + len + len) * direction; | |
774 if (direction < 0) | |
775 pat = (base_pat += len - 1); | |
776 BM_tab_base = BM_tab; | |
777 BM_tab += 0400; | |
778 j = dirlen; /* to get it in a register */ | |
779 /* A character that does not appear in the pattern induces a */ | |
780 /* stride equal to the pattern length. */ | |
781 while (BM_tab_base != BM_tab) | |
782 { | |
783 *--BM_tab = j; | |
784 *--BM_tab = j; | |
785 *--BM_tab = j; | |
786 *--BM_tab = j; | |
787 } | |
788 i = 0; | |
789 while (i != infinity) | |
790 { | |
791 j = pat[i]; i += direction; | |
792 if (i == dirlen) i = infinity; | |
793 if ((int) trt) | |
794 { | |
795 k = (j = trt[j]); | |
796 if (i == infinity) | |
797 stride_for_teases = BM_tab[j]; | |
798 BM_tab[j] = dirlen - i; | |
799 /* A translation table is accompanied by its inverse -- see */ | |
800 /* comment following downcase_table for details */ | |
801 while ((j = inverse_trt[j]) != k) | |
802 BM_tab[j] = dirlen - i; | |
803 } | |
804 else | |
805 { | |
806 if (i == infinity) | |
807 stride_for_teases = BM_tab[j]; | |
808 BM_tab[j] = dirlen - i; | |
809 } | |
810 /* stride_for_teases tells how much to stride if we get a */ | |
811 /* match on the far character but are subsequently */ | |
812 /* disappointed, by recording what the stride would have been */ | |
813 /* for that character if the last character had been */ | |
814 /* different. */ | |
815 } | |
816 infinity = dirlen - infinity; | |
817 pos += dirlen - ((direction > 0) ? direction : 0); | |
818 /* loop invariant - pos points at where last char (first char if reverse) | |
819 of pattern would align in a possible match. */ | |
820 while (n != 0) | |
821 { | |
822 if ((lim - pos - (direction > 0)) * direction < 0) | |
823 return (n * (0 - direction)); | |
824 /* First we do the part we can by pointers (maybe nothing) */ | |
825 QUIT; | |
826 pat = base_pat; | |
827 limit = pos - dirlen + direction; | |
828 limit = ((direction > 0) | |
829 ? BUFFER_CEILING_OF (limit) | |
830 : BUFFER_FLOOR_OF (limit)); | |
831 /* LIMIT is now the last (not beyond-last!) value | |
832 POS can take on without hitting edge of buffer or the gap. */ | |
833 limit = ((direction > 0) | |
834 ? min (lim - 1, min (limit, pos + 20000)) | |
835 : max (lim, max (limit, pos - 20000))); | |
836 if ((limit - pos) * direction > 20) | |
837 { | |
838 p_limit = &FETCH_CHAR (limit); | |
839 p2 = (cursor = &FETCH_CHAR (pos)); | |
840 /* In this loop, pos + cursor - p2 is the surrogate for pos */ | |
841 while (1) /* use one cursor setting as long as i can */ | |
842 { | |
843 if (direction > 0) /* worth duplicating */ | |
844 { | |
845 /* Use signed comparison if appropriate | |
846 to make cursor+infinity sure to be > p_limit. | |
847 Assuming that the buffer lies in a range of addresses | |
848 that are all "positive" (as ints) or all "negative", | |
849 either kind of comparison will work as long | |
850 as we don't step by infinity. So pick the kind | |
851 that works when we do step by infinity. */ | |
852 if ((int) (p_limit + infinity) > (int) p_limit) | |
853 while ((int) cursor <= (int) p_limit) | |
854 cursor += BM_tab[*cursor]; | |
855 else | |
856 while ((unsigned int) cursor <= (unsigned int) p_limit) | |
857 cursor += BM_tab[*cursor]; | |
858 } | |
859 else | |
860 { | |
861 if ((int) (p_limit + infinity) < (int) p_limit) | |
862 while ((int) cursor >= (int) p_limit) | |
863 cursor += BM_tab[*cursor]; | |
864 else | |
865 while ((unsigned int) cursor >= (unsigned int) p_limit) | |
866 cursor += BM_tab[*cursor]; | |
867 } | |
868 /* If you are here, cursor is beyond the end of the searched region. */ | |
869 /* This can happen if you match on the far character of the pattern, */ | |
870 /* because the "stride" of that character is infinity, a number able */ | |
871 /* to throw you well beyond the end of the search. It can also */ | |
872 /* happen if you fail to match within the permitted region and would */ | |
873 /* otherwise try a character beyond that region */ | |
874 if ((cursor - p_limit) * direction <= len) | |
875 break; /* a small overrun is genuine */ | |
876 cursor -= infinity; /* large overrun = hit */ | |
877 i = dirlen - direction; | |
878 if ((int) trt) | |
879 { | |
880 while ((i -= direction) + direction != 0) | |
881 if (pat[i] != trt[*(cursor -= direction)]) | |
882 break; | |
883 } | |
884 else | |
885 { | |
886 while ((i -= direction) + direction != 0) | |
887 if (pat[i] != *(cursor -= direction)) | |
888 break; | |
889 } | |
890 cursor += dirlen - i - direction; /* fix cursor */ | |
891 if (i + direction == 0) | |
892 { | |
893 cursor -= direction; | |
708 | 894 |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
895 set_search_regs (pos + cursor - p2 + ((direction > 0) |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
896 ? 1 - len : 0), |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
897 len); |
708 | 898 |
603 | 899 if ((n -= direction) != 0) |
900 cursor += dirlen; /* to resume search */ | |
901 else | |
902 return ((direction > 0) | |
903 ? search_regs.end[0] : search_regs.start[0]); | |
904 } | |
905 else | |
906 cursor += stride_for_teases; /* <sigh> we lose - */ | |
907 } | |
908 pos += cursor - p2; | |
909 } | |
910 else | |
911 /* Now we'll pick up a clump that has to be done the hard */ | |
912 /* way because it covers a discontinuity */ | |
913 { | |
914 limit = ((direction > 0) | |
915 ? BUFFER_CEILING_OF (pos - dirlen + 1) | |
916 : BUFFER_FLOOR_OF (pos - dirlen - 1)); | |
917 limit = ((direction > 0) | |
918 ? min (limit + len, lim - 1) | |
919 : max (limit - len, lim)); | |
920 /* LIMIT is now the last value POS can have | |
921 and still be valid for a possible match. */ | |
922 while (1) | |
923 { | |
924 /* This loop can be coded for space rather than */ | |
925 /* speed because it will usually run only once. */ | |
926 /* (the reach is at most len + 21, and typically */ | |
927 /* does not exceed len) */ | |
928 while ((limit - pos) * direction >= 0) | |
929 pos += BM_tab[FETCH_CHAR(pos)]; | |
930 /* now run the same tests to distinguish going off the */ | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
931 /* end, a match or a phony match. */ |
603 | 932 if ((pos - limit) * direction <= len) |
933 break; /* ran off the end */ | |
934 /* Found what might be a match. | |
935 Set POS back to last (first if reverse) char pos. */ | |
936 pos -= infinity; | |
937 i = dirlen - direction; | |
938 while ((i -= direction) + direction != 0) | |
939 { | |
940 pos -= direction; | |
941 if (pat[i] != (((int) trt) | |
942 ? trt[FETCH_CHAR(pos)] | |
943 : FETCH_CHAR (pos))) | |
944 break; | |
945 } | |
946 /* Above loop has moved POS part or all the way | |
947 back to the first char pos (last char pos if reverse). | |
948 Set it once again at the last (first if reverse) char. */ | |
949 pos += dirlen - i- direction; | |
950 if (i + direction == 0) | |
951 { | |
952 pos -= direction; | |
708 | 953 |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
954 set_search_regs (pos + ((direction > 0) ? 1 - len : 0), |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
955 len); |
708 | 956 |
603 | 957 if ((n -= direction) != 0) |
958 pos += dirlen; /* to resume search */ | |
959 else | |
960 return ((direction > 0) | |
961 ? search_regs.end[0] : search_regs.start[0]); | |
962 } | |
963 else | |
964 pos += stride_for_teases; | |
965 } | |
966 } | |
967 /* We have done one clump. Can we continue? */ | |
968 if ((lim - pos) * direction < 0) | |
969 return ((0 - n) * direction); | |
970 } | |
971 return pos; | |
972 } | |
973 } | |
5556
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
974 |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
975 /* Record beginning BEG and end BEG + LEN |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
976 for a match just found in the current buffer. */ |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
977 |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
978 static void |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
979 set_search_regs (beg, len) |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
980 int beg, len; |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
981 { |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
982 /* Make sure we have registers in which to store |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
983 the match position. */ |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
984 if (search_regs.num_regs == 0) |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
985 { |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
986 regoff_t *starts, *ends; |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
987 |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
988 starts = (regoff_t *) xmalloc (2 * sizeof (regoff_t)); |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
989 ends = (regoff_t *) xmalloc (2 * sizeof (regoff_t)); |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
990 BLOCK_INPUT; |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
991 re_set_registers (&searchbuf, |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
992 &search_regs, |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
993 2, starts, ends); |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
994 UNBLOCK_INPUT; |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
995 } |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
996 |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
997 search_regs.start[0] = beg; |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
998 search_regs.end[0] = beg + len; |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
999 XSET (last_thing_searched, Lisp_Buffer, current_buffer); |
14161cfec24a
(set_search_regs): New subroutine.
Richard M. Stallman <rms@gnu.org>
parents:
4954
diff
changeset
|
1000 } |
603 | 1001 |
1002 /* Given a string of words separated by word delimiters, | |
1003 compute a regexp that matches those exact words | |
1004 separated by arbitrary punctuation. */ | |
1005 | |
1006 static Lisp_Object | |
1007 wordify (string) | |
1008 Lisp_Object string; | |
1009 { | |
1010 register unsigned char *p, *o; | |
1011 register int i, len, punct_count = 0, word_count = 0; | |
1012 Lisp_Object val; | |
1013 | |
1014 CHECK_STRING (string, 0); | |
1015 p = XSTRING (string)->data; | |
1016 len = XSTRING (string)->size; | |
1017 | |
1018 for (i = 0; i < len; i++) | |
1019 if (SYNTAX (p[i]) != Sword) | |
1020 { | |
1021 punct_count++; | |
1022 if (i > 0 && SYNTAX (p[i-1]) == Sword) word_count++; | |
1023 } | |
1024 if (SYNTAX (p[len-1]) == Sword) word_count++; | |
1025 if (!word_count) return build_string (""); | |
1026 | |
1027 val = make_string (p, len - punct_count + 5 * (word_count - 1) + 4); | |
1028 | |
1029 o = XSTRING (val)->data; | |
1030 *o++ = '\\'; | |
1031 *o++ = 'b'; | |
1032 | |
1033 for (i = 0; i < len; i++) | |
1034 if (SYNTAX (p[i]) == Sword) | |
1035 *o++ = p[i]; | |
1036 else if (i > 0 && SYNTAX (p[i-1]) == Sword && --word_count) | |
1037 { | |
1038 *o++ = '\\'; | |
1039 *o++ = 'W'; | |
1040 *o++ = '\\'; | |
1041 *o++ = 'W'; | |
1042 *o++ = '*'; | |
1043 } | |
1044 | |
1045 *o++ = '\\'; | |
1046 *o++ = 'b'; | |
1047 | |
1048 return val; | |
1049 } | |
1050 | |
1051 DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4, | |
1052 "sSearch backward: ", | |
1053 "Search backward from point for STRING.\n\ | |
1054 Set point to the beginning of the occurrence found, and return point.\n\ | |
1055 An optional second argument bounds the search; it is a buffer position.\n\ | |
1056 The match found must not extend before that position.\n\ | |
1057 Optional third argument, if t, means if fail just return nil (no error).\n\ | |
1058 If not nil and not t, position at limit of search and return nil.\n\ | |
1059 Optional fourth argument is repeat count--search for successive occurrences.\n\ | |
1060 See also the functions `match-beginning', `match-end' and `replace-match'.") | |
1061 (string, bound, noerror, count) | |
1062 Lisp_Object string, bound, noerror, count; | |
1063 { | |
1064 return search_command (string, bound, noerror, count, -1, 0); | |
1065 } | |
1066 | |
1067 DEFUN ("search-forward", Fsearch_forward, Ssearch_forward, 1, 4, "sSearch: ", | |
1068 "Search forward from point for STRING.\n\ | |
1069 Set point to the end of the occurrence found, and return point.\n\ | |
1070 An optional second argument bounds the search; it is a buffer position.\n\ | |
1071 The match found must not extend after that position. nil is equivalent\n\ | |
1072 to (point-max).\n\ | |
1073 Optional third argument, if t, means if fail just return nil (no error).\n\ | |
1074 If not nil and not t, move to limit of search and return nil.\n\ | |
1075 Optional fourth argument is repeat count--search for successive occurrences.\n\ | |
1076 See also the functions `match-beginning', `match-end' and `replace-match'.") | |
1077 (string, bound, noerror, count) | |
1078 Lisp_Object string, bound, noerror, count; | |
1079 { | |
1080 return search_command (string, bound, noerror, count, 1, 0); | |
1081 } | |
1082 | |
1083 DEFUN ("word-search-backward", Fword_search_backward, Sword_search_backward, 1, 4, | |
1084 "sWord search backward: ", | |
1085 "Search backward from point for STRING, ignoring differences in punctuation.\n\ | |
1086 Set point to the beginning of the occurrence found, and return point.\n\ | |
1087 An optional second argument bounds the search; it is a buffer position.\n\ | |
1088 The match found must not extend before that position.\n\ | |
1089 Optional third argument, if t, means if fail just return nil (no error).\n\ | |
1090 If not nil and not t, move to limit of search and return nil.\n\ | |
1091 Optional fourth argument is repeat count--search for successive occurrences.") | |
1092 (string, bound, noerror, count) | |
1093 Lisp_Object string, bound, noerror, count; | |
1094 { | |
1095 return search_command (wordify (string), bound, noerror, count, -1, 1); | |
1096 } | |
1097 | |
1098 DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4, | |
1099 "sWord search: ", | |
1100 "Search forward from point for STRING, ignoring differences in punctuation.\n\ | |
1101 Set point to the end of the occurrence found, and return point.\n\ | |
1102 An optional second argument bounds the search; it is a buffer position.\n\ | |
1103 The match found must not extend after that position.\n\ | |
1104 Optional third argument, if t, means if fail just return nil (no error).\n\ | |
1105 If not nil and not t, move to limit of search and return nil.\n\ | |
1106 Optional fourth argument is repeat count--search for successive occurrences.") | |
1107 (string, bound, noerror, count) | |
1108 Lisp_Object string, bound, noerror, count; | |
1109 { | |
1110 return search_command (wordify (string), bound, noerror, count, 1, 1); | |
1111 } | |
1112 | |
1113 DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, | |
1114 "sRE search backward: ", | |
1115 "Search backward from point for match for regular expression REGEXP.\n\ | |
1116 Set point to the beginning of the match, and return point.\n\ | |
1117 The match found is the one starting last in the buffer\n\ | |
1118 and yet ending before the place the origin of the search.\n\ | |
1119 An optional second argument bounds the search; it is a buffer position.\n\ | |
1120 The match found must start at or after that position.\n\ | |
1121 Optional third argument, if t, means if fail just return nil (no error).\n\ | |
1122 If not nil and not t, move to limit of search and return nil.\n\ | |
1123 Optional fourth argument is repeat count--search for successive occurrences.\n\ | |
1124 See also the functions `match-beginning', `match-end' and `replace-match'.") | |
1125 (string, bound, noerror, count) | |
1126 Lisp_Object string, bound, noerror, count; | |
1127 { | |
1128 return search_command (string, bound, noerror, count, -1, 1); | |
1129 } | |
1130 | |
1131 DEFUN ("re-search-forward", Fre_search_forward, Sre_search_forward, 1, 4, | |
1132 "sRE search: ", | |
1133 "Search forward from point for regular expression REGEXP.\n\ | |
1134 Set point to the end of the occurrence found, and return point.\n\ | |
1135 An optional second argument bounds the search; it is a buffer position.\n\ | |
1136 The match found must not extend after that position.\n\ | |
1137 Optional third argument, if t, means if fail just return nil (no error).\n\ | |
1138 If not nil and not t, move to limit of search and return nil.\n\ | |
1139 Optional fourth argument is repeat count--search for successive occurrences.\n\ | |
1140 See also the functions `match-beginning', `match-end' and `replace-match'.") | |
1141 (string, bound, noerror, count) | |
1142 Lisp_Object string, bound, noerror, count; | |
1143 { | |
1144 return search_command (string, bound, noerror, count, 1, 1); | |
1145 } | |
1146 | |
1147 DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 3, 0, | |
1148 "Replace text matched by last search with NEWTEXT.\n\ | |
1149 If second arg FIXEDCASE is non-nil, do not alter case of replacement text.\n\ | |
1150 Otherwise convert to all caps or cap initials, like replaced text.\n\ | |
1151 If third arg LITERAL is non-nil, insert NEWTEXT literally.\n\ | |
1152 Otherwise treat `\\' as special:\n\ | |
1153 `\\&' in NEWTEXT means substitute original matched text.\n\ | |
1154 `\\N' means substitute what matched the Nth `\\(...\\)'.\n\ | |
1155 If Nth parens didn't match, substitute nothing.\n\ | |
1156 `\\\\' means insert one `\\'.\n\ | |
708 | 1157 FIXEDCASE and LITERAL are optional arguments.\n\ |
603 | 1158 Leaves point at end of replacement text.") |
4882
8c09f87f5087
(Freplace_match): Fix argument names to match doc string.
Brian Fox <bfox@gnu.org>
parents:
4832
diff
changeset
|
1159 (newtext, fixedcase, literal) |
8c09f87f5087
(Freplace_match): Fix argument names to match doc string.
Brian Fox <bfox@gnu.org>
parents:
4832
diff
changeset
|
1160 Lisp_Object newtext, fixedcase, literal; |
603 | 1161 { |
1162 enum { nochange, all_caps, cap_initial } case_action; | |
1163 register int pos, last; | |
1164 int some_multiletter_word; | |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1165 int some_lowercase; |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1166 int some_uppercase_initial; |
603 | 1167 register int c, prevc; |
1168 int inslen; | |
1169 | |
4882
8c09f87f5087
(Freplace_match): Fix argument names to match doc string.
Brian Fox <bfox@gnu.org>
parents:
4832
diff
changeset
|
1170 CHECK_STRING (newtext, 0); |
603 | 1171 |
1172 case_action = nochange; /* We tried an initialization */ | |
1173 /* but some C compilers blew it */ | |
621 | 1174 |
1175 if (search_regs.num_regs <= 0) | |
1176 error ("replace-match called before any match found"); | |
1177 | |
603 | 1178 if (search_regs.start[0] < BEGV |
1179 || search_regs.start[0] > search_regs.end[0] | |
1180 || search_regs.end[0] > ZV) | |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1181 args_out_of_range (make_number (search_regs.start[0]), |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1182 make_number (search_regs.end[0])); |
603 | 1183 |
1184 if (NILP (fixedcase)) | |
1185 { | |
1186 /* Decide how to casify by examining the matched text. */ | |
1187 | |
1188 last = search_regs.end[0]; | |
1189 prevc = '\n'; | |
1190 case_action = all_caps; | |
1191 | |
1192 /* some_multiletter_word is set nonzero if any original word | |
1193 is more than one letter long. */ | |
1194 some_multiletter_word = 0; | |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1195 some_lowercase = 0; |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1196 some_uppercase_initial = 0; |
603 | 1197 |
1198 for (pos = search_regs.start[0]; pos < last; pos++) | |
1199 { | |
1200 c = FETCH_CHAR (pos); | |
1201 if (LOWERCASEP (c)) | |
1202 { | |
1203 /* Cannot be all caps if any original char is lower case */ | |
1204 | |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1205 some_lowercase = 1; |
603 | 1206 if (SYNTAX (prevc) != Sword) |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1207 ; |
603 | 1208 else |
1209 some_multiletter_word = 1; | |
1210 } | |
1211 else if (!NOCASEP (c)) | |
1212 { | |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1213 if (SYNTAX (prevc) != Sword) |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1214 some_uppercase_initial = 1; |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1215 else |
603 | 1216 some_multiletter_word = 1; |
1217 } | |
1218 | |
1219 prevc = c; | |
1220 } | |
1221 | |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1222 /* Convert to all caps if the old text is all caps |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1223 and has at least one multiletter word. */ |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1224 if (! some_lowercase && some_multiletter_word) |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1225 case_action = all_caps; |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1226 /* Capitalize each word, if the old text has a capitalized word. */ |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1227 else if (some_uppercase_initial) |
603 | 1228 case_action = cap_initial; |
2393
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1229 else |
a35d2c5cbb3b
(Freplace_match): Clean up criterion about converting case.
Richard M. Stallman <rms@gnu.org>
parents:
1926
diff
changeset
|
1230 case_action = nochange; |
603 | 1231 } |
1232 | |
2655
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1233 /* We insert the replacement text before the old text, and then |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1234 delete the original text. This means that markers at the |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1235 beginning or end of the original will float to the corresponding |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1236 position in the replacement. */ |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1237 SET_PT (search_regs.start[0]); |
603 | 1238 if (!NILP (literal)) |
4882
8c09f87f5087
(Freplace_match): Fix argument names to match doc string.
Brian Fox <bfox@gnu.org>
parents:
4832
diff
changeset
|
1239 Finsert_and_inherit (1, &newtext); |
603 | 1240 else |
1241 { | |
1242 struct gcpro gcpro1; | |
4882
8c09f87f5087
(Freplace_match): Fix argument names to match doc string.
Brian Fox <bfox@gnu.org>
parents:
4832
diff
changeset
|
1243 GCPRO1 (newtext); |
603 | 1244 |
4882
8c09f87f5087
(Freplace_match): Fix argument names to match doc string.
Brian Fox <bfox@gnu.org>
parents:
4832
diff
changeset
|
1245 for (pos = 0; pos < XSTRING (newtext)->size; pos++) |
603 | 1246 { |
2655
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1247 int offset = point - search_regs.start[0]; |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1248 |
4882
8c09f87f5087
(Freplace_match): Fix argument names to match doc string.
Brian Fox <bfox@gnu.org>
parents:
4832
diff
changeset
|
1249 c = XSTRING (newtext)->data[pos]; |
603 | 1250 if (c == '\\') |
1251 { | |
4882
8c09f87f5087
(Freplace_match): Fix argument names to match doc string.
Brian Fox <bfox@gnu.org>
parents:
4832
diff
changeset
|
1252 c = XSTRING (newtext)->data[++pos]; |
603 | 1253 if (c == '&') |
2655
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1254 Finsert_buffer_substring |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1255 (Fcurrent_buffer (), |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1256 make_number (search_regs.start[0] + offset), |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1257 make_number (search_regs.end[0] + offset)); |
621 | 1258 else if (c >= '1' && c <= search_regs.num_regs + '0') |
603 | 1259 { |
1260 if (search_regs.start[c - '0'] >= 1) | |
2655
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1261 Finsert_buffer_substring |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1262 (Fcurrent_buffer (), |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1263 make_number (search_regs.start[c - '0'] + offset), |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1264 make_number (search_regs.end[c - '0'] + offset)); |
603 | 1265 } |
1266 else | |
1267 insert_char (c); | |
1268 } | |
1269 else | |
1270 insert_char (c); | |
1271 } | |
1272 UNGCPRO; | |
1273 } | |
1274 | |
2655
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1275 inslen = point - (search_regs.start[0]); |
594a33ffed85
* search.c (Freplace_match): Arrange for markers sitting at the
Jim Blandy <jimb@redhat.com>
parents:
2475
diff
changeset
|
1276 del_range (search_regs.start[0] + inslen, search_regs.end[0] + inslen); |
603 | 1277 |
1278 if (case_action == all_caps) | |
1279 Fupcase_region (make_number (point - inslen), make_number (point)); | |
1280 else if (case_action == cap_initial) | |
1281 upcase_initials_region (make_number (point - inslen), make_number (point)); | |
1282 return Qnil; | |
1283 } | |
1284 | |
1285 static Lisp_Object | |
1286 match_limit (num, beginningp) | |
1287 Lisp_Object num; | |
1288 int beginningp; | |
1289 { | |
1290 register int n; | |
1291 | |
1292 CHECK_NUMBER (num, 0); | |
1293 n = XINT (num); | |
621 | 1294 if (n < 0 || n >= search_regs.num_regs) |
1295 args_out_of_range (num, make_number (search_regs.num_regs)); | |
1296 if (search_regs.num_regs <= 0 | |
1297 || search_regs.start[n] < 0) | |
603 | 1298 return Qnil; |
1299 return (make_number ((beginningp) ? search_regs.start[n] | |
1300 : search_regs.end[n])); | |
1301 } | |
1302 | |
1303 DEFUN ("match-beginning", Fmatch_beginning, Smatch_beginning, 1, 1, 0, | |
1304 "Return position of start of text matched by last search.\n\ | |
4882
8c09f87f5087
(Freplace_match): Fix argument names to match doc string.
Brian Fox <bfox@gnu.org>
parents:
4832
diff
changeset
|
1305 NUM specifies which parenthesized expression in the last regexp.\n\ |
8c09f87f5087
(Freplace_match): Fix argument names to match doc string.
Brian Fox <bfox@gnu.org>
parents:
4832
diff
changeset
|
1306 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.\n\ |
603 | 1307 Zero means the entire text matched by the whole regexp or whole string.") |
1308 (num) | |
1309 Lisp_Object num; | |
1310 { | |
1311 return match_limit (num, 1); | |
1312 } | |
1313 | |
1314 DEFUN ("match-end", Fmatch_end, Smatch_end, 1, 1, 0, | |
1315 "Return position of end of text matched by last search.\n\ | |
1316 ARG, a number, specifies which parenthesized expression in the last regexp.\n\ | |
1317 Value is nil if ARGth pair didn't match, or there were less than ARG pairs.\n\ | |
1318 Zero means the entire text matched by the whole regexp or whole string.") | |
1319 (num) | |
1320 Lisp_Object num; | |
1321 { | |
1322 return match_limit (num, 0); | |
1323 } | |
1324 | |
1325 DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 0, 0, | |
1326 "Return a list containing all info on what the last search matched.\n\ | |
1327 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'.\n\ | |
1328 All the elements are markers or nil (nil if the Nth pair didn't match)\n\ | |
1329 if the last match was on a buffer; integers or nil if a string was matched.\n\ | |
1330 Use `store-match-data' to reinstate the data in this list.") | |
1331 () | |
1332 { | |
621 | 1333 Lisp_Object *data; |
603 | 1334 int i, len; |
1335 | |
727 | 1336 if (NILP (last_thing_searched)) |
1337 error ("match-data called before any match found"); | |
1338 | |
621 | 1339 data = (Lisp_Object *) alloca ((2 * search_regs.num_regs) |
1340 * sizeof (Lisp_Object)); | |
1341 | |
603 | 1342 len = -1; |
621 | 1343 for (i = 0; i < search_regs.num_regs; i++) |
603 | 1344 { |
1345 int start = search_regs.start[i]; | |
1346 if (start >= 0) | |
1347 { | |
727 | 1348 if (EQ (last_thing_searched, Qt)) |
603 | 1349 { |
1350 XFASTINT (data[2 * i]) = start; | |
1351 XFASTINT (data[2 * i + 1]) = search_regs.end[i]; | |
1352 } | |
727 | 1353 else if (XTYPE (last_thing_searched) == Lisp_Buffer) |
603 | 1354 { |
1355 data[2 * i] = Fmake_marker (); | |
727 | 1356 Fset_marker (data[2 * i], |
1357 make_number (start), | |
1358 last_thing_searched); | |
603 | 1359 data[2 * i + 1] = Fmake_marker (); |
1360 Fset_marker (data[2 * i + 1], | |
727 | 1361 make_number (search_regs.end[i]), |
1362 last_thing_searched); | |
603 | 1363 } |
727 | 1364 else |
1365 /* last_thing_searched must always be Qt, a buffer, or Qnil. */ | |
1366 abort (); | |
1367 | |
603 | 1368 len = i; |
1369 } | |
1370 else | |
1371 data[2 * i] = data [2 * i + 1] = Qnil; | |
1372 } | |
1373 return Flist (2 * len + 2, data); | |
1374 } | |
1375 | |
1376 | |
1377 DEFUN ("store-match-data", Fstore_match_data, Sstore_match_data, 1, 1, 0, | |
1378 "Set internal data on last search match from elements of LIST.\n\ | |
1379 LIST should have been created by calling `match-data' previously.") | |
1380 (list) | |
1381 register Lisp_Object list; | |
1382 { | |
1383 register int i; | |
1384 register Lisp_Object marker; | |
1385 | |
1386 if (!CONSP (list) && !NILP (list)) | |
1926
952f2a18f83d
* callint.c (Fcall_interactively): Pass the correct number of
Jim Blandy <jimb@redhat.com>
parents:
1896
diff
changeset
|
1387 list = wrong_type_argument (Qconsp, list); |
603 | 1388 |
727 | 1389 /* Unless we find a marker with a buffer in LIST, assume that this |
1390 match data came from a string. */ | |
1391 last_thing_searched = Qt; | |
1392 | |
621 | 1393 /* Allocate registers if they don't already exist. */ |
1394 { | |
1523
bd61aaa7828b
* search.c (Fstore_match_data): Don't assume Flength returns an
Jim Blandy <jimb@redhat.com>
parents:
1413
diff
changeset
|
1395 int length = XFASTINT (Flength (list)) / 2; |
621 | 1396 |
1397 if (length > search_regs.num_regs) | |
1398 { | |
708 | 1399 if (search_regs.num_regs == 0) |
1400 { | |
1401 search_regs.start | |
1402 = (regoff_t *) xmalloc (length * sizeof (regoff_t)); | |
1403 search_regs.end | |
1404 = (regoff_t *) xmalloc (length * sizeof (regoff_t)); | |
1405 } | |
621 | 1406 else |
708 | 1407 { |
1408 search_regs.start | |
1409 = (regoff_t *) xrealloc (search_regs.start, | |
1410 length * sizeof (regoff_t)); | |
1411 search_regs.end | |
1412 = (regoff_t *) xrealloc (search_regs.end, | |
1413 length * sizeof (regoff_t)); | |
1414 } | |
621 | 1415 |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2393
diff
changeset
|
1416 BLOCK_INPUT; |
708 | 1417 re_set_registers (&searchbuf, &search_regs, length, |
1418 search_regs.start, search_regs.end); | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2393
diff
changeset
|
1419 UNBLOCK_INPUT; |
621 | 1420 } |
1421 } | |
1422 | |
1423 for (i = 0; i < search_regs.num_regs; i++) | |
603 | 1424 { |
1425 marker = Fcar (list); | |
1426 if (NILP (marker)) | |
1427 { | |
1428 search_regs.start[i] = -1; | |
1429 list = Fcdr (list); | |
1430 } | |
1431 else | |
1432 { | |
727 | 1433 if (XTYPE (marker) == Lisp_Marker) |
1434 { | |
1435 if (XMARKER (marker)->buffer == 0) | |
1436 XFASTINT (marker) = 0; | |
1437 else | |
1438 XSET (last_thing_searched, Lisp_Buffer, | |
1439 XMARKER (marker)->buffer); | |
1440 } | |
603 | 1441 |
1442 CHECK_NUMBER_COERCE_MARKER (marker, 0); | |
1443 search_regs.start[i] = XINT (marker); | |
1444 list = Fcdr (list); | |
1445 | |
1446 marker = Fcar (list); | |
1447 if (XTYPE (marker) == Lisp_Marker | |
1448 && XMARKER (marker)->buffer == 0) | |
1449 XFASTINT (marker) = 0; | |
1450 | |
1451 CHECK_NUMBER_COERCE_MARKER (marker, 0); | |
1452 search_regs.end[i] = XINT (marker); | |
1453 } | |
1454 list = Fcdr (list); | |
1455 } | |
1456 | |
1457 return Qnil; | |
1458 } | |
1459 | |
1460 /* Quote a string to inactivate reg-expr chars */ | |
1461 | |
1462 DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0, | |
1463 "Return a regexp string which matches exactly STRING and nothing else.") | |
1464 (str) | |
1465 Lisp_Object str; | |
1466 { | |
1467 register unsigned char *in, *out, *end; | |
1468 register unsigned char *temp; | |
1469 | |
1470 CHECK_STRING (str, 0); | |
1471 | |
1472 temp = (unsigned char *) alloca (XSTRING (str)->size * 2); | |
1473 | |
1474 /* Now copy the data into the new string, inserting escapes. */ | |
1475 | |
1476 in = XSTRING (str)->data; | |
1477 end = in + XSTRING (str)->size; | |
1478 out = temp; | |
1479 | |
1480 for (; in != end; in++) | |
1481 { | |
1482 if (*in == '[' || *in == ']' | |
1483 || *in == '*' || *in == '.' || *in == '\\' | |
1484 || *in == '?' || *in == '+' | |
1485 || *in == '^' || *in == '$') | |
1486 *out++ = '\\'; | |
1487 *out++ = *in; | |
1488 } | |
1489 | |
1490 return make_string (temp, out - temp); | |
1491 } | |
1492 | |
1493 syms_of_search () | |
1494 { | |
1495 register int i; | |
1496 | |
1497 searchbuf.allocated = 100; | |
605 | 1498 searchbuf.buffer = (unsigned char *) malloc (searchbuf.allocated); |
603 | 1499 searchbuf.fastmap = search_fastmap; |
1500 | |
1501 Qsearch_failed = intern ("search-failed"); | |
1502 staticpro (&Qsearch_failed); | |
1503 Qinvalid_regexp = intern ("invalid-regexp"); | |
1504 staticpro (&Qinvalid_regexp); | |
1505 | |
1506 Fput (Qsearch_failed, Qerror_conditions, | |
1507 Fcons (Qsearch_failed, Fcons (Qerror, Qnil))); | |
1508 Fput (Qsearch_failed, Qerror_message, | |
1509 build_string ("Search failed")); | |
1510 | |
1511 Fput (Qinvalid_regexp, Qerror_conditions, | |
1512 Fcons (Qinvalid_regexp, Fcons (Qerror, Qnil))); | |
1513 Fput (Qinvalid_regexp, Qerror_message, | |
1514 build_string ("Invalid regexp")); | |
1515 | |
1516 last_regexp = Qnil; | |
1517 staticpro (&last_regexp); | |
1518 | |
727 | 1519 last_thing_searched = Qnil; |
1520 staticpro (&last_thing_searched); | |
1521 | |
603 | 1522 defsubr (&Sstring_match); |
1523 defsubr (&Slooking_at); | |
1524 defsubr (&Sskip_chars_forward); | |
1525 defsubr (&Sskip_chars_backward); | |
1896
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
1526 defsubr (&Sskip_syntax_forward); |
10895ac08bc6
(Fskip_syntax_backward): New function.
Richard M. Stallman <rms@gnu.org>
parents:
1878
diff
changeset
|
1527 defsubr (&Sskip_syntax_backward); |
603 | 1528 defsubr (&Ssearch_forward); |
1529 defsubr (&Ssearch_backward); | |
1530 defsubr (&Sword_search_forward); | |
1531 defsubr (&Sword_search_backward); | |
1532 defsubr (&Sre_search_forward); | |
1533 defsubr (&Sre_search_backward); | |
1534 defsubr (&Sreplace_match); | |
1535 defsubr (&Smatch_beginning); | |
1536 defsubr (&Smatch_end); | |
1537 defsubr (&Smatch_data); | |
1538 defsubr (&Sstore_match_data); | |
1539 defsubr (&Sregexp_quote); | |
1540 } |