aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2012-05-17 03:03:49 +0300
committerJuri Linkov2012-05-17 03:03:49 +0300
commita0a79cde7c978cf457c4a817b9a67bb4557f8a5c (patch)
treeb7097e44bfdde8e6596d5579c736a6eb4d3181c0
parent5ec546086a3f0ea5ad6ba2501dc4d84188e8b880 (diff)
downloademacs-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/ChangeLog7
-rw-r--r--lisp/isearch.el88
-rw-r--r--src/ChangeLog7
-rw-r--r--src/search.c181
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 @@
12012-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
12012-05-16 Agustín Martín Domingo <agustin.martin@hispalinux.es> 82012-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.
1389Given STRING, a string of words separated by word delimiters,
1390compute a regexp that matches those exact words separated by
1391arbitrary punctuation. If LAX is non-nil, the end of the string
1392need not match a word boundary unless it ends in whitespace.
1393
1394Used 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.
1405Set point to the beginning of the occurrence found, and return point.
1406An optional second argument bounds the search; it is a buffer position.
1407The match found must not extend before that position.
1408Optional 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.
1410Optional fourth argument is repeat count--search for successive occurrences.
1411
1412Relies on the function `word-search-regexp' to convert a sequence
1413of words in STRING to a regexp used to search words without regard
1414to 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.
1420Set point to the end of the occurrence found, and return point.
1421An optional second argument bounds the search; it is a buffer position.
1422The match found must not extend after that position.
1423Optional 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.
1425Optional fourth argument is repeat count--search for successive occurrences.
1426
1427Relies on the function `word-search-regexp' to convert a sequence
1428of words in STRING to a regexp used to search words without regard
1429to 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.
1435Set point to the beginning of the occurrence found, and return point.
1436
1437Unlike `word-search-backward', the end of STRING need not match a word
1438boundary, unless STRING ends in whitespace.
1439
1440An optional second argument bounds the search; it is a buffer position.
1441The match found must not extend before that position.
1442Optional 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.
1444Optional fourth argument is repeat count--search for successive occurrences.
1445
1446Relies on the function `word-search-regexp' to convert a sequence
1447of words in STRING to a regexp used to search words without regard
1448to 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.
1454Set point to the end of the occurrence found, and return point.
1455
1456Unlike `word-search-forward', the end of STRING need not match a word
1457boundary, unless STRING ends in whitespace.
1458
1459An optional second argument bounds the search; it is a buffer position.
1460The match found must not extend after that position.
1461Optional 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.
1463Optional fourth argument is repeat count--search for successive occurrences.
1464
1465Relies on the function `word-search-regexp' to convert a sequence
1466of words in STRING to a regexp used to search words without regard
1467to 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.
1386The arg DELIMITED (prefix arg if interactive), if non-nil, means replace 1474The 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 @@
12012-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
12012-05-16 Paul Eggert <eggert@cs.ucla.edu> 82012-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
2081DEFUN ("word-search-regexp", Fword_search_regexp, Sword_search_regexp, 1, 2, 0,
2082 doc: /* Return a regexp which matches words, ignoring punctuation.
2083Given STRING, a string of words separated by word delimiters,
2084compute a regexp that matches those exact words separated by
2085arbitrary punctuation. If LAX is non-nil, the end of the string
2086need not match a word boundary unless it ends in whitespace.
2087
2088Used 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
2177DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4, 2081DEFUN ("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
2219DEFUN ("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.
2222Set point to the beginning of the occurrence found, and return point.
2223An optional second argument bounds the search; it is a buffer position.
2224The match found must not extend before that position.
2225Optional 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.
2227Optional fourth argument is repeat count--search for successive occurrences.
2228
2229Relies on the function `word-search-regexp' to convert a sequence
2230of words in STRING to a regexp used to search words without regard
2231to 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
2237DEFUN ("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.
2240Set point to the end of the occurrence found, and return point.
2241An optional second argument bounds the search; it is a buffer position.
2242The match found must not extend after that position.
2243Optional 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.
2245Optional fourth argument is repeat count--search for successive occurrences.
2246
2247Relies on the function `word-search-regexp' to convert a sequence
2248of words in STRING to a regexp used to search words without regard
2249to 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
2255DEFUN ("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.
2258Set point to the beginning of the occurrence found, and return point.
2259
2260Unlike `word-search-backward', the end of STRING need not match a word
2261boundary, unless STRING ends in whitespace.
2262
2263An optional second argument bounds the search; it is a buffer position.
2264The match found must not extend before that position.
2265Optional 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.
2267Optional fourth argument is repeat count--search for successive occurrences.
2268
2269Relies on the function `word-search-regexp' to convert a sequence
2270of words in STRING to a regexp used to search words without regard
2271to 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
2277DEFUN ("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.
2280Set point to the end of the occurrence found, and return point.
2281
2282Unlike `word-search-forward', the end of STRING need not match a word
2283boundary, unless STRING ends in whitespace.
2284
2285An optional second argument bounds the search; it is a buffer position.
2286The match found must not extend after that position.
2287Optional 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.
2289Optional fourth argument is repeat count--search for successive occurrences.
2290
2291Relies on the function `word-search-regexp' to convert a sequence
2292of words in STRING to a regexp used to search words without regard
2293to 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
2299DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, 2123DEFUN ("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);