diff options
| author | Juri Linkov | 2012-05-17 03:03:49 +0300 |
|---|---|---|
| committer | Juri Linkov | 2012-05-17 03:03:49 +0300 |
| commit | a0a79cde7c978cf457c4a817b9a67bb4557f8a5c (patch) | |
| tree | b7097e44bfdde8e6596d5579c736a6eb4d3181c0 | |
| parent | 5ec546086a3f0ea5ad6ba2501dc4d84188e8b880 (diff) | |
| download | emacs-a0a79cde7c978cf457c4a817b9a67bb4557f8a5c.tar.gz emacs-a0a79cde7c978cf457c4a817b9a67bb4557f8a5c.zip | |
Move word search functions from search.c to isearch.el (bug#10145, bug#11381).
* lisp/isearch.el (word-search-regexp, word-search-backward)
(word-search-forward, word-search-backward-lax)
(word-search-forward-lax): Move functions from search.c.
* src/search.c (Fword_search_regexp, Fword_search_backward)
(Fword_search_forward, Fword_search_backward_lax)
(Fword_search_forward_lax): Move functions to isearch.el.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/isearch.el | 88 | ||||
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/search.c | 181 |
4 files changed, 102 insertions, 181 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 60b238e79d1..b1d9323e481 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2012-05-17 Juri Linkov <juri@jurta.org> | ||
| 2 | |||
| 3 | * isearch.el (word-search-regexp, word-search-backward) | ||
| 4 | (word-search-forward, word-search-backward-lax) | ||
| 5 | (word-search-forward-lax): Move functions from search.c | ||
| 6 | (bug#10145, bug#11381). | ||
| 7 | |||
| 1 | 2012-05-16 Agustín Martín Domingo <agustin.martin@hispalinux.es> | 8 | 2012-05-16 Agustín Martín Domingo <agustin.martin@hispalinux.es> |
| 2 | 9 | ||
| 3 | * flyspell.el (flyspell-check-pre-word-p, flyspell-check-word-p) | 10 | * flyspell.el (flyspell-check-pre-word-p, flyspell-check-word-p) |
diff --git a/lisp/isearch.el b/lisp/isearch.el index 9d69443b6a4..7f68fb4ad32 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el | |||
| @@ -1381,6 +1381,94 @@ Use `isearch-exit' to quit without signaling." | |||
| 1381 | (sit-for 1) | 1381 | (sit-for 1) |
| 1382 | (isearch-update)) | 1382 | (isearch-update)) |
| 1383 | 1383 | ||
| 1384 | |||
| 1385 | ;; Word search | ||
| 1386 | |||
| 1387 | (defun word-search-regexp (string &optional lax) | ||
| 1388 | "Return a regexp which matches words, ignoring punctuation. | ||
| 1389 | Given STRING, a string of words separated by word delimiters, | ||
| 1390 | compute a regexp that matches those exact words separated by | ||
| 1391 | arbitrary punctuation. If LAX is non-nil, the end of the string | ||
| 1392 | need not match a word boundary unless it ends in whitespace. | ||
| 1393 | |||
| 1394 | Used in `word-search-forward', `word-search-backward', | ||
| 1395 | `word-search-forward-lax', `word-search-backward-lax'." | ||
| 1396 | (if (string-match-p "^\\W*$" string) | ||
| 1397 | "" | ||
| 1398 | (concat | ||
| 1399 | "\\b" | ||
| 1400 | (mapconcat 'identity (split-string string "\\W+" t) "\\W+") | ||
| 1401 | (if (or (not lax) (string-match-p "\\W$" string)) "\\b")))) | ||
| 1402 | |||
| 1403 | (defun word-search-backward (string &optional bound noerror count) | ||
| 1404 | "Search backward from point for STRING, ignoring differences in punctuation. | ||
| 1405 | Set point to the beginning of the occurrence found, and return point. | ||
| 1406 | An optional second argument bounds the search; it is a buffer position. | ||
| 1407 | The match found must not extend before that position. | ||
| 1408 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 1409 | If not nil and not t, move to limit of search and return nil. | ||
| 1410 | Optional fourth argument is repeat count--search for successive occurrences. | ||
| 1411 | |||
| 1412 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 1413 | of words in STRING to a regexp used to search words without regard | ||
| 1414 | to punctuation." | ||
| 1415 | (interactive "sWord search backward: ") | ||
| 1416 | (re-search-backward (word-search-regexp string nil) bound noerror count)) | ||
| 1417 | |||
| 1418 | (defun word-search-forward (string &optional bound noerror count) | ||
| 1419 | "Search forward from point for STRING, ignoring differences in punctuation. | ||
| 1420 | Set point to the end of the occurrence found, and return point. | ||
| 1421 | An optional second argument bounds the search; it is a buffer position. | ||
| 1422 | The match found must not extend after that position. | ||
| 1423 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 1424 | If not nil and not t, move to limit of search and return nil. | ||
| 1425 | Optional fourth argument is repeat count--search for successive occurrences. | ||
| 1426 | |||
| 1427 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 1428 | of words in STRING to a regexp used to search words without regard | ||
| 1429 | to punctuation." | ||
| 1430 | (interactive "sWord search: ") | ||
| 1431 | (re-search-forward (word-search-regexp string nil) bound noerror count)) | ||
| 1432 | |||
| 1433 | (defun word-search-backward-lax (string &optional bound noerror count) | ||
| 1434 | "Search backward from point for STRING, ignoring differences in punctuation. | ||
| 1435 | Set point to the beginning of the occurrence found, and return point. | ||
| 1436 | |||
| 1437 | Unlike `word-search-backward', the end of STRING need not match a word | ||
| 1438 | boundary, unless STRING ends in whitespace. | ||
| 1439 | |||
| 1440 | An optional second argument bounds the search; it is a buffer position. | ||
| 1441 | The match found must not extend before that position. | ||
| 1442 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 1443 | If not nil and not t, move to limit of search and return nil. | ||
| 1444 | Optional fourth argument is repeat count--search for successive occurrences. | ||
| 1445 | |||
| 1446 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 1447 | of words in STRING to a regexp used to search words without regard | ||
| 1448 | to punctuation." | ||
| 1449 | (interactive "sWord search backward: ") | ||
| 1450 | (re-search-backward (word-search-regexp string t) bound noerror count)) | ||
| 1451 | |||
| 1452 | (defun word-search-forward-lax (string &optional bound noerror count) | ||
| 1453 | "Search forward from point for STRING, ignoring differences in punctuation. | ||
| 1454 | Set point to the end of the occurrence found, and return point. | ||
| 1455 | |||
| 1456 | Unlike `word-search-forward', the end of STRING need not match a word | ||
| 1457 | boundary, unless STRING ends in whitespace. | ||
| 1458 | |||
| 1459 | An optional second argument bounds the search; it is a buffer position. | ||
| 1460 | The match found must not extend after that position. | ||
| 1461 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 1462 | If not nil and not t, move to limit of search and return nil. | ||
| 1463 | Optional fourth argument is repeat count--search for successive occurrences. | ||
| 1464 | |||
| 1465 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 1466 | of words in STRING to a regexp used to search words without regard | ||
| 1467 | to punctuation." | ||
| 1468 | (interactive "sWord search: ") | ||
| 1469 | (re-search-forward (word-search-regexp string t) bound noerror count)) | ||
| 1470 | |||
| 1471 | |||
| 1384 | (defun isearch-query-replace (&optional delimited regexp-flag) | 1472 | (defun isearch-query-replace (&optional delimited regexp-flag) |
| 1385 | "Start `query-replace' with string to replace from last search string. | 1473 | "Start `query-replace' with string to replace from last search string. |
| 1386 | The arg DELIMITED (prefix arg if interactive), if non-nil, means replace | 1474 | The arg DELIMITED (prefix arg if interactive), if non-nil, means replace |
diff --git a/src/ChangeLog b/src/ChangeLog index 63661f5d27a..c72c8ae4d65 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2012-05-17 Juri Linkov <juri@jurta.org> | ||
| 2 | |||
| 3 | * search.c (Fword_search_regexp, Fword_search_backward) | ||
| 4 | (Fword_search_forward, Fword_search_backward_lax) | ||
| 5 | (Fword_search_forward_lax): Move functions to isearch.el | ||
| 6 | (bug#10145, bug#11381). | ||
| 7 | |||
| 1 | 2012-05-16 Paul Eggert <eggert@cs.ucla.edu> | 8 | 2012-05-16 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 9 | ||
| 3 | * xgselect.c (xg_select): Just invoke 'select' if -nw (Bug#9754). | 10 | * xgselect.c (xg_select): Just invoke 'select' if -nw (Bug#9754). |
diff --git a/src/search.c b/src/search.c index 1f3ccc25dc8..2bf5f78d93b 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -2078,102 +2078,6 @@ set_search_regs (EMACS_INT beg_byte, EMACS_INT nbytes) | |||
| 2078 | XSETBUFFER (last_thing_searched, current_buffer); | 2078 | XSETBUFFER (last_thing_searched, current_buffer); |
| 2079 | } | 2079 | } |
| 2080 | 2080 | ||
| 2081 | DEFUN ("word-search-regexp", Fword_search_regexp, Sword_search_regexp, 1, 2, 0, | ||
| 2082 | doc: /* Return a regexp which matches words, ignoring punctuation. | ||
| 2083 | Given STRING, a string of words separated by word delimiters, | ||
| 2084 | compute a regexp that matches those exact words separated by | ||
| 2085 | arbitrary punctuation. If LAX is non-nil, the end of the string | ||
| 2086 | need not match a word boundary unless it ends in whitespace. | ||
| 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) | ||
| 2091 | { | ||
| 2092 | register unsigned char *o; | ||
| 2093 | register EMACS_INT i, i_byte, len, punct_count = 0, word_count = 0; | ||
| 2094 | Lisp_Object val; | ||
| 2095 | int prev_c = 0; | ||
| 2096 | EMACS_INT adjust; | ||
| 2097 | int whitespace_at_end; | ||
| 2098 | |||
| 2099 | CHECK_STRING (string); | ||
| 2100 | len = SCHARS (string); | ||
| 2101 | |||
| 2102 | for (i = 0, i_byte = 0; i < len; ) | ||
| 2103 | { | ||
| 2104 | int c; | ||
| 2105 | |||
| 2106 | FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte); | ||
| 2107 | |||
| 2108 | if (SYNTAX (c) != Sword) | ||
| 2109 | { | ||
| 2110 | punct_count++; | ||
| 2111 | if (SYNTAX (prev_c) == Sword) | ||
| 2112 | word_count++; | ||
| 2113 | } | ||
| 2114 | |||
| 2115 | prev_c = c; | ||
| 2116 | } | ||
| 2117 | |||
| 2118 | if (SYNTAX (prev_c) == Sword) | ||
| 2119 | { | ||
| 2120 | word_count++; | ||
| 2121 | whitespace_at_end = 0; | ||
| 2122 | } | ||
| 2123 | else | ||
| 2124 | { | ||
| 2125 | whitespace_at_end = 1; | ||
| 2126 | if (!word_count) | ||
| 2127 | return empty_unibyte_string; | ||
| 2128 | } | ||
| 2129 | |||
| 2130 | adjust = - punct_count + 5 * (word_count - 1) | ||
| 2131 | + ((!NILP (lax) && !whitespace_at_end) ? 2 : 4); | ||
| 2132 | if (STRING_MULTIBYTE (string)) | ||
| 2133 | val = make_uninit_multibyte_string (len + adjust, | ||
| 2134 | SBYTES (string) | ||
| 2135 | + adjust); | ||
| 2136 | else | ||
| 2137 | val = make_uninit_string (len + adjust); | ||
| 2138 | |||
| 2139 | o = SDATA (val); | ||
| 2140 | *o++ = '\\'; | ||
| 2141 | *o++ = 'b'; | ||
| 2142 | prev_c = 0; | ||
| 2143 | |||
| 2144 | for (i = 0, i_byte = 0; i < len; ) | ||
| 2145 | { | ||
| 2146 | int c; | ||
| 2147 | EMACS_INT i_byte_orig = i_byte; | ||
| 2148 | |||
| 2149 | FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte); | ||
| 2150 | |||
| 2151 | if (SYNTAX (c) == Sword) | ||
| 2152 | { | ||
| 2153 | memcpy (o, SDATA (string) + i_byte_orig, i_byte - i_byte_orig); | ||
| 2154 | o += i_byte - i_byte_orig; | ||
| 2155 | } | ||
| 2156 | else if (SYNTAX (prev_c) == Sword && --word_count) | ||
| 2157 | { | ||
| 2158 | *o++ = '\\'; | ||
| 2159 | *o++ = 'W'; | ||
| 2160 | *o++ = '\\'; | ||
| 2161 | *o++ = 'W'; | ||
| 2162 | *o++ = '*'; | ||
| 2163 | } | ||
| 2164 | |||
| 2165 | prev_c = c; | ||
| 2166 | } | ||
| 2167 | |||
| 2168 | if (NILP (lax) || whitespace_at_end) | ||
| 2169 | { | ||
| 2170 | *o++ = '\\'; | ||
| 2171 | *o++ = 'b'; | ||
| 2172 | } | ||
| 2173 | |||
| 2174 | return val; | ||
| 2175 | } | ||
| 2176 | |||
| 2177 | DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4, | 2081 | DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4, |
| 2178 | "MSearch backward: ", | 2082 | "MSearch backward: ", |
| 2179 | doc: /* Search backward from point for STRING. | 2083 | doc: /* Search backward from point for STRING. |
| @@ -2216,86 +2120,6 @@ See also the functions `match-beginning', `match-end' and `replace-match'. */) | |||
| 2216 | return search_command (string, bound, noerror, count, 1, 0, 0); | 2120 | return search_command (string, bound, noerror, count, 1, 0, 0); |
| 2217 | } | 2121 | } |
| 2218 | 2122 | ||
| 2219 | DEFUN ("word-search-backward", Fword_search_backward, Sword_search_backward, 1, 4, | ||
| 2220 | "sWord search backward: ", | ||
| 2221 | doc: /* Search backward from point for STRING, ignoring differences in punctuation. | ||
| 2222 | Set point to the beginning of the occurrence found, and return point. | ||
| 2223 | An optional second argument bounds the search; it is a buffer position. | ||
| 2224 | The match found must not extend before that position. | ||
| 2225 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 2226 | If not nil and not t, move to limit of search and return nil. | ||
| 2227 | Optional fourth argument is repeat count--search for successive occurrences. | ||
| 2228 | |||
| 2229 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2230 | of words in STRING to a regexp used to search words without regard | ||
| 2231 | to punctuation. */) | ||
| 2232 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | ||
| 2233 | { | ||
| 2234 | return search_command (Fword_search_regexp (string, Qnil), bound, noerror, count, -1, 1, 0); | ||
| 2235 | } | ||
| 2236 | |||
| 2237 | DEFUN ("word-search-forward", Fword_search_forward, Sword_search_forward, 1, 4, | ||
| 2238 | "sWord search: ", | ||
| 2239 | doc: /* Search forward from point for STRING, ignoring differences in punctuation. | ||
| 2240 | Set point to the end of the occurrence found, and return point. | ||
| 2241 | An optional second argument bounds the search; it is a buffer position. | ||
| 2242 | The match found must not extend after that position. | ||
| 2243 | 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. | ||
| 2245 | Optional fourth argument is repeat count--search for successive occurrences. | ||
| 2246 | |||
| 2247 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2248 | of words in STRING to a regexp used to search words without regard | ||
| 2249 | to punctuation. */) | ||
| 2250 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | ||
| 2251 | { | ||
| 2252 | return search_command (Fword_search_regexp (string, Qnil), bound, noerror, count, 1, 1, 0); | ||
| 2253 | } | ||
| 2254 | |||
| 2255 | DEFUN ("word-search-backward-lax", Fword_search_backward_lax, Sword_search_backward_lax, 1, 4, | ||
| 2256 | "sWord search backward: ", | ||
| 2257 | doc: /* Search backward from point for STRING, ignoring differences in punctuation. | ||
| 2258 | Set point to the beginning of the occurrence found, and return point. | ||
| 2259 | |||
| 2260 | Unlike `word-search-backward', the end of STRING need not match a word | ||
| 2261 | boundary, unless STRING ends in whitespace. | ||
| 2262 | |||
| 2263 | An optional second argument bounds the search; it is a buffer position. | ||
| 2264 | The match found must not extend before that position. | ||
| 2265 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 2266 | If not nil and not t, move to limit of search and return nil. | ||
| 2267 | Optional fourth argument is repeat count--search for successive occurrences. | ||
| 2268 | |||
| 2269 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2270 | of words in STRING to a regexp used to search words without regard | ||
| 2271 | to punctuation. */) | ||
| 2272 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | ||
| 2273 | { | ||
| 2274 | return search_command (Fword_search_regexp (string, Qt), bound, noerror, count, -1, 1, 0); | ||
| 2275 | } | ||
| 2276 | |||
| 2277 | DEFUN ("word-search-forward-lax", Fword_search_forward_lax, Sword_search_forward_lax, 1, 4, | ||
| 2278 | "sWord search: ", | ||
| 2279 | doc: /* Search forward from point for STRING, ignoring differences in punctuation. | ||
| 2280 | Set point to the end of the occurrence found, and return point. | ||
| 2281 | |||
| 2282 | Unlike `word-search-forward', the end of STRING need not match a word | ||
| 2283 | boundary, unless STRING ends in whitespace. | ||
| 2284 | |||
| 2285 | An optional second argument bounds the search; it is a buffer position. | ||
| 2286 | The match found must not extend after that position. | ||
| 2287 | Optional third argument, if t, means if fail just return nil (no error). | ||
| 2288 | If not nil and not t, move to limit of search and return nil. | ||
| 2289 | Optional fourth argument is repeat count--search for successive occurrences. | ||
| 2290 | |||
| 2291 | Relies on the function `word-search-regexp' to convert a sequence | ||
| 2292 | of words in STRING to a regexp used to search words without regard | ||
| 2293 | to punctuation. */) | ||
| 2294 | (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count) | ||
| 2295 | { | ||
| 2296 | return search_command (Fword_search_regexp (string, Qt), bound, noerror, count, 1, 1, 0); | ||
| 2297 | } | ||
| 2298 | |||
| 2299 | DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, | 2123 | DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, |
| 2300 | "sRE search backward: ", | 2124 | "sRE search backward: ", |
| 2301 | doc: /* Search backward from point for match for regular expression REGEXP. | 2125 | doc: /* Search backward from point for match for regular expression REGEXP. |
| @@ -3252,11 +3076,6 @@ is to bind it with `let' around a small expression. */); | |||
| 3252 | defsubr (&Sposix_string_match); | 3076 | defsubr (&Sposix_string_match); |
| 3253 | defsubr (&Ssearch_forward); | 3077 | defsubr (&Ssearch_forward); |
| 3254 | defsubr (&Ssearch_backward); | 3078 | defsubr (&Ssearch_backward); |
| 3255 | defsubr (&Sword_search_regexp); | ||
| 3256 | defsubr (&Sword_search_forward); | ||
| 3257 | defsubr (&Sword_search_backward); | ||
| 3258 | defsubr (&Sword_search_forward_lax); | ||
| 3259 | defsubr (&Sword_search_backward_lax); | ||
| 3260 | defsubr (&Sre_search_forward); | 3079 | defsubr (&Sre_search_forward); |
| 3261 | defsubr (&Sre_search_backward); | 3080 | defsubr (&Sre_search_backward); |
| 3262 | defsubr (&Sposix_search_forward); | 3081 | defsubr (&Sposix_search_forward); |