From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Chong Yidong" Newsgroups: gmane.emacs.devel Subject: Re: search-whitespace-regexp Date: Fri, 4 Feb 2005 10:55:05 -0500 (EST) Message-ID: <2252.219.74.2.152.1107532505.squirrel@219.74.2.152> References: <1982.220.255.95.17.1107526353.squirrel@220.255.95.17> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1107532935 694 80.91.229.2 (4 Feb 2005 16:02:15 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 4 Feb 2005 16:02:15 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Feb 04 17:02:15 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Cx5uM-00051j-Cs for ged-emacs-devel@m.gmane.org; Fri, 04 Feb 2005 17:02:10 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Cx67u-0005WR-9j for ged-emacs-devel@m.gmane.org; Fri, 04 Feb 2005 11:16:10 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Cx67I-0005Ls-GE for emacs-devel@gnu.org; Fri, 04 Feb 2005 11:15:32 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Cx67G-0005KJ-Lh for emacs-devel@gnu.org; Fri, 04 Feb 2005 11:15:31 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Cx67G-0005KC-Hs for emacs-devel@gnu.org; Fri, 04 Feb 2005 11:15:30 -0500 Original-Received: from [64.21.80.18] (helo=shark.dnsvelocity.com) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1Cx5nd-0000bM-LT for emacs-devel@gnu.org; Fri, 04 Feb 2005 10:55:14 -0500 Original-Received: from stupidch by shark.dnsvelocity.com with local (Exim 4.43) id 1Cx5nV-0007Nr-J9 for emacs-devel@gnu.org; Fri, 04 Feb 2005 10:55:05 -0500 Original-Received: from 219.74.2.152 ([219.74.2.152]) (SquirrelMail authenticated user cyd@stupidchicken.com); by www.stupidchicken.com with HTTP; Fri, 4 Feb 2005 10:55:05 -0500 (EST) In-Reply-To: Original-To: emacs-devel@gnu.org User-Agent: SquirrelMail/1.4.3a X-Mailer: SquirrelMail/1.4.3a X-Priority: 3 (Normal) Importance: Normal X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - shark.dnsvelocity.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [32675 33085] / [47 12] X-AntiAbuse: Sender Address Domain - shark.dnsvelocity.com X-Source: /usr/local/cpanel/3rdparty/bin/php X-Source-Args: /usr/local/cpanel/3rdparty/bin/php /usr/local/cpanel/base/3rdparty/squirrelmail/src/compose.php X-Source-Dir: stupidchicken.com:/base/3rdparty/squirrelmail/src X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org X-MailScanner-To: ged-emacs-devel@m.gmane.org Xref: main.gmane.org gmane.emacs.devel:32877 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:32877 > I generally agree with your proposal to change the behavior of isearch > such that only plain search uses a "magical space", whereas regexp search > is made more "raw". But the above code is wrong in that it fails to quote > chars like "[" in the search string. How about this revised patch? *** isearch.el~ Fri Feb 4 19:33:15 2005 --- isearch.el Fri Feb 4 23:47:15 2005 *************** *** 109,122 **** :type 'boolean :group 'isearch) ! (defcustom search-whitespace-regexp "\\s-+" "*If non-nil, regular expression to match a sequence of whitespace chars. ! This applies to regular expression incremental search. ! When you put a space or spaces in the incremental regexp, it stands for ! this, unless it is inside of a regexp construct such as [...] or *, + or ?. ! You might want to use something like \"[ \\t\\r\\n]+\" instead. ! In the Customization buffer, that is `[' followed by a space, ! a tab, a carriage return (control-M), a newline, and `]+'." :type 'regexp :group 'isearch) --- 109,124 ---- :type 'boolean :group 'isearch) ! (defcustom search-whitespace-regexp nil "*If non-nil, regular expression to match a sequence of whitespace chars. ! When you put a space or spaces in the incremental search string, ! it will be replaced with this regular expression when searching. ! This applies to `isearch-forward' and `isearch-backward', but not ! the regular expression searches `isearch-forward-regexp' and ! `isearch-backward-regexp'. You might want to use something like ! \"[ \\t\\r\\n]+\". In the Customization buffer, that is `[' ! followed by a space, a tab, a carriage return (control-M), a ! newline, and `]+'." :type 'regexp :group 'isearch) *************** *** 514,519 **** --- 516,525 ---- With a prefix argument, do an incremental regular expression search instead. \\ As you type characters, they add to the search string and are found. + + If `search-whitespace-regexp' is non-nil, any space or spaces + entered are replaced with that regular expression when searching. + The following non-printing keys are bound in `isearch-mode-map'. Type \\[isearch-delete-char] to cancel last input item from end of search string. *************** *** 573,584 **** Do incremental search forward for regular expression. With a prefix argument, do a regular string search instead. Like ordinary incremental search except that your input ! is treated as a regexp. See \\[isearch-forward] for more info. ! ! In regexp incremental searches, a space or spaces normally matches ! any whitespace (the variable `search-whitespace-regexp' controls ! precisely what that means). If you want to search for a literal space ! and nothing else, enter `[ ]'." (interactive "P\np") (isearch-mode t (null not-regexp) nil (not no-recursive-edit))) --- 579,585 ---- Do incremental search forward for regular expression. With a prefix argument, do a regular string search instead. Like ordinary incremental search except that your input ! is treated as a regexp. See \\[isearch-forward] for more info." (interactive "P\np") (isearch-mode t (null not-regexp) nil (not no-recursive-edit))) *************** *** 2029,2035 **** (isearch-regexp (if isearch-forward 're-search-forward 're-search-backward)) (t ! (if isearch-forward 'search-forward 'search-backward))))) (defun isearch-search () ;; Do the search with the current search string. --- 2030,2045 ---- (isearch-regexp (if isearch-forward 're-search-forward 're-search-backward)) (t ! (if isearch-forward 'isearch-search-forward ! 'isearch-search-backward))))) ! ! (defun isearch-search-forward (string &optional bound noerror count) ! (let ((search-spaces-regexp search-whitespace-regexp)) ! (re-search-forward (regexp-quote string) bound noerror count))) ! ! (defun isearch-search-backward (string &optional bound noerror count) ! (let ((search-spaces-regexp search-whitespace-regexp)) ! (re-search-backward (regexp-quote string) bound noerror count))) (defun isearch-search () ;; Do the search with the current search string. *************** *** 2041,2047 **** (let ((inhibit-point-motion-hooks search-invisible) (inhibit-quit nil) (case-fold-search isearch-case-fold-search) - (search-spaces-regexp search-whitespace-regexp) (retry t)) (if isearch-regexp (setq isearch-invalid-regexp nil)) (setq isearch-within-brackets nil) --- 2051,2056 ---- *************** *** 2377,2384 **** (defun isearch-lazy-highlight-search () "Search ahead for the next or previous match, for lazy highlighting. Attempt to do the search exactly the way the pending isearch would." ! (let ((case-fold-search isearch-case-fold-search) ! (search-spaces-regexp search-whitespace-regexp)) (funcall (isearch-search-fun) isearch-string (if isearch-forward --- 2386,2392 ---- (defun isearch-lazy-highlight-search () "Search ahead for the next or previous match, for lazy highlighting. Attempt to do the search exactly the way the pending isearch would." ! (let ((case-fold-search isearch-case-fold-search)) (funcall (isearch-search-fun) isearch-string (if isearch-forward