diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/search.c | 74 |
1 files changed, 63 insertions, 11 deletions
diff --git a/src/search.c b/src/search.c index df054434b63..244220b92f5 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -2115,19 +2115,21 @@ set_search_regs (beg_byte, nbytes) | |||
| 2115 | XSETBUFFER (last_thing_searched, current_buffer); | 2115 | XSETBUFFER (last_thing_searched, current_buffer); |
| 2116 | } | 2116 | } |
| 2117 | 2117 | ||
| 2118 | /* Given a string of words separated by word delimiters, | 2118 | /* Given STRING, a string of words separated by word delimiters, |
| 2119 | compute a regexp that matches those exact words | 2119 | compute a regexp that matches those exact words separated by |
| 2120 | separated by arbitrary punctuation. */ | 2120 | arbitrary punctuation. If LAX is nonzero, the end of the string |
| 2121 | need not match a word boundary unless it ends in whitespace. */ | ||
| 2121 | 2122 | ||
| 2122 | static Lisp_Object | 2123 | static Lisp_Object |
| 2123 | wordify (string) | 2124 | wordify (string, lax) |
| 2124 | Lisp_Object string; | 2125 | Lisp_Object string; |
| 2126 | int lax; | ||
| 2125 | { | 2127 | { |
| 2126 | register unsigned char *p, *o; | 2128 | register unsigned char *p, *o; |
| 2127 | register int i, i_byte, len, punct_count = 0, word_count = 0; | 2129 | register int i, i_byte, len, punct_count = 0, word_count = 0; |
| 2128 | Lisp_Object val; | 2130 | Lisp_Object val; |
| 2129 | int prev_c = 0; | 2131 | int prev_c = 0; |
| 2130 | int adjust; | 2132 | int adjust, whitespace_at_end; |
| 2131 | 2133 | ||
| 2132 | CHECK_STRING (string); | 2134 | CHECK_STRING (string); |
| 2133 | p = SDATA (string); | 2135 | p = SDATA (string); |
| @@ -2150,11 +2152,18 @@ wordify (string) | |||
| 2150 | } | 2152 | } |
| 2151 | 2153 | ||
| 2152 | if (SYNTAX (prev_c) == Sword) | 2154 | if (SYNTAX (prev_c) == Sword) |
| 2153 | word_count++; | 2155 | { |
| 2156 | word_count++; | ||
| 2157 | whitespace_at_end = 0; | ||
| 2158 | } | ||
| 2159 | else | ||
| 2160 | whitespace_at_end = 1; | ||
| 2161 | |||
| 2154 | if (!word_count) | 2162 | if (!word_count) |
| 2155 | return empty_unibyte_string; | 2163 | return empty_unibyte_string; |
| 2156 | 2164 | ||
| 2157 | adjust = - punct_count + 5 * (word_count - 1) + 4; | 2165 | adjust = - punct_count + 5 * (word_count - 1) |
| 2166 | + ((lax && !whitespace_at_end) ? 2 : 4); | ||
| 2158 | if (STRING_MULTIBYTE (string)) | 2167 | if (STRING_MULTIBYTE (string)) |
| 2159 | val = make_uninit_multibyte_string (len + adjust, | 2168 | val = make_uninit_multibyte_string (len + adjust, |
| 2160 | SBYTES (string) | 2169 | SBYTES (string) |
| @@ -2192,8 +2201,11 @@ wordify (string) | |||
| 2192 | prev_c = c; | 2201 | prev_c = c; |
| 2193 | } | 2202 | } |
| 2194 | 2203 | ||
| 2195 | *o++ = '\\'; | 2204 | if (!lax || whitespace_at_end) |
| 2196 | *o++ = 'b'; | 2205 | { |
| 2206 | *o++ = '\\'; | ||
| 2207 | *o++ = 'b'; | ||
| 2208 | } | ||
| 2197 | 2209 | ||
| 2198 | return val; | 2210 | return val; |
| 2199 | } | 2211 | } |
| @@ -2250,7 +2262,7 @@ Optional fourth argument is repeat count--search for successive occurrences. */ | |||
| 2250 | (string, bound, noerror, count) | 2262 | (string, bound, noerror, count) |
| 2251 | Lisp_Object string, bound, noerror, count; | 2263 | Lisp_Object string, bound, noerror, count; |
| 2252 | { | 2264 | { |
| 2253 | return search_command (wordify (string), bound, noerror, count, -1, 1, 0); | 2265 | return search_command (wordify (string, 0), bound, noerror, count, -1, 1, 0); |
| 2254 | } | 2266 | } |
| 2255 | 2267 | ||
| 2256 | DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4, | 2268 | DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4, |
| @@ -2265,7 +2277,45 @@ Optional fourth argument is repeat count--search for successive occurrences. */ | |||
| 2265 | (string, bound, noerror, count) | 2277 | (string, bound, noerror, count) |
| 2266 | Lisp_Object string, bound, noerror, count; | 2278 | Lisp_Object string, bound, noerror, count; |
| 2267 | { | 2279 | { |
| 2268 | return search_command (wordify (string), bound, noerror, count, 1, 1, 0); | 2280 | return search_command (wordify (string, 0), bound, noerror, count, 1, 1, 0); |
| 2281 | } | ||
| 2282 | |||
| 2283 | DEFUN ("word-search-backward-lax", Fword_search_backward_lax, Sword_search_backward_lax, 1, 4, | ||
| 2284 | "sWord search backward: ", | ||
| 2285 | doc: /* Search backward from point for STRING, ignoring differences in punctuation. | ||
| 2286 | Set point to the beginning of the occurrence found, and return point. | ||
| 2287 | |||
| 2288 | Unlike `word-search-backward', the end of STRING need not match a word | ||
| 2289 | boundary unless it ends in whitespace. | ||
| 2290 | |||
| 2291 | An optional second argument bounds the search; it is a buffer position. | ||
| 2292 | The match found must not extend before that position. | ||
| 2293 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 2294 | If not nil and not t, move to limit of search and return nil. | ||
| 2295 | Optional fourth argument is repeat count--search for successive occurrences. */) | ||
| 2296 | (string, bound, noerror, count) | ||
| 2297 | Lisp_Object string, bound, noerror, count; | ||
| 2298 | { | ||
| 2299 | return search_command (wordify (string, 1), bound, noerror, count, -1, 1, 0); | ||
| 2300 | } | ||
| 2301 | |||
| 2302 | DEFUN ("word-search-forward-lax", Fword_search_forward_lax, Sword_search_forward_lax, 1, 4, | ||
| 2303 | "sWord search: ", | ||
| 2304 | doc: /* Search forward from point for STRING, ignoring differences in punctuation. | ||
| 2305 | Set point to the end of the occurrence found, and return point. | ||
| 2306 | |||
| 2307 | Unlike `word-search-forward', the end of STRING need not match a word | ||
| 2308 | boundary unless it ends in whitespace. | ||
| 2309 | |||
| 2310 | An optional second argument bounds the search; it is a buffer position. | ||
| 2311 | The match found must not extend after that position. | ||
| 2312 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 2313 | If not nil and not t, move to limit of search and return nil. | ||
| 2314 | Optional fourth argument is repeat count--search for successive occurrences. */) | ||
| 2315 | (string, bound, noerror, count) | ||
| 2316 | Lisp_Object string, bound, noerror, count; | ||
| 2317 | { | ||
| 2318 | return search_command (wordify (string, 1), bound, noerror, count, 1, 1, 0); | ||
| 2269 | } | 2319 | } |
| 2270 | 2320 | ||
| 2271 | DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, | 2321 | DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, |
| @@ -3235,6 +3285,8 @@ is to bind it with `let' around a small expression. */); | |||
| 3235 | defsubr (&Ssearch_backward); | 3285 | defsubr (&Ssearch_backward); |
| 3236 | defsubr (&Sword_search_forward); | 3286 | defsubr (&Sword_search_forward); |
| 3237 | defsubr (&Sword_search_backward); | 3287 | defsubr (&Sword_search_backward); |
| 3288 | defsubr (&Sword_search_forward_lax); | ||
| 3289 | defsubr (&Sword_search_backward_lax); | ||
| 3238 | defsubr (&Sre_search_forward); | 3290 | defsubr (&Sre_search_forward); |
| 3239 | defsubr (&Sre_search_backward); | 3291 | defsubr (&Sre_search_backward); |
| 3240 | defsubr (&Sposix_search_forward); | 3292 | defsubr (&Sposix_search_forward); |