diff options
| author | Paul Eggert | 2011-12-10 16:56:50 -0800 |
|---|---|---|
| committer | Paul Eggert | 2011-12-10 16:56:50 -0800 |
| commit | 8f50130c565eaf0ad7c49e4ad044c3291ecdfa71 (patch) | |
| tree | c8129448cbbf387fe82667ccac02983592c688f1 /src/search.c | |
| parent | 85a83e2e2585a1906dec5168ed96ad521b5849ed (diff) | |
| parent | 7b9d523a07395ecea505be88f45c33d73aea7038 (diff) | |
| download | emacs-8f50130c565eaf0ad7c49e4ad044c3291ecdfa71.tar.gz emacs-8f50130c565eaf0ad7c49e4ad044c3291ecdfa71.zip | |
Merge from trunk.
Diffstat (limited to 'src/search.c')
| -rw-r--r-- | src/search.c | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/src/search.c b/src/search.c index df53dbf8d89..160d08e3c8c 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -83,11 +83,10 @@ static struct re_registers search_regs; | |||
| 83 | Qnil if no searching has been done yet. */ | 83 | Qnil if no searching has been done yet. */ |
| 84 | static Lisp_Object last_thing_searched; | 84 | static Lisp_Object last_thing_searched; |
| 85 | 85 | ||
| 86 | /* error condition signaled when regexp compile_pattern fails */ | 86 | /* Error condition signaled when regexp compile_pattern fails. */ |
| 87 | |||
| 88 | static Lisp_Object Qinvalid_regexp; | 87 | static Lisp_Object Qinvalid_regexp; |
| 89 | 88 | ||
| 90 | /* Error condition used for failing searches */ | 89 | /* Error condition used for failing searches. */ |
| 91 | static Lisp_Object Qsearch_failed; | 90 | static Lisp_Object Qsearch_failed; |
| 92 | 91 | ||
| 93 | static void set_search_regs (ptrdiff_t, ptrdiff_t); | 92 | static void set_search_regs (ptrdiff_t, ptrdiff_t); |
| @@ -1893,7 +1892,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat, | |||
| 1893 | || CHAR_HEAD_P (cursor[1])) | 1892 | || CHAR_HEAD_P (cursor[1])) |
| 1894 | && (CHAR_HEAD_P (cursor[0]) | 1893 | && (CHAR_HEAD_P (cursor[0]) |
| 1895 | /* Check if this is the last byte of | 1894 | /* Check if this is the last byte of |
| 1896 | a translable character. */ | 1895 | a translatable character. */ |
| 1897 | || (translate_prev_byte1 == cursor[-1] | 1896 | || (translate_prev_byte1 == cursor[-1] |
| 1898 | && (CHAR_HEAD_P (translate_prev_byte1) | 1897 | && (CHAR_HEAD_P (translate_prev_byte1) |
| 1899 | || (translate_prev_byte2 == cursor[-2] | 1898 | || (translate_prev_byte2 == cursor[-2] |
| @@ -1992,7 +1991,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat, | |||
| 1992 | || CHAR_HEAD_P (ptr[1])) | 1991 | || CHAR_HEAD_P (ptr[1])) |
| 1993 | && (CHAR_HEAD_P (ptr[0]) | 1992 | && (CHAR_HEAD_P (ptr[0]) |
| 1994 | /* Check if this is the last byte of a | 1993 | /* Check if this is the last byte of a |
| 1995 | translable character. */ | 1994 | translatable character. */ |
| 1996 | || (translate_prev_byte1 == ptr[-1] | 1995 | || (translate_prev_byte1 == ptr[-1] |
| 1997 | && (CHAR_HEAD_P (translate_prev_byte1) | 1996 | && (CHAR_HEAD_P (translate_prev_byte1) |
| 1998 | || (translate_prev_byte2 == ptr[-2] | 1997 | || (translate_prev_byte2 == ptr[-2] |
| @@ -2079,13 +2078,16 @@ set_search_regs (ptrdiff_t beg_byte, ptrdiff_t nbytes) | |||
| 2079 | XSETBUFFER (last_thing_searched, current_buffer); | 2078 | XSETBUFFER (last_thing_searched, current_buffer); |
| 2080 | } | 2079 | } |
| 2081 | 2080 | ||
| 2082 | /* Given STRING, a string of words separated by word delimiters, | 2081 | DEFUN ("word-search-regexp", Fword_search_regexp, Sword_search_regexp, 1, 2, 0, |
| 2083 | compute a regexp that matches those exact words separated by | 2082 | doc: /* Return a regexp which matches words, ignoring punctuation. |
| 2084 | arbitrary punctuation. If LAX is nonzero, the end of the string | 2083 | Given STRING, a string of words separated by word delimiters, |
| 2085 | need not match a word boundary unless it ends in whitespace. */ | 2084 | compute a regexp that matches those exact words separated by |
| 2086 | 2085 | arbitrary punctuation. If LAX is non-nil, the end of the string | |
| 2087 | static Lisp_Object | 2086 | need not match a word boundary unless it ends in whitespace. |
| 2088 | wordify (Lisp_Object string, int lax) | 2087 | |
| 2088 | Used in `word-search-forward', `word-search-backward', | ||
| 2089 | `word-search-forward-lax', `word-search-backward-lax'. */) | ||
| 2090 | (Lisp_Object string, Lisp_Object lax) | ||
| 2089 | { | 2091 | { |
| 2090 | register unsigned char *o; | 2092 | register unsigned char *o; |
| 2091 | register ptrdiff_t i, i_byte, len, punct_count = 0, word_count = 0; | 2093 | register ptrdiff_t i, i_byte, len, punct_count = 0, word_count = 0; |
| @@ -2129,7 +2131,7 @@ wordify (Lisp_Object string, int lax) | |||
| 2129 | if (TYPE_MAXIMUM (EMACS_INT) / 5 < adjust) | 2131 | if (TYPE_MAXIMUM (EMACS_INT) / 5 < adjust) |
| 2130 | memory_full (SIZE_MAX); | 2132 | memory_full (SIZE_MAX); |
| 2131 | adjust = - punct_count + 5 * adjust | 2133 | adjust = - punct_count + 5 * adjust |
| 2132 | + ((lax && !whitespace_at_end) ? 2 : 4); | 2134 | + ((!NILP (lax) && !whitespace_at_end) ? 2 : 4); |
| 2133 | if (STRING_MULTIBYTE (string)) | 2135 | if (STRING_MULTIBYTE (string)) |
| 2134 | { | 2136 | { |
| 2135 | if (INT_ADD_OVERFLOW (SBYTES (string), adjust)) | 2137 | if (INT_ADD_OVERFLOW (SBYTES (string), adjust)) |
| @@ -2173,7 +2175,7 @@ wordify (Lisp_Object string, int lax) | |||
| 2173 | prev_c = c; | 2175 | prev_c = c; |
| 2174 | } | 2176 | } |
| 2175 | 2177 | ||
| 2176 | if (!lax || whitespace_at_end) | 2178 | if (NILP (lax) || whitespace_at_end) |
| 2177 | { | 2179 | { |
| 2178 | *o++ = '\\'; | 2180 | *o++ = '\\'; |
| 2179 | *o++ = 'b'; | 2181 | *o++ = 'b'; |
| @@ -2228,10 +2230,14 @@ An optional second argument bounds the search; it is a buffer position. | |||
| 2228 | The match found must not extend before that position. | 2230 | The match found must not extend before that position. |
| 2229 | Optional third argument, if t, means if fail just return nil (no error). | 2231 | Optional third argument, if t, means if fail just return nil (no error). |
| 2230 | If not nil and not t, move to limit of search and return nil. | 2232 | If not nil and not t, move to limit of search and return nil. |
| 2231 | Optional fourth argument is repeat count--search for successive occurrences. */) | 2233 | Optional fourth argument is repeat count--search for successive occurrences. |
| 2234 | |||
| 2235 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2236 | of words in STRING to a regexp used to search words without regard | ||
| 2237 | to punctuation. */) | ||
| 2232 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | 2238 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) |
| 2233 | { | 2239 | { |
| 2234 | return search_command (wordify (string, 0), bound, noerror, count, -1, 1, 0); | 2240 | return search_command (Fword_search_regexp (string, Qnil), bound, noerror, count, -1, 1, 0); |
| 2235 | } | 2241 | } |
| 2236 | 2242 | ||
| 2237 | DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4, | 2243 | DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4, |
| @@ -2242,10 +2248,14 @@ An optional second argument bounds the search; it is a buffer position. | |||
| 2242 | The match found must not extend after that position. | 2248 | The match found must not extend after that position. |
| 2243 | Optional third argument, if t, means if fail just return nil (no error). | 2249 | Optional third argument, if t, means if fail just return nil (no error). |
| 2244 | If not nil and not t, move to limit of search and return nil. | 2250 | If not nil and not t, move to limit of search and return nil. |
| 2245 | Optional fourth argument is repeat count--search for successive occurrences. */) | 2251 | Optional fourth argument is repeat count--search for successive occurrences. |
| 2252 | |||
| 2253 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2254 | of words in STRING to a regexp used to search words without regard | ||
| 2255 | to punctuation. */) | ||
| 2246 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | 2256 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) |
| 2247 | { | 2257 | { |
| 2248 | return search_command (wordify (string, 0), bound, noerror, count, 1, 1, 0); | 2258 | return search_command (Fword_search_regexp (string, Qnil), bound, noerror, count, 1, 1, 0); |
| 2249 | } | 2259 | } |
| 2250 | 2260 | ||
| 2251 | DEFUN ("word-search-backward-lax", Fword_search_backward_lax, Sword_search_backward_lax, 1, 4, | 2261 | DEFUN ("word-search-backward-lax", Fword_search_backward_lax, Sword_search_backward_lax, 1, 4, |
| @@ -2260,10 +2270,14 @@ An optional second argument bounds the search; it is a buffer position. | |||
| 2260 | The match found must not extend before that position. | 2270 | The match found must not extend before that position. |
| 2261 | Optional third argument, if t, means if fail just return nil (no error). | 2271 | Optional third argument, if t, means if fail just return nil (no error). |
| 2262 | If not nil and not t, move to limit of search and return nil. | 2272 | If not nil and not t, move to limit of search and return nil. |
| 2263 | Optional fourth argument is repeat count--search for successive occurrences. */) | 2273 | Optional fourth argument is repeat count--search for successive occurrences. |
| 2274 | |||
| 2275 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2276 | of words in STRING to a regexp used to search words without regard | ||
| 2277 | to punctuation. */) | ||
| 2264 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | 2278 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) |
| 2265 | { | 2279 | { |
| 2266 | return search_command (wordify (string, 1), bound, noerror, count, -1, 1, 0); | 2280 | return search_command (Fword_search_regexp (string, Qt), bound, noerror, count, -1, 1, 0); |
| 2267 | } | 2281 | } |
| 2268 | 2282 | ||
| 2269 | DEFUN ("word-search-forward-lax", Fword_search_forward_lax, Sword_search_forward_lax, 1, 4, | 2283 | DEFUN ("word-search-forward-lax", Fword_search_forward_lax, Sword_search_forward_lax, 1, 4, |
| @@ -2278,10 +2292,14 @@ An optional second argument bounds the search; it is a buffer position. | |||
| 2278 | The match found must not extend after that position. | 2292 | The match found must not extend after that position. |
| 2279 | Optional third argument, if t, means if fail just return nil (no error). | 2293 | Optional third argument, if t, means if fail just return nil (no error). |
| 2280 | If not nil and not t, move to limit of search and return nil. | 2294 | If not nil and not t, move to limit of search and return nil. |
| 2281 | Optional fourth argument is repeat count--search for successive occurrences. */) | 2295 | Optional fourth argument is repeat count--search for successive occurrences. |
| 2296 | |||
| 2297 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2298 | of words in STRING to a regexp used to search words without regard | ||
| 2299 | to punctuation. */) | ||
| 2282 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | 2300 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) |
| 2283 | { | 2301 | { |
| 2284 | return search_command (wordify (string, 1), bound, noerror, count, 1, 1, 0); | 2302 | return search_command (Fword_search_regexp (string, Qt), bound, noerror, count, 1, 1, 0); |
| 2285 | } | 2303 | } |
| 2286 | 2304 | ||
| 2287 | DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, | 2305 | DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, |
| @@ -3157,7 +3175,7 @@ record_unwind_save_match_data (void) | |||
| 3157 | Fmatch_data (Qnil, Qnil, Qnil)); | 3175 | Fmatch_data (Qnil, Qnil, Qnil)); |
| 3158 | } | 3176 | } |
| 3159 | 3177 | ||
| 3160 | /* Quote a string to inactivate reg-expr chars */ | 3178 | /* Quote a string to deactivate reg-expr chars */ |
| 3161 | 3179 | ||
| 3162 | DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0, | 3180 | DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0, |
| 3163 | doc: /* Return a regexp string which matches exactly STRING and nothing else. */) | 3181 | doc: /* Return a regexp string which matches exactly STRING and nothing else. */) |
| @@ -3254,6 +3272,7 @@ is to bind it with `let' around a small expression. */); | |||
| 3254 | defsubr (&Sposix_string_match); | 3272 | defsubr (&Sposix_string_match); |
| 3255 | defsubr (&Ssearch_forward); | 3273 | defsubr (&Ssearch_forward); |
| 3256 | defsubr (&Ssearch_backward); | 3274 | defsubr (&Ssearch_backward); |
| 3275 | defsubr (&Sword_search_regexp); | ||
| 3257 | defsubr (&Sword_search_forward); | 3276 | defsubr (&Sword_search_forward); |
| 3258 | defsubr (&Sword_search_backward); | 3277 | defsubr (&Sword_search_backward); |
| 3259 | defsubr (&Sword_search_forward_lax); | 3278 | defsubr (&Sword_search_forward_lax); |