diff options
author | Juri Linkov <juri@jurta.org> | 2013-06-14 00:49:10 +0300 |
---|---|---|
committer | Juri Linkov <juri@jurta.org> | 2013-06-14 00:49:10 +0300 |
commit | a22289f7ab658767b2f586aa1f1f794b1470df95 (patch) | |
tree | f475873ede54bd64998be620e5fe6ba462a0b518 /lisp/isearch.el | |
parent | cb89acab6cdfa418d1d14ad3200712e1dd406673 (diff) | |
download | emacs-a22289f7ab658767b2f586aa1f1f794b1470df95.tar.gz |
* 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/isearch.el')
-rw-r--r-- | lisp/isearch.el | 41 |
1 files changed, 31 insertions, 10 deletions
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' "Return a regexp which matches words, ignoring punctuation. Given STRING, a string of words separated by word delimiters, compute a regexp that matches those exact words separated by -arbitrary punctuation. If LAX is non-nil, the end of the string -need not match a word boundary unless it ends in whitespace. +arbitrary punctuation. If the string begins or ends in whitespace, +the beginning or the end of the string matches arbitrary whitespace. +Otherwise if LAX is non-nil, the beginning or the end of the string +need not match a word boundary. Used in `word-search-forward', `word-search-backward', `word-search-forward-lax', `word-search-backward-lax'." - (if (string-match-p "^\\W*$" string) - "" - (concat - "\\b" - (mapconcat 'identity (split-string string "\\W+" t) "\\W+") - (if (or (not lax) (string-match-p "\\W$" string)) "\\b")))) + (cond + ((equal string "") "") + ((string-match-p "\\`\\W+\\'" string) "\\W+") + (t (concat + (if (string-match-p "\\`\\W" string) "\\W+" + (unless lax "\\<")) + (mapconcat 'regexp-quote (split-string string "\\W+" t) "\\W+") + (if (string-match-p "\\W\\'" string) "\\W+" + (unless lax "\\>")))))) (defun word-search-backward (string &optional bound noerror count) "Search backward from point for STRING, ignoring differences in punctuation. @@ -1625,8 +1630,24 @@ to punctuation." (defun isearch-symbol-regexp (string &optional lax) "Return a regexp which matches STRING as a symbol. Creates a regexp where STRING is surrounded by symbol delimiters \\_< and \\_>. -If LAX is non-nil, the end of the string need not match a symbol boundary." - (concat "\\_<" (regexp-quote string) (unless lax "\\_>"))) +If there are more than one symbol, then compute a regexp that matches +those exact symbols separated by non-symbol characters. If the string +begins or ends in whitespace, the beginning or the end of the string +matches arbitrary non-symbol whitespace. Otherwise if LAX is non-nil, +the beginning or the end of the string need not match a symbol boundary." + (let ((not-word-symbol-re + ;; This regexp matches all syntaxes except word and symbol syntax. + ;; FIXME: Replace it with something shorter if possible (bug#14602). + "\\(?:\\s-\\|\\s.\\|\\s(\\|\\s)\\|\\s\"\\|\\s\\\\|\\s/\\|\\s$\\|\\s'\\|\\s<\\|\\s>\\|\\s@\\|\\s!\\|\\s|\\)+")) + (cond + ((equal string "") "") + ((string-match-p (format "\\`%s\\'" not-word-symbol-re) string) not-word-symbol-re) + (t (concat + (if (string-match-p (format "\\`%s" not-word-symbol-re) string) not-word-symbol-re + (unless lax "\\_<")) + (mapconcat 'regexp-quote (split-string string not-word-symbol-re t) not-word-symbol-re) + (if (string-match-p (format "%s\\'" not-word-symbol-re) string) not-word-symbol-re + (unless lax "\\_>"))))))) (put 'isearch-symbol-regexp 'isearch-message-prefix "symbol ") |