aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJuri Linkov2012-05-17 03:03:49 +0300
committerJuri Linkov2012-05-17 03:03:49 +0300
commita0a79cde7c978cf457c4a817b9a67bb4557f8a5c (patch)
treeb7097e44bfdde8e6596d5579c736a6eb4d3181c0 /lisp
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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/isearch.el88
2 files changed, 95 insertions, 0 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