diff options
| author | Juri Linkov | 2013-06-14 00:49:10 +0300 |
|---|---|---|
| committer | Juri Linkov | 2013-06-14 00:49:10 +0300 |
| commit | a22289f7ab658767b2f586aa1f1f794b1470df95 (patch) | |
| tree | f475873ede54bd64998be620e5fe6ba462a0b518 /lisp | |
| parent | cb89acab6cdfa418d1d14ad3200712e1dd406673 (diff) | |
| download | emacs-a22289f7ab658767b2f586aa1f1f794b1470df95.tar.gz emacs-a22289f7ab658767b2f586aa1f1f794b1470df95.zip | |
* lisp/isearch.el (word-search-regexp): Match whitespace if the search
string begins or ends in whitespace. The LAX arg is applied to
both ends of the search string. Use `regexp-quote' and explicit
\< and \> instead of \b. Use \` and \' instead of ^ and $.
(isearch-symbol-regexp): Sync with `word-search-regexp' where word
boundaries are replaced with symbol boundaries, and characters
between symbols match non-word non-symbol syntax.
Fixes: debbugs:14602
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/isearch.el | 41 |
2 files changed, 41 insertions, 10 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f21f6e4b068..5327ce12e7b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,15 @@ | |||
| 1 | 2013-06-13 Juri Linkov <juri@jurta.org> | 1 | 2013-06-13 Juri Linkov <juri@jurta.org> |
| 2 | 2 | ||
| 3 | * isearch.el (word-search-regexp): Match whitespace if the search | ||
| 4 | string begins or ends in whitespace. The LAX arg is applied to | ||
| 5 | both ends of the search string. Use `regexp-quote' and explicit | ||
| 6 | \< and \> instead of \b. Use \` and \' instead of ^ and $. | ||
| 7 | (isearch-symbol-regexp): Sync with `word-search-regexp' where word | ||
| 8 | boundaries are replaced with symbol boundaries, and characters | ||
| 9 | between symbols match non-word non-symbol syntax. (Bug#14602) | ||
| 10 | |||
| 11 | 2013-06-13 Juri Linkov <juri@jurta.org> | ||
| 12 | |||
| 3 | * isearch.el (isearch-del-char): Don't exceed the length of | 13 | * isearch.el (isearch-del-char): Don't exceed the length of |
| 4 | `isearch-string' by the prefix arg. (Bug#14563) | 14 | `isearch-string' by the prefix arg. (Bug#14563) |
| 5 | 15 | ||
diff --git a/lisp/isearch.el b/lisp/isearch.el index ddb5ba9331c..37070ba6f51 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el | |||
| @@ -1540,17 +1540,22 @@ nil and a non-nil value of the option `search-invisible' | |||
| 1540 | "Return a regexp which matches words, ignoring punctuation. | 1540 | "Return a regexp which matches words, ignoring punctuation. |
| 1541 | Given STRING, a string of words separated by word delimiters, | 1541 | Given STRING, a string of words separated by word delimiters, |
| 1542 | compute a regexp that matches those exact words separated by | 1542 | compute a regexp that matches those exact words separated by |
| 1543 | arbitrary punctuation. If LAX is non-nil, the end of the string | 1543 | arbitrary punctuation. If the string begins or ends in whitespace, |
| 1544 | need not match a word boundary unless it ends in whitespace. | 1544 | the beginning or the end of the string matches arbitrary whitespace. |
| 1545 | Otherwise if LAX is non-nil, the beginning or the end of the string | ||
| 1546 | need not match a word boundary. | ||
| 1545 | 1547 | ||
| 1546 | Used in `word-search-forward', `word-search-backward', | 1548 | Used in `word-search-forward', `word-search-backward', |
| 1547 | `word-search-forward-lax', `word-search-backward-lax'." | 1549 | `word-search-forward-lax', `word-search-backward-lax'." |
| 1548 | (if (string-match-p "^\\W*$" string) | 1550 | (cond |
| 1549 | "" | 1551 | ((equal string "") "") |
| 1550 | (concat | 1552 | ((string-match-p "\\`\\W+\\'" string) "\\W+") |
| 1551 | "\\b" | 1553 | (t (concat |
| 1552 | (mapconcat 'identity (split-string string "\\W+" t) "\\W+") | 1554 | (if (string-match-p "\\`\\W" string) "\\W+" |
| 1553 | (if (or (not lax) (string-match-p "\\W$" string)) "\\b")))) | 1555 | (unless lax "\\<")) |
| 1556 | (mapconcat 'regexp-quote (split-string string "\\W+" t) "\\W+") | ||
| 1557 | (if (string-match-p "\\W\\'" string) "\\W+" | ||
| 1558 | (unless lax "\\>")))))) | ||
| 1554 | 1559 | ||
| 1555 | (defun word-search-backward (string &optional bound noerror count) | 1560 | (defun word-search-backward (string &optional bound noerror count) |
| 1556 | "Search backward from point for STRING, ignoring differences in punctuation. | 1561 | "Search backward from point for STRING, ignoring differences in punctuation. |
| @@ -1625,8 +1630,24 @@ to punctuation." | |||
| 1625 | (defun isearch-symbol-regexp (string &optional lax) | 1630 | (defun isearch-symbol-regexp (string &optional lax) |
| 1626 | "Return a regexp which matches STRING as a symbol. | 1631 | "Return a regexp which matches STRING as a symbol. |
| 1627 | Creates a regexp where STRING is surrounded by symbol delimiters \\_< and \\_>. | 1632 | Creates a regexp where STRING is surrounded by symbol delimiters \\_< and \\_>. |
| 1628 | If LAX is non-nil, the end of the string need not match a symbol boundary." | 1633 | If there are more than one symbol, then compute a regexp that matches |
| 1629 | (concat "\\_<" (regexp-quote string) (unless lax "\\_>"))) | 1634 | those exact symbols separated by non-symbol characters. If the string |
| 1635 | begins or ends in whitespace, the beginning or the end of the string | ||
| 1636 | matches arbitrary non-symbol whitespace. Otherwise if LAX is non-nil, | ||
| 1637 | the beginning or the end of the string need not match a symbol boundary." | ||
| 1638 | (let ((not-word-symbol-re | ||
| 1639 | ;; This regexp matches all syntaxes except word and symbol syntax. | ||
| 1640 | ;; FIXME: Replace it with something shorter if possible (bug#14602). | ||
| 1641 | "\\(?:\\s-\\|\\s.\\|\\s(\\|\\s)\\|\\s\"\\|\\s\\\\|\\s/\\|\\s$\\|\\s'\\|\\s<\\|\\s>\\|\\s@\\|\\s!\\|\\s|\\)+")) | ||
| 1642 | (cond | ||
| 1643 | ((equal string "") "") | ||
| 1644 | ((string-match-p (format "\\`%s\\'" not-word-symbol-re) string) not-word-symbol-re) | ||
| 1645 | (t (concat | ||
| 1646 | (if (string-match-p (format "\\`%s" not-word-symbol-re) string) not-word-symbol-re | ||
| 1647 | (unless lax "\\_<")) | ||
| 1648 | (mapconcat 'regexp-quote (split-string string not-word-symbol-re t) not-word-symbol-re) | ||
| 1649 | (if (string-match-p (format "%s\\'" not-word-symbol-re) string) not-word-symbol-re | ||
| 1650 | (unless lax "\\_>"))))))) | ||
| 1630 | 1651 | ||
| 1631 | (put 'isearch-symbol-regexp 'isearch-message-prefix "symbol ") | 1652 | (put 'isearch-symbol-regexp 'isearch-message-prefix "symbol ") |
| 1632 | 1653 | ||