From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#45617: loses the edit region. Works in 23.3, broke in 26.3 Date: Mon, 04 Jan 2021 19:37:28 +0200 Organization: LINKOV.NET Message-ID: <87ble4ob6v.fsf@mail.linkov.net> References: <000001d6e16c$984bcb70$c8e36250$@net> <83turycc18.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32021"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: Bob Floyd , 45617@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 04 19:14:00 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwUMi-0008CA-6V for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 04 Jan 2021 19:14:00 +0100 Original-Received: from localhost ([::1]:54860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kwUMh-0008A8-5S for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 04 Jan 2021 13:13:59 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwUHv-0002mw-Rl for bug-gnu-emacs@gnu.org; Mon, 04 Jan 2021 13:09:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kwUHv-0003Zq-KC for bug-gnu-emacs@gnu.org; Mon, 04 Jan 2021 13:09:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kwUHv-0005EV-GC for bug-gnu-emacs@gnu.org; Mon, 04 Jan 2021 13:09: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: Mon, 04 Jan 2021 18:09:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45617 X-GNU-PR-Package: emacs Original-Received: via spool by 45617-submit@debbugs.gnu.org id=B45617.160978372520038 (code B ref 45617); Mon, 04 Jan 2021 18:09:03 +0000 Original-Received: (at 45617) by debbugs.gnu.org; 4 Jan 2021 18:08:45 +0000 Original-Received: from localhost ([127.0.0.1]:60232 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwUHc-0005D7-Tj for submit@debbugs.gnu.org; Mon, 04 Jan 2021 13:08:45 -0500 Original-Received: from relay4-d.mail.gandi.net ([217.70.183.196]:43833) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwUHa-0005CR-Rg for 45617@debbugs.gnu.org; Mon, 04 Jan 2021 13:08:43 -0500 X-Originating-IP: 91.129.98.64 Original-Received: from mail.gandi.net (m91-129-98-64.cust.tele2.ee [91.129.98.64]) (Authenticated sender: juri@linkov.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 364EFE0003; Mon, 4 Jan 2021 18:08:34 +0000 (UTC) In-Reply-To: <83turycc18.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 03 Jan 2021 16:47:47 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:197325 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit >> 7. Nothing happens because the region in step (1) has been lost. >> It should ask to replace 4 ‘_xx’s in the region. > > I suspect this is due to changes in how selection works in Emacs. > Those changes were made in Emacs 24; please see the section "Selection > changes" in the file etc/NEWS.24, where you will also find > instructions for getting back the old behavior. I tried to fix this problem by this patch, and indeed it fixed it, so the region boundaries are preserved even when changed during the minibuffer reading the strings: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=query-replace-region.patch diff --git a/lisp/replace.el b/lisp/replace.el index 9765b2b5be..c5acf8fca7 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -395,7 +395,10 @@ query-replace To customize possible responses, change the bindings in `query-replace-map'." (interactive - (let ((common + (let ((start (if (use-region-p) (region-beginning))) + (end (if (use-region-p) (region-end))) + (region-noncontiguous-p (if (use-region-p) (region-noncontiguous-p))) + (common (query-replace-read-args (concat "Query replace" (if current-prefix-arg @@ -407,10 +410,7 @@ query-replace ;; These are done separately here ;; so that command-history will record these expressions ;; rather than the values they had this time. - (if (use-region-p) (region-beginning)) - (if (use-region-p) (region-end)) - (nth 3 common) - (if (use-region-p) (region-noncontiguous-p))))) + start end (nth 3 common) region-noncontiguous-p))) (perform-replace from-string to-string t nil delimited nil nil start end backward region-noncontiguous-p)) (define-key esc-map "%" 'query-replace) --=-=-= Content-Type: text/plain But then I noticed this comment in 'query-replace': ;; These are done separately here ;; so that command-history will record these expressions ;; rather than the values they had this time. And indeed this patch broke this feature, so region boundaries are saved as numbers in command-history for repeat-complex-command instead of such code: C-x M-: (query-replace "a" "z" nil (if (use-region-p) (region-beginning)) (if (use-region-p) (region-end)) nil nil) But anyway this feature was broken by design and never worked: with a compiled replace.el it saves region boundaries as numbers, and only when 'query-replace' is manually evaluated with 'eval-defun', only then region boundaries are saved as code to command-history. So we could just delete 'fix_command' from callint.c, and don't worry about such cases. --=-=-=--