emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r112974: * lisp/isearch.el (word-search-regexp): Mat


From: Juri Linkov
Subject: [Emacs-diffs] trunk r112974: * lisp/isearch.el (word-search-regexp): Match whitespace if the search
Date: Thu, 13 Jun 2013 21:49:14 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 112974
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/14602
committer: Juri Linkov <address@hidden>
branch nick: trunk
timestamp: Fri 2013-06-14 00:49:10 +0300
message:
  * 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.
modified:
  etc/NEWS                       news-20100311060928-aoit31wvzf25yr1z-1
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/isearch.el                isearch.el-20091113204419-o5vbwnq5f7feedwu-486
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2013-06-13 20:50:51 +0000
+++ b/etc/NEWS  2013-06-13 21:49:10 +0000
@@ -300,6 +300,14 @@
 `isearch-printing-char', `isearch-quote-char', `isearch-yank-word',
 `isearch-yank-line'.
 
+*** Word search now matches whitespace at the beginning/end
+of the search string if it contains leading/trailing whitespace.
+In an incremental word search or when using a non-nil LAX argument
+of `word-search-regexp', the lax matching can also match part of
+the first word (in addition to the lax matching of the last word).
+The same rules are now applied to the symbol search with the difference
+that it matches symbols, and non-symbol characters between symbols.
+
 ** MH-E has been updated to MH-E version 8.5.
 See MH-E-NEWS for details.
 

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-06-13 21:11:42 +0000
+++ b/lisp/ChangeLog    2013-06-13 21:49:10 +0000
@@ -1,5 +1,15 @@
 2013-06-13  Juri Linkov  <address@hidden>
 
+       * 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.  (Bug#14602)
+
+2013-06-13  Juri Linkov  <address@hidden>
+
        * isearch.el (isearch-del-char): Don't exceed the length of
        `isearch-string' by the prefix arg.  (Bug#14563)
 

=== modified file 'lisp/isearch.el'
--- a/lisp/isearch.el   2013-06-13 21:11:42 +0000
+++ b/lisp/isearch.el   2013-06-13 21:49:10 +0000
@@ -1540,17 +1540,22 @@
   "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 @@
 (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>\\|address@hidden|\\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 ")
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]