From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#10885: Replace expressions: enhance functionality when searching in filled paragraphs Date: Sun, 02 Sep 2012 14:32:33 +0300 Organization: JURTA Message-ID: <87boho1wyz.fsf@mail.jurta.org> References: <33392837.post@talk.nabble.com> <1oipiuxspa.fsf@fencepost.gnu.org> <87d38z1bp3.fsf@mail.jurta.org> <87linm79pc.fsf@mail.jurta.org> <8762ebbehj.fsf@mail.jurta.org> <87oblo21xe.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1346585927 21942 80.91.229.3 (2 Sep 2012 11:38:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Sep 2012 11:38:47 +0000 (UTC) To: 10885@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Sep 02 13:38:48 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1T88Vn-0006E9-Sd for geb-bug-gnu-emacs@m.gmane.org; Sun, 02 Sep 2012 13:38:44 +0200 Original-Received: from localhost ([::1]:57215 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T88Vl-0001d8-8h for geb-bug-gnu-emacs@m.gmane.org; Sun, 02 Sep 2012 07:38:41 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56366) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T88Vh-0001cu-Kr for bug-gnu-emacs@gnu.org; Sun, 02 Sep 2012 07:38:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T88Vf-0007sL-Vx for bug-gnu-emacs@gnu.org; Sun, 02 Sep 2012 07:38:37 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:52638) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T88Vf-0007sG-Rt for bug-gnu-emacs@gnu.org; Sun, 02 Sep 2012 07:38:35 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1T88X3-0008Cf-Kg for bug-gnu-emacs@gnu.org; Sun, 02 Sep 2012 07:40:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 02 Sep 2012 11:40:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10885 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 10885-submit@debbugs.gnu.org id=B10885.134658594531465 (code B ref 10885); Sun, 02 Sep 2012 11:40:01 +0000 Original-Received: (at 10885) by debbugs.gnu.org; 2 Sep 2012 11:39:05 +0000 Original-Received: from localhost ([127.0.0.1]:33951 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T88W8-0008BR-Eh for submit@debbugs.gnu.org; Sun, 02 Sep 2012 07:39:05 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:39441 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T88W4-0008B0-MJ for 10885@debbugs.gnu.org; Sun, 02 Sep 2012 07:39:02 -0400 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 5C723451CC76 for <10885@debbugs.gnu.org>; Sun, 2 Sep 2012 04:37:32 -0700 (PDT) In-Reply-To: <87oblo21xe.fsf@mail.jurta.org> (Juri Linkov's message of "Sun, 02 Sep 2012 12:45:33 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:63674 Archived-At: > 1. Add a new defcustom like `case-replace' with a name e.g. > `replace-lax-whitespace' and use it in `perform-replace'. > When non-nil, spaces will match any whitespace in replacement. This is implemented in the following patch: === modified file 'lisp/replace.el' --- lisp/replace.el 2012-08-06 05:33:39 +0000 +++ lisp/replace.el 2012-09-02 11:27:15 +0000 @@ -33,6 +33,13 @@ (defcustom case-replace t :type 'boolean :group 'matching) +(defcustom replace-lax-whitespace nil + "Non-nil means `query-replace' matches a sequence of whitespace chars. +When you enter a space or spaces in the strings or regexps to be replaced, +it will match any sequence matched by the regexp `search-whitespace-regexp'." + :type 'boolean + :group 'matching) + (defvar query-replace-history nil "Default history list for query-replace commands. See `query-replace-from-history-variable' and @@ -226,6 +233,10 @@ (defun query-replace (from-string to-str matched is all caps, or capitalized, then its replacement is upcased or capitalized.) +If `replace-lax-whitespace' is non-nil, a space or spaces in the string +to be replaced will match a sequence of whitespace chars defined by the +regexp in `search-whitespace-regexp'. + Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace only matches surrounded by word boundaries. Fourth and fifth arg START and END specify the region to operate on. @@ -270,6 +281,10 @@ (defun query-replace-regexp (regexp to-s all caps, or capitalized, then its replacement is upcased or capitalized.) +If `replace-lax-whitespace' is non-nil, a space or spaces in the regexp +to be replaced will match a sequence of whitespace chars defined by the +regexp in `search-whitespace-regexp'. + Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace only matches surrounded by word boundaries. Fourth and fifth arg START and END specify the region to operate on. @@ -346,6 +361,10 @@ (defun query-replace-regexp-eval (regexp Preserves case in each replacement if `case-replace' and `case-fold-search' are non-nil and REGEXP has no uppercase letters. +If `replace-lax-whitespace' is non-nil, a space or spaces in the regexp +to be replaced will match a sequence of whitespace chars defined by the +regexp in `search-whitespace-regexp'. + Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace only matches that are surrounded by word boundaries. Fourth and fifth arg START and END specify the region to operate on." @@ -437,6 +456,10 @@ (defun replace-string (from-string to-st \(Preserving case means that if the string matched is all caps, or capitalized, then its replacement is upcased or capitalized.) +If `replace-lax-whitespace' is non-nil, a space or spaces in the string +to be replaced will match a sequence of whitespace chars defined by the +regexp in `search-whitespace-regexp'. + In Transient Mark mode, if the mark is active, operate on the contents of the region. Otherwise, operate from point to the end of the buffer. @@ -475,6 +498,10 @@ (defun replace-regexp (regexp to-string Preserve case in each match if `case-replace' and `case-fold-search' are non-nil and REGEXP has no uppercase letters. +If `replace-lax-whitespace' is non-nil, a space or spaces in the regexp +to be replaced will match a sequence of whitespace chars defined by the +regexp in `search-whitespace-regexp'. + In Transient Mark mode, if the mark is active, operate on the contents of the region. Otherwise, operate from point to the end of the buffer. @@ -1717,12 +1745,12 @@ (defun replace-match-maybe-edit (newtext (replace-match newtext fixedcase literal) noedit) -(defvar replace-search-function 'search-forward +(defvar replace-search-function nil "Function to use when searching for strings to replace. It is used by `query-replace' and `replace-string', and is called with three arguments, as if it were `search-forward'.") -(defvar replace-re-search-function 're-search-forward +(defvar replace-re-search-function nil "Function to use when searching for regexps to replace. It is used by `query-replace-regexp', `replace-regexp', `query-replace-regexp-eval', and `map-query-replace-regexp'. @@ -1755,9 +1783,16 @@ (defun perform-replace (from-string repl (nocasify (not (and case-replace case-fold-search))) (literal (or (not regexp-flag) (eq regexp-flag 'literal))) (search-function - (if regexp-flag - replace-re-search-function - replace-search-function)) + (or (if regexp-flag + replace-re-search-function + replace-search-function) + (if replace-lax-whitespace + (if regexp-flag + #'re-search-forward-lax-whitespace + #'search-forward-lax-whitespace) + (if regexp-flag + #'re-search-forward + #'search-forward)))) (search-string from-string) (real-match-data nil) ; The match data for the current match. (next-replacement nil) @@ -2120,7 +2156,10 @@ (defun replace-highlight (match-beg matc ;; Set isearch-word to nil because word-replace is regexp-based, ;; so `isearch-search-fun' should not use `word-search-forward'. (isearch-word nil) - (search-whitespace-regexp nil) + (isearch-lax-whitespace + (and replace-lax-whitespace (not regexp))) + (isearch-regexp-lax-whitespace + (and replace-lax-whitespace regexp)) (isearch-case-fold-search case-fold) (isearch-forward t) (isearch-error nil)) === modified file 'lisp/isearch.el' --- lisp/isearch.el 2012-09-02 09:31:45 +0000 +++ lisp/isearch.el 2012-09-02 11:27:15 +0000 @@ -1579,14 +1612,11 @@ (defun isearch-query-replace (&optional ;; set `search-upper-case' to nil to not call ;; `isearch-no-upper-case-p' in `perform-replace' (search-upper-case nil) - (replace-search-function - (if (and isearch-lax-whitespace (not regexp-flag)) - #'search-forward-lax-whitespace - replace-search-function)) - (replace-re-search-function - (if (and isearch-regexp-lax-whitespace regexp-flag) - #'re-search-forward-lax-whitespace - replace-re-search-function)) + (replace-lax-whitespace + (and search-whitespace-regexp + (if isearch-regexp + isearch-regexp-lax-whitespace + isearch-lax-whitespace))) ;; Set `isearch-recursive-edit' to nil to prevent calling ;; `exit-recursive-edit' in `isearch-done' that terminates ;; the execution of this command when it is non-nil. @@ -2956,6 +3045,10 @@ (defun isearch-lazy-highlight-search () (isearch-regexp isearch-lazy-highlight-regexp) (isearch-word isearch-lazy-highlight-word) (search-invisible nil) ; don't match invisible text + (isearch-lax-whitespace + isearch-lazy-highlight-lax-whitespace) + (isearch-regexp-lax-whitespace + isearch-lazy-highlight-regexp-lax-whitespace) (retry t) (success nil) (isearch-forward isearch-lazy-highlight-forward)