From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: isearch-allow-move [Was: isearch-allow-prefix] Date: Sun, 09 Jun 2013 23:09:24 +0300 Organization: JURTA Message-ID: <87fvwrnj0r.fsf@mail.jurta.org> References: <20130525200103.GA3451@acm.acm> <878v32aj3c.fsf@mail.jurta.org> <20130602210512.GC2765@acm.acm> <87sj0xn484.fsf@mail.jurta.org> <20130604212400.GB2492@acm.acm> <87d2s1otjb.fsf@mail.jurta.org> <20130605210241.GA3730@acm.acm> <8761xr93h5.fsf_-_@mail.jurta.org> <20130606200719.GA3911@acm.acm> <87ehcexw3u.fsf@mail.jurta.org> <20130607103057.GA3199@acm.acm> <87hah9lnw5.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1370808984 16278 80.91.229.3 (9 Jun 2013 20:16:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Jun 2013 20:16:24 +0000 (UTC) Cc: Stefan Monnier , Drew Adams , emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jun 09 22:16:24 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ulm2J-0002D6-3Q for ged-emacs-devel@m.gmane.org; Sun, 09 Jun 2013 22:16:23 +0200 Original-Received: from localhost ([::1]:46107 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ulm2I-0007ZM-KI for ged-emacs-devel@m.gmane.org; Sun, 09 Jun 2013 16:16:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ulm2C-0007U5-Jk for emacs-devel@gnu.org; Sun, 09 Jun 2013 16:16:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ulm2A-0001qv-Vr for emacs-devel@gnu.org; Sun, 09 Jun 2013 16:16:16 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:51962 helo=ps18281.dreamhostps.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ulm2A-0001qk-NU for emacs-devel@gnu.org; Sun, 09 Jun 2013 16:16:14 -0400 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 42D30258B9E91C; Sun, 9 Jun 2013 13:16:12 -0700 (PDT) In-Reply-To: <87hah9lnw5.fsf@mail.jurta.org> (Juri Linkov's message of "Fri, 07 Jun 2013 22:30:18 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 69.163.218.105 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160295 Archived-At: > However, the new feature `M-s C-f' helped to discover a problem > in a word search where the same problem exists in `C-M-y' > (isearch-yank-char). Actually removing OMIT-NULLS from `split-string' produces a wrong regexp "\\bw\\W+\\b" for the input string "w ". Better is to handle leading/trailing whitespace explicitly to produce more correct regexp "\\bw\\b\\W+" as the patch below does. This feature also helped to discover more problems (in addition to the above mentioned problem where `isearch-yank-char' failed to yank trailing whitespace). Another problem is that `word-search-regexp' fails to handle multi-line matches. This problem can be fixed by using "\\`" instead of "\\^" in `word-search-regexp'. The third problem is the need to apply the LAX arg to the beginning of the regexp in a reverse search that can be fixed by adding a new argument BACKWARD to `word-search-regexp'. `isearch-symbol-regexp' requires the same changes that will make it a copy of `word-search-regexp' that uses "\\_<" and "\\_>" instead of "\\b". === modified file 'lisp/isearch.el' --- lisp/isearch.el 2013-06-06 06:23:19 +0000 +++ lisp/isearch.el 2013-06-09 20:08:29 +0000 @@ -1536,7 +1638,7 @@ (defun isearch-toggle-invisible () ;; Word search -(defun word-search-regexp (string &optional lax) +(defun word-search-regexp (string &optional lax backward) "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 @@ -1545,12 +1647,14 @@ (defun word-search-regexp (string &optio Used in `word-search-forward', `word-search-backward', `word-search-forward-lax', `word-search-backward-lax'." - (if (string-match-p "^\\W*$" string) - "" + (if (string-match-p "\\`\\W*\\'" string) + "\\W*" (concat - "\\b" - (mapconcat 'identity (split-string string "\\W+" t) "\\W+") - (if (or (not lax) (string-match-p "\\W$" string)) "\\b")))) + (if (string-match-p "\\`\\W" string) "\\W+") + (if (or (not lax) (not backward)) "\\b") + (mapconcat 'regexp-quote (split-string string "\\W+" t) "\\W+") + (if (or (not lax) backward) "\\b") + (if (string-match-p "\\W\\'" string) "\\W+")))) (defun word-search-backward (string &optional bound noerror count) "Search backward from point for STRING, ignoring differences in punctuation. @@ -1565,7 +1669,7 @@ (defun word-search-backward (string &opt of words in STRING to a regexp used to search words without regard to punctuation." (interactive "sWord search backward: ") - (re-search-backward (word-search-regexp string nil) bound noerror count)) + (re-search-backward (word-search-regexp string nil t) bound noerror count)) (defun word-search-forward (string &optional bound noerror count) "Search forward from point for STRING, ignoring differences in punctuation. @@ -1580,7 +1684,7 @@ (defun word-search-forward (string &opti of words in STRING to a regexp used to search words without regard to punctuation." (interactive "sWord search: ") - (re-search-forward (word-search-regexp string nil) bound noerror count)) + (re-search-forward (word-search-regexp string nil nil) bound noerror count)) (defun word-search-backward-lax (string &optional bound noerror count) "Search backward from point for STRING, ignoring differences in punctuation. @@ -1599,7 +1703,7 @@ (defun word-search-backward-lax (string of words in STRING to a regexp used to search words without regard to punctuation." (interactive "sWord search backward: ") - (re-search-backward (word-search-regexp string t) bound noerror count)) + (re-search-backward (word-search-regexp string t t) bound noerror count)) (defun word-search-forward-lax (string &optional bound noerror count) "Search forward from point for STRING, ignoring differences in punctuation. @@ -1618,15 +1722,22 @@ (defun word-search-forward-lax (string & of words in STRING to a regexp used to search words without regard to punctuation." (interactive "sWord search: ") - (re-search-forward (word-search-regexp string t) bound noerror count)) + (re-search-forward (word-search-regexp string t nil) bound noerror count)) ;; Symbol search -(defun isearch-symbol-regexp (string &optional lax) +(defun isearch-symbol-regexp (string &optional lax backward) "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 (string-match-p "\\`\\W*\\'" string) + "\\W*" + (concat + (if (string-match-p "\\`\\W" string) "\\W+") + (if (or (not lax) (not backward)) "\\_<") + (mapconcat 'regexp-quote (split-string string "\\W+" t) "\\W+") + (if (or (not lax) backward) "\\_>") + (if (string-match-p "\\W\\'" string) "\\W+")))) PS: a table that summarizes the returned values after the change: (word-search-regexp "" ) "\\W*" (word-search-regexp " " ) "\\W*" (word-search-regexp "w" ) "\\bw\\b" (word-search-regexp " w" ) "\\W+\\bw\\b" (word-search-regexp "w " ) "\\bw\\b\\W+" (word-search-regexp " w " ) "\\W+\\bw\\b\\W+" (word-search-regexp "w w" ) "\\bw\\W+w\\b" (word-search-regexp " w w" ) "\\W+\\bw\\W+w\\b" (word-search-regexp "w w " ) "\\bw\\W+w\\b\\W+" (word-search-regexp " w w ") "\\W+\\bw\\W+w\\b\\W+" (word-search-regexp "" nil t) "\\W*" (word-search-regexp " " nil t) "\\W*" (word-search-regexp "w" nil t) "\\bw\\b" (word-search-regexp " w" nil t) "\\W+\\bw\\b" (word-search-regexp "w " nil t) "\\bw\\b\\W+" (word-search-regexp " w " nil t) "\\W+\\bw\\b\\W+" (word-search-regexp "w w" nil t) "\\bw\\W+w\\b" (word-search-regexp " w w" nil t) "\\W+\\bw\\W+w\\b" (word-search-regexp "w w " nil t) "\\bw\\W+w\\b\\W+" (word-search-regexp " w w " nil t) "\\W+\\bw\\W+w\\b\\W+" (word-search-regexp "" t) "\\W*" (word-search-regexp " " t) "\\W*" (word-search-regexp "w" t) "\\bw" (word-search-regexp " w" t) "\\W+\\bw" (word-search-regexp "w " t) "\\bw\\W+" (word-search-regexp " w " t) "\\W+\\bw\\W+" (word-search-regexp "w w" t) "\\bw\\W+w" (word-search-regexp " w w" t) "\\W+\\bw\\W+w" (word-search-regexp "w w " t) "\\bw\\W+w\\W+" (word-search-regexp " w w " t) "\\W+\\bw\\W+w\\W+" (word-search-regexp "" t t) "\\W*" (word-search-regexp " " t t) "\\W*" (word-search-regexp "w" t t) "w\\b" (word-search-regexp " w" t t) "\\W+w\\b" (word-search-regexp "w " t t) "w\\b\\W+" (word-search-regexp " w " t t) "\\W+w\\b\\W+" (word-search-regexp "w w" t t) "w\\W+w\\b" (word-search-regexp " w w" t t) "\\W+w\\W+w\\b" (word-search-regexp "w w " t t) "w\\W+w\\b\\W+" (word-search-regexp " w w " t t) "\\W+w\\W+w\\b\\W+" (isearch-symbol-regexp "" ) "\\W*" (isearch-symbol-regexp " " ) "\\W*" (isearch-symbol-regexp "w" ) "\\_" (isearch-symbol-regexp " w" ) "\\W+\\_" (isearch-symbol-regexp "w " ) "\\_\\W+" (isearch-symbol-regexp " w " ) "\\W+\\_\\W+" (isearch-symbol-regexp "w w" ) "\\_" (isearch-symbol-regexp " w w" ) "\\W+\\_" (isearch-symbol-regexp "w w " ) "\\_\\W+" (isearch-symbol-regexp " w w ") "\\W+\\_\\W+" (isearch-symbol-regexp "" nil t) "\\W*" (isearch-symbol-regexp " " nil t) "\\W*" (isearch-symbol-regexp "w" nil t) "\\_" (isearch-symbol-regexp " w" nil t) "\\W+\\_" (isearch-symbol-regexp "w " nil t) "\\_\\W+" (isearch-symbol-regexp " w " nil t) "\\W+\\_\\W+" (isearch-symbol-regexp "w w" nil t) "\\_" (isearch-symbol-regexp " w w" nil t) "\\W+\\_" (isearch-symbol-regexp "w w " nil t) "\\_\\W+" (isearch-symbol-regexp " w w " nil t) "\\W+\\_\\W+" (isearch-symbol-regexp "" t) "\\W*" (isearch-symbol-regexp " " t) "\\W*" (isearch-symbol-regexp "w" t) "\\_" (isearch-symbol-regexp " w" t t) "\\W+w\\_>" (isearch-symbol-regexp "w " t t) "w\\_>\\W+" (isearch-symbol-regexp " w " t t) "\\W+w\\_>\\W+" (isearch-symbol-regexp "w w" t t) "w\\W+w\\_>" (isearch-symbol-regexp " w w" t t) "\\W+w\\W+w\\_>" (isearch-symbol-regexp "w w " t t) "w\\W+w\\_>\\W+" (isearch-symbol-regexp " w w " t t) "\\W+w\\W+w\\_>\\W+"