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#13178: Query-replace fails soon after narrow-to-region Date: Mon, 02 Mar 2015 22:14:17 +0200 Organization: LINKOV.NET Message-ID: <87ioejw412.fsf@mail.linkov.net> References: <20121214.130320.1173151390202861752.teika@lavabit.com> <20150227.171230.1758903055908506043.teika@gmx.com> <4c17eddd-79fb-4939-98d2-5f929e5f1c7c@default> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1425327443 3666 80.91.229.3 (2 Mar 2015 20:17:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 2 Mar 2015 20:17:23 +0000 (UTC) Cc: Teika Kazura , 13178@debbugs.gnu.org, Artur Malabarba To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Mar 02 21:17:13 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 1YSWm8-0000xm-OU for geb-bug-gnu-emacs@m.gmane.org; Mon, 02 Mar 2015 21:17:13 +0100 Original-Received: from localhost ([::1]:59452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSWm8-00030c-1S for geb-bug-gnu-emacs@m.gmane.org; Mon, 02 Mar 2015 15:17:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSWm3-0002vy-Hm for bug-gnu-emacs@gnu.org; Mon, 02 Mar 2015 15:17:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YSWly-0000yV-HL for bug-gnu-emacs@gnu.org; Mon, 02 Mar 2015 15:17:07 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:34601) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSWly-0000yB-Ej for bug-gnu-emacs@gnu.org; Mon, 02 Mar 2015 15:17:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YSWlx-0006qW-PU for bug-gnu-emacs@gnu.org; Mon, 02 Mar 2015 15:17:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 02 Mar 2015 20:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13178 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 13178-submit@debbugs.gnu.org id=B13178.142532739026271 (code B ref 13178); Mon, 02 Mar 2015 20:17:01 +0000 Original-Received: (at 13178) by debbugs.gnu.org; 2 Mar 2015 20:16:30 +0000 Original-Received: from localhost ([127.0.0.1]:33169 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YSWlS-0006pe-29 for submit@debbugs.gnu.org; Mon, 02 Mar 2015 15:16:30 -0500 Original-Received: from ps18281.dreamhost.com ([69.163.222.226]:60978 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YSWlO-0006pS-Dw for 13178@debbugs.gnu.org; Mon, 02 Mar 2015 15:16:28 -0500 Original-Received: from localhost.linkov.net (ps18281.dreamhostps.com [69.163.222.226]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 3024F395209B82; Mon, 2 Mar 2015 12:16:23 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Mon, 02 Mar 2015 12:23:40 -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:99992 Archived-At: >> Perhaps the "replace" family of commands ought to ignore the region if it's >> empty? > > It should obey use-empty-active-region. This patch allows query-replace commands to obey use-empty-active-region: diff --git a/lisp/replace.el b/lisp/replace.el index e0636e0..8b62b54 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -312,15 +312,15 @@ (defun query-replace (from-string to-string &optional delimited start end backwa (if current-prefix-arg (if (eq current-prefix-arg '-) " backward" " word") "") - (if (and transient-mark-mode mark-active) " in region" "")) + (if (use-region-p) " in region" "")) nil))) (list (nth 0 common) (nth 1 common) (nth 2 common) ;; These are done separately here ;; so that command-history will record these expressions ;; rather than the values they had this time. - (if (and transient-mark-mode mark-active) + (if (use-region-p) (region-beginning)) - (if (and transient-mark-mode mark-active) + (if (use-region-p) (region-end)) (nth 3 common)))) (perform-replace from-string to-string t nil delimited nil nil start end backward)) @@ -392,15 +392,15 @@ (defun query-replace-regexp (regexp to-string &optional delimited start end back (if (eq current-prefix-arg '-) " backward" " word") "") " regexp" - (if (and transient-mark-mode mark-active) " in region" "")) + (if (use-region-p) " in region" "")) t))) (list (nth 0 common) (nth 1 common) (nth 2 common) ;; These are done separately here ;; so that command-history will record these expressions ;; rather than the values they had this time. - (if (and transient-mark-mode mark-active) + (if (use-region-p) (region-beginning)) - (if (and transient-mark-mode mark-active) + (if (use-region-p) (region-end)) (nth 3 common)))) (perform-replace regexp to-string t t delimited nil nil start end backward)) @@ -469,9 +469,9 @@ (defun query-replace-regexp-eval (regexp to-expr &optional delimited start end) ;; and the user might enter a single token. (replace-match-string-symbols to) (list from (car to) current-prefix-arg - (if (and transient-mark-mode mark-active) + (if (use-region-p) (region-beginning)) - (if (and transient-mark-mode mark-active) + (if (use-region-p) (region-end)))))) (perform-replace regexp (cons 'replace-eval-replacement to-expr) t 'literal delimited nil nil start end)) @@ -507,9 +507,9 @@ (defun map-query-replace-regexp (regexp to-strings &optional n start end) (list from to (and current-prefix-arg (prefix-numeric-value current-prefix-arg)) - (if (and transient-mark-mode mark-active) + (if (use-region-p) (region-beginning)) - (if (and transient-mark-mode mark-active) + (if (use-region-p) (region-end))))) (let (replacements) (if (listp to-strings) @@ -571,12 +571,12 @@ (defun replace-string (from-string to-string &optional delimited start end backw (if (eq current-prefix-arg '-) " backward" " word") "") " string" - (if (and transient-mark-mode mark-active) " in region" "")) + (if (use-region-p) " in region" "")) nil))) (list (nth 0 common) (nth 1 common) (nth 2 common) - (if (and transient-mark-mode mark-active) + (if (use-region-p) (region-beginning)) - (if (and transient-mark-mode mark-active) + (if (use-region-p) (region-end)) (nth 3 common)))) (perform-replace from-string to-string nil nil delimited nil nil start end backward)) @@ -645,12 +645,12 @@ (defun replace-regexp (regexp to-string &optional delimited start end backward) (if (eq current-prefix-arg '-) " backward" " word") "") " regexp" - (if (and transient-mark-mode mark-active) " in region" "")) + (if (use-region-p) " in region" "")) t))) (list (nth 0 common) (nth 1 common) (nth 2 common) - (if (and transient-mark-mode mark-active) + (if (use-region-p) (region-beginning)) - (if (and transient-mark-mode mark-active) + (if (use-region-p) (region-end)) (nth 3 common)))) (perform-replace regexp to-string nil t delimited nil nil start end backward)) @@ -816,7 +816,7 @@ (defun keep-lines (regexp &optional rstart rend interactive) (unless (or (bolp) (eobp)) (forward-line 0)) (point-marker))))) - (if (and interactive transient-mark-mode mark-active) + (if (and interactive (use-region-p)) (setq rstart (region-beginning) rend (progn (goto-char (region-end)) @@ -885,7 +885,7 @@ (defun flush-lines (regexp &optional rstart rend interactive) (progn (goto-char (min rstart rend)) (setq rend (copy-marker (max rstart rend)))) - (if (and interactive transient-mark-mode mark-active) + (if (and interactive (use-region-p)) (setq rstart (region-beginning) rend (copy-marker (region-end))) (setq rstart (point) @@ -935,7 +935,7 @@ (defun how-many (regexp &optional rstart rend interactive) (setq rend (max rstart rend))) (goto-char rstart) (setq rend (point-max))) - (if (and interactive transient-mark-mode mark-active) + (if (and interactive (use-region-p)) (setq rstart (region-beginning) rend (region-end)) (setq rstart (point)