diff options
| author | Juri Linkov | 2011-12-02 12:19:49 +0200 |
|---|---|---|
| committer | Juri Linkov | 2011-12-02 12:19:49 +0200 |
| commit | 02b16839f5242e93a234e7ebb0578d5aebb529ca (patch) | |
| tree | 7436dcb7526068d6f501a63bda883a5d8dda4367 /src | |
| parent | 71c90957bf6d537092d057b743d31e1fd2992f75 (diff) | |
| download | emacs-02b16839f5242e93a234e7ebb0578d5aebb529ca.tar.gz emacs-02b16839f5242e93a234e7ebb0578d5aebb529ca.zip | |
Change `wordify' to `word-search-regexp'.
* lisp/isearch.el (isearch-occur): Use `word-search-regexp' for
`isearch-word'.
(isearch-search-and-update): Add condition for `isearch-word' and
call `word-search-regexp'.
* src/search.c (Fword_search_regexp): New Lisp function created from
`wordify'. Change type of arg `lax' from `int' to `Lisp_Object'.
(Fword_search_backward, Fword_search_forward)
(Fword_search_backward_lax, Fword_search_forward_lax):
Use `Fword_search_regexp' instead of `wordify'. Doc fix.
(syms_of_search): Define `Sword_search_regexp'.
Fixes: debbugs:10145
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 9 | ||||
| -rw-r--r-- | src/search.c | 59 |
2 files changed, 48 insertions, 20 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 75f62ad6fbd..ed47da2caa1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2011-12-02 Juri Linkov <juri@jurta.org> | ||
| 2 | |||
| 3 | * search.c (Fword_search_regexp): New Lisp function created from | ||
| 4 | `wordify'. Change type of arg `lax' from `int' to `Lisp_Object'. | ||
| 5 | (Fword_search_backward, Fword_search_forward) | ||
| 6 | (Fword_search_backward_lax, Fword_search_forward_lax): | ||
| 7 | Use `Fword_search_regexp' instead of `wordify'. Doc fix. | ||
| 8 | (syms_of_search): Define `Sword_search_regexp'. (Bug#10145) | ||
| 9 | |||
| 1 | 2011-12-01 Stefan Monnier <monnier@iro.umontreal.ca> | 10 | 2011-12-01 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 11 | ||
| 3 | * fileio.c (Finsert_file_contents): Move after-change-function call | 12 | * fileio.c (Finsert_file_contents): Move after-change-function call |
diff --git a/src/search.c b/src/search.c index fe4ce534b0b..811ac74e194 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 (EMACS_INT, EMACS_INT); | 92 | static void set_search_regs (EMACS_INT, EMACS_INT); |
| @@ -2078,13 +2077,16 @@ set_search_regs (EMACS_INT beg_byte, EMACS_INT nbytes) | |||
| 2078 | XSETBUFFER (last_thing_searched, current_buffer); | 2077 | XSETBUFFER (last_thing_searched, current_buffer); |
| 2079 | } | 2078 | } |
| 2080 | 2079 | ||
| 2081 | /* Given STRING, a string of words separated by word delimiters, | 2080 | DEFUN ("word-search-regexp", Fword_search_regexp, Sword_search_regexp, 1, 2, 0, |
| 2082 | compute a regexp that matches those exact words separated by | 2081 | doc: /* Return a regexp which matches words, ignoring punctuation. |
| 2083 | arbitrary punctuation. If LAX is nonzero, the end of the string | 2082 | Given STRING, a string of words separated by word delimiters, |
| 2084 | need not match a word boundary unless it ends in whitespace. */ | 2083 | compute a regexp that matches those exact words separated by |
| 2085 | 2084 | arbitrary punctuation. If LAX is non-nil, the end of the string | |
| 2086 | static Lisp_Object | 2085 | need not match a word boundary unless it ends in whitespace. |
| 2087 | wordify (Lisp_Object string, int lax) | 2086 | |
| 2087 | Used in `word-search-forward', `word-search-backward', | ||
| 2088 | `word-search-forward-lax', `word-search-backward-lax'. */) | ||
| 2089 | (Lisp_Object string, Lisp_Object lax) | ||
| 2088 | { | 2090 | { |
| 2089 | register unsigned char *o; | 2091 | register unsigned char *o; |
| 2090 | register EMACS_INT i, i_byte, len, punct_count = 0, word_count = 0; | 2092 | register EMACS_INT i, i_byte, len, punct_count = 0, word_count = 0; |
| @@ -2125,7 +2127,7 @@ wordify (Lisp_Object string, int lax) | |||
| 2125 | } | 2127 | } |
| 2126 | 2128 | ||
| 2127 | adjust = - punct_count + 5 * (word_count - 1) | 2129 | adjust = - punct_count + 5 * (word_count - 1) |
| 2128 | + ((lax && !whitespace_at_end) ? 2 : 4); | 2130 | + ((!NILP (lax) && !whitespace_at_end) ? 2 : 4); |
| 2129 | if (STRING_MULTIBYTE (string)) | 2131 | if (STRING_MULTIBYTE (string)) |
| 2130 | val = make_uninit_multibyte_string (len + adjust, | 2132 | val = make_uninit_multibyte_string (len + adjust, |
| 2131 | SBYTES (string) | 2133 | SBYTES (string) |
| @@ -2162,7 +2164,7 @@ wordify (Lisp_Object string, int lax) | |||
| 2162 | prev_c = c; | 2164 | prev_c = c; |
| 2163 | } | 2165 | } |
| 2164 | 2166 | ||
| 2165 | if (!lax || whitespace_at_end) | 2167 | if (NILP (lax) || whitespace_at_end) |
| 2166 | { | 2168 | { |
| 2167 | *o++ = '\\'; | 2169 | *o++ = '\\'; |
| 2168 | *o++ = 'b'; | 2170 | *o++ = 'b'; |
| @@ -2217,10 +2219,14 @@ An optional second argument bounds the search; it is a buffer position. | |||
| 2217 | The match found must not extend before that position. | 2219 | The match found must not extend before that position. |
| 2218 | Optional third argument, if t, means if fail just return nil (no error). | 2220 | Optional third argument, if t, means if fail just return nil (no error). |
| 2219 | If not nil and not t, move to limit of search and return nil. | 2221 | If not nil and not t, move to limit of search and return nil. |
| 2220 | Optional fourth argument is repeat count--search for successive occurrences. */) | 2222 | Optional fourth argument is repeat count--search for successive occurrences. |
| 2223 | |||
| 2224 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2225 | of words in STRING to a regexp used to search words without regard | ||
| 2226 | to punctuation. */) | ||
| 2221 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | 2227 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) |
| 2222 | { | 2228 | { |
| 2223 | return search_command (wordify (string, 0), bound, noerror, count, -1, 1, 0); | 2229 | return search_command (Fword_search_regexp (string, Qnil), bound, noerror, count, -1, 1, 0); |
| 2224 | } | 2230 | } |
| 2225 | 2231 | ||
| 2226 | DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4, | 2232 | DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4, |
| @@ -2231,10 +2237,14 @@ An optional second argument bounds the search; it is a buffer position. | |||
| 2231 | The match found must not extend after that position. | 2237 | The match found must not extend after that position. |
| 2232 | Optional third argument, if t, means if fail just return nil (no error). | 2238 | Optional third argument, if t, means if fail just return nil (no error). |
| 2233 | If not nil and not t, move to limit of search and return nil. | 2239 | If not nil and not t, move to limit of search and return nil. |
| 2234 | Optional fourth argument is repeat count--search for successive occurrences. */) | 2240 | Optional fourth argument is repeat count--search for successive occurrences. |
| 2241 | |||
| 2242 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2243 | of words in STRING to a regexp used to search words without regard | ||
| 2244 | to punctuation. */) | ||
| 2235 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | 2245 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) |
| 2236 | { | 2246 | { |
| 2237 | return search_command (wordify (string, 0), bound, noerror, count, 1, 1, 0); | 2247 | return search_command (Fword_search_regexp (string, Qnil), bound, noerror, count, 1, 1, 0); |
| 2238 | } | 2248 | } |
| 2239 | 2249 | ||
| 2240 | DEFUN ("word-search-backward-lax", Fword_search_backward_lax, Sword_search_backward_lax, 1, 4, | 2250 | DEFUN ("word-search-backward-lax", Fword_search_backward_lax, Sword_search_backward_lax, 1, 4, |
| @@ -2249,10 +2259,14 @@ An optional second argument bounds the search; it is a buffer position. | |||
| 2249 | The match found must not extend before that position. | 2259 | The match found must not extend before that position. |
| 2250 | Optional third argument, if t, means if fail just return nil (no error). | 2260 | Optional third argument, if t, means if fail just return nil (no error). |
| 2251 | If not nil and not t, move to limit of search and return nil. | 2261 | If not nil and not t, move to limit of search and return nil. |
| 2252 | Optional fourth argument is repeat count--search for successive occurrences. */) | 2262 | Optional fourth argument is repeat count--search for successive occurrences. |
| 2263 | |||
| 2264 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2265 | of words in STRING to a regexp used to search words without regard | ||
| 2266 | to punctuation. */) | ||
| 2253 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | 2267 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) |
| 2254 | { | 2268 | { |
| 2255 | return search_command (wordify (string, 1), bound, noerror, count, -1, 1, 0); | 2269 | return search_command (Fword_search_regexp (string, Qt), bound, noerror, count, -1, 1, 0); |
| 2256 | } | 2270 | } |
| 2257 | 2271 | ||
| 2258 | DEFUN ("word-search-forward-lax", Fword_search_forward_lax, Sword_search_forward_lax, 1, 4, | 2272 | DEFUN ("word-search-forward-lax", Fword_search_forward_lax, Sword_search_forward_lax, 1, 4, |
| @@ -2267,10 +2281,14 @@ An optional second argument bounds the search; it is a buffer position. | |||
| 2267 | The match found must not extend after that position. | 2281 | The match found must not extend after that position. |
| 2268 | Optional third argument, if t, means if fail just return nil (no error). | 2282 | Optional third argument, if t, means if fail just return nil (no error). |
| 2269 | If not nil and not t, move to limit of search and return nil. | 2283 | If not nil and not t, move to limit of search and return nil. |
| 2270 | Optional fourth argument is repeat count--search for successive occurrences. */) | 2284 | Optional fourth argument is repeat count--search for successive occurrences. |
| 2285 | |||
| 2286 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2287 | of words in STRING to a regexp used to search words without regard | ||
| 2288 | to punctuation. */) | ||
| 2271 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | 2289 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) |
| 2272 | { | 2290 | { |
| 2273 | return search_command (wordify (string, 1), bound, noerror, count, 1, 1, 0); | 2291 | return search_command (Fword_search_regexp (string, Qt), bound, noerror, count, 1, 1, 0); |
| 2274 | } | 2292 | } |
| 2275 | 2293 | ||
| 2276 | DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, | 2294 | DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, |
| @@ -3229,6 +3247,7 @@ is to bind it with `let' around a small expression. */); | |||
| 3229 | defsubr (&Sposix_string_match); | 3247 | defsubr (&Sposix_string_match); |
| 3230 | defsubr (&Ssearch_forward); | 3248 | defsubr (&Ssearch_forward); |
| 3231 | defsubr (&Ssearch_backward); | 3249 | defsubr (&Ssearch_backward); |
| 3250 | defsubr (&Sword_search_regexp); | ||
| 3232 | defsubr (&Sword_search_forward); | 3251 | defsubr (&Sword_search_forward); |
| 3233 | defsubr (&Sword_search_backward); | 3252 | defsubr (&Sword_search_backward); |
| 3234 | defsubr (&Sword_search_forward_lax); | 3253 | defsubr (&Sword_search_forward_lax); |