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#19829: 25.0.50; query-replace in rectangle regions do not honor boundaries Date: Fri, 13 Feb 2015 02:54:55 +0200 Organization: LINKOV.NET Message-ID: <87zj8iljfk.fsf@mail.linkov.net> References: <87r3txhkz1.fsf@ceis-strat.com> <87twyt5o8q.fsf@mail.linkov.net> <874mqsq6ar.fsf@mail.linkov.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1423789227 10395 80.91.229.3 (13 Feb 2015 01:00:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 13 Feb 2015 01:00:27 +0000 (UTC) Cc: Bastien , 19829@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Feb 13 02:00:14 2015 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 1YM4c7-0006df-70 for geb-bug-gnu-emacs@m.gmane.org; Fri, 13 Feb 2015 02:00:11 +0100 Original-Received: from localhost ([::1]:52829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YM4c6-0001Xp-J7 for geb-bug-gnu-emacs@m.gmane.org; Thu, 12 Feb 2015 20:00:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YM4c2-0001V8-Vr for bug-gnu-emacs@gnu.org; Thu, 12 Feb 2015 20:00:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YM4bz-0008J0-PE for bug-gnu-emacs@gnu.org; Thu, 12 Feb 2015 20:00:06 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49852) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YM4bz-0008Hg-Lx for bug-gnu-emacs@gnu.org; Thu, 12 Feb 2015 20:00:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YM4bz-00007X-1b for bug-gnu-emacs@gnu.org; Thu, 12 Feb 2015 20:00:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Feb 2015 01:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19829 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 19829-submit@debbugs.gnu.org id=B19829.1423789156379 (code B ref 19829); Fri, 13 Feb 2015 01:00:02 +0000 Original-Received: (at 19829) by debbugs.gnu.org; 13 Feb 2015 00:59:16 +0000 Original-Received: from localhost ([127.0.0.1]:41092 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YM4bD-000062-GN for submit@debbugs.gnu.org; Thu, 12 Feb 2015 19:59:15 -0500 Original-Received: from ps18281.dreamhost.com ([69.163.222.226]:56086 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YM4b9-00005s-SS for 19829@debbugs.gnu.org; Thu, 12 Feb 2015 19:59:13 -0500 Original-Received: from localhost.linkov.net (ps18281.dreamhostps.com [69.163.222.226]) by ps18281.dreamhostps.com (Postfix) with ESMTP id E572B378E0091C; Thu, 12 Feb 2015 16:59:08 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Thu, 12 Feb 2015 09:33:29 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x 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:99277 Archived-At: >> I wonder how do other commands that accept region-beginning/end >> process the rectangular region? > > Well, there's the source code to help you find out, of course. > More seriously, the rectangle support (can be rect.el or cua-rect.el) > code sets up `region-extract-function' and commands that need to operate > on the region should then call `region-extract-function' instead of > relying on region-beginning/end. > > Obviously, this infrastructure is not sufficient for query-replace, so > we'll need to add a `region-map-function` or something like that. Better would be to add a function that will return a list of positions of the rectangular region, i.e. while currently for the contiguous region region-beginning/end returns its bounds, for non-contiguous rectangular regions we need a list of column bounds. As a proof of concept, this small patch implements the feature of query-replace in rectangular regions, but I'm not sure how its parts should be refactored into a more general function such as e.g. `region-positions-extract-function' that will return a list of region positions. diff --git a/lisp/replace.el b/lisp/replace.el index e0636e0..8eeeb1a 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2089,6 +2089,7 @@ (defun perform-replace (from-string replacements ;; If non-nil, it is marker saying where in the buffer to stop. (limit nil) + (rectangular-region-positions nil) ;; Data for the next match. If a cons, it has the same format as ;; (match-data); otherwise it is t if a match is possible at point. @@ -2101,6 +2102,27 @@ (defun perform-replace (from-string replacements "Query replacing %s with %s: (\\\\[help] for help) ") minibuffer-prompt-properties)))) + (when rectangle-mark-mode + (let ((positions (list nil))) + (apply-on-rectangle + (lambda (startcol endcol positions) + (setcdr positions (cons (cons + (progn (move-to-column startcol) (point)) + (progn (move-to-column endcol) (point))) + (cdr positions)))) + (region-beginning) (region-end) positions) + (setq rectangular-region-positions (nreverse (cdr positions))) + (add-function :after-while (local 'isearch-filter-predicate) + (lambda (start end) + (delq nil (mapcar + (lambda (positions) + (and + (>= start (car positions)) + (<= start (cdr positions)) + (>= end (car positions)) + (<= end (cdr positions)))) + rectangular-region-positions)))))) + ;; If region is active, in Transient Mark mode, operate on region. (if backward (when end