From unknown Sun Jun 22 11:30:53 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#31492 <31492@debbugs.gnu.org> To: bug#31492 <31492@debbugs.gnu.org> Subject: Status: 26.1; query-replace-regexp undo fails in regexps w/o printable chars Reply-To: bug#31492 <31492@debbugs.gnu.org> Date: Sun, 22 Jun 2025 18:30:53 +0000 retitle 31492 26.1; query-replace-regexp undo fails in regexps w/o printabl= e chars reassign 31492 emacs submitter 31492 Tino Calancha severity 31492 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Fri May 18 09:28:00 2018 Received: (at submit) by debbugs.gnu.org; 18 May 2018 13:28:00 +0000 Received: from localhost ([127.0.0.1]:39309 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJfQN-0002Ey-Lb for submit@debbugs.gnu.org; Fri, 18 May 2018 09:27:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41966) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJfQL-0002Ek-CQ for submit@debbugs.gnu.org; Fri, 18 May 2018 09:27:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJfQF-0001Jg-1m for submit@debbugs.gnu.org; Fri, 18 May 2018 09:27:52 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_20,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:58270) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fJfQE-0001JS-Qt for submit@debbugs.gnu.org; Fri, 18 May 2018 09:27:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32924) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJfQD-0005qO-CU for bug-gnu-emacs@gnu.org; Fri, 18 May 2018 09:27:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJfQ9-0001Gq-6h for bug-gnu-emacs@gnu.org; Fri, 18 May 2018 09:27:49 -0400 Received: from mail-pg0-x22e.google.com ([2607:f8b0:400e:c05::22e]:43528) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fJfQ9-0001GL-0Z for bug-gnu-emacs@gnu.org; Fri, 18 May 2018 09:27:45 -0400 Received: by mail-pg0-x22e.google.com with SMTP id p8-v6so3326705pgq.10 for ; Fri, 18 May 2018 06:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=E+seKEQ0BO2xO2bm5nSNn/Am44kYYeDywkIg6PLbWJM=; b=hebck9RkoVhmoyIACKSPtAJSkcQFnSK1l27vZyj+eGauhj1d/WRFSnCzGDcLsbOlWV k3Ziw8NO2raD1EIUHDIni4sYTaMRp5jpdXzFEdnhXAYWALhsg6JLUaQsAMrQhgQ+tlv7 8nIjfrs65OZXbGQvGNvlxDB/WRcOLZJNzSs4C6Bg4ShJ3pYddYouYFrKVMalRhTNwLYq xcqxGK08y7wulR088yzuWyi29kjuAKklJmIqYPb2i1YmSFLRGRWr4a0VY+JgCMieS5VL 98rJQTqBAkg7Yb+3wvO/0JUE1JDMzP82qdNhG0hAR+xm98P5/9O56nApQgD7b+1+dw8n Utkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=E+seKEQ0BO2xO2bm5nSNn/Am44kYYeDywkIg6PLbWJM=; b=umpp90W/RIEkb8GBkObuJrcr0WLTHup7aLhsiOFm+gdaII+hRdr/J8UpRjeStnwmYO LFAlucLUFDiEYnAL8WamoW/zs8V4PNz7cLjlZ/ApcS6fh4SxrYfUCDnPr5YhqFoFSt3m ARyu2d+EuD6tZg4eAXj2fqB/gvcovie1+W2DGtJ2jD2PD9hdAAGQqwacGw9JARdOWTvE 7Yj9uoHQfMM9tVnO3UP440o9YuLQG+pnxTwKgWwQFu3gxUvDmqMiCvC2sqk5m3MTeioO kiceKAWBym0N32yRfxFmn1ewxDIS6NDA60sdPj53L8Cg99MsmsfPp5xtheUYycMVQRip 6kzw== X-Gm-Message-State: ALKqPwfR8orPwnGpGK3JvOu4SeYJ+StQVcHRE/oetI6Zz6ekDScJoEQd aPgA3eAPfkfdP7LdVYKMQQRBdA== X-Google-Smtp-Source: AB8JxZrzweGgye0IXHo0zk+uMUSGo0Q9JjI69lWI56JAWcuu5uj55gMx6Dd16BvfraZkoc0SMHM6eA== X-Received: by 2002:a65:6581:: with SMTP id u1-v6mr7433402pgv.396.1526650063492; Fri, 18 May 2018 06:27:43 -0700 (PDT) Received: from calancha-pc (228.225.128.101.dy.bbexcite.jp. [101.128.225.228]) by smtp.gmail.com with ESMTPSA id o70-v6sm13238652pfo.49.2018.05.18.06.27.41 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 May 2018 06:27:42 -0700 (PDT) From: Tino Calancha To: bug-gnu-emacs@gnu.org Subject: 26.1; query-replace-regexp undo fails in regexps w/o printable chars Date: Fri, 18 May 2018 22:27:36 +0900 Message-ID: <8736yp14c7.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) emacs -Q < C-M-% \b RET foo RET TAB TAB TAB U ; undo all replacements ;; Nothing is undid :-( --8<-----------------------------cut here---------------start------------->8--- commit f1ee02d0c0bef4534c895559eb53b1ac0ecfb752 Author: Tino Calancha Date: Fri May 18 22:19:18 2018 +0900 Fix corner case in query-replace-regexp undo * lisp/replace.el (perform-replace): Handle the case of a regexp not having printable characters (Bug#31492). * test/lisp/replace-tests.el (query-replace-undo-bug31492): Add test. diff --git a/lisp/replace.el b/lisp/replace.el index 3503b656d9..526a40d230 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2692,7 +2692,9 @@ perform-replace (setq real-match-data (save-excursion (goto-char (match-beginning 0)) - (looking-at search-string) + (if (/= (match-beginning 0) (match-end 0)) + (looking-at search-string) + (looking-back search-string (- (point) (length search-string)))) (match-data t (nth 2 elt))) noedit (replace-match-maybe-edit diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el index 40a1a31cf7..5c0ec2aa1c 100644 --- a/test/lisp/replace-tests.el +++ b/test/lisp/replace-tests.el @@ -399,5 +399,25 @@ replace-tests--query-replace-undo ;; After undo text must be the same. (should (string= text (buffer-string)))))) +(ert-deftest query-replace-undo-bug31492 () + "Test for https://debbugs.gnu.org/31492 ." + (let ((text "a\nb\nc\n") + (count 0) + (inhibit-message t)) + (with-temp-buffer + (insert text) + (goto-char 1) + (cl-letf (((symbol-function 'read-event) + (lambda (&rest args) + (cl-incf count) + (let ((val (pcase count + ((or 1 2) ?\s) ; replace current and go next + (3 ?U) ; undo-all + (_ ?q)))) ; exit + val)))) + (perform-replace "^\\|\b\\|$" "foo" t t nil)) + ;; After undo text must be the same. + (should (string= text (buffer-string)))))) + ;;; replace-tests.el ends here --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.1 (build 6, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2018-05-18 built on calancha-pc Repository revision: 73bc6f8693fcbb98b41ee67ab35a4dd8c3940355 From debbugs-submit-bounces@debbugs.gnu.org Fri May 18 10:16:19 2018 Received: (at 31492) by debbugs.gnu.org; 18 May 2018 14:16:19 +0000 Received: from localhost ([127.0.0.1]:39899 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJgB9-0003SE-DD for submit@debbugs.gnu.org; Fri, 18 May 2018 10:16:19 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53887) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJgB7-0003S0-0M for 31492@debbugs.gnu.org; Fri, 18 May 2018 10:16:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJgAx-00026z-Mf for 31492@debbugs.gnu.org; Fri, 18 May 2018 10:16:11 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05 autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:53338) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJgAx-00026p-IX; Fri, 18 May 2018 10:16:07 -0400 Received: from [176.228.60.248] (port=4681 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fJgAw-0000NN-2i; Fri, 18 May 2018 10:16:06 -0400 Date: Fri, 18 May 2018 17:16:01 +0300 Message-Id: <838t8hhwwu.fsf@gnu.org> From: Eli Zaretskii To: Tino Calancha In-reply-to: <8736yp14c7.fsf@gmail.com> (message from Tino Calancha on Fri, 18 May 2018 22:27:36 +0900) Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars References: <8736yp14c7.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) > From: Tino Calancha > Date: Fri, 18 May 2018 22:27:36 +0900 > > emacs -Q > > < C-M-% \b RET foo RET TAB TAB TAB > U ; undo all replacements > ;; Nothing is undid :-( I'm probably missing something, because I cannot reproduce the problem (and therefore don't understand the solution). When I repeat what you show above, I get "replaced 0 occurrences", and therefore there's nothing to undo in the first place... I guess the explanation is in what does "<" mean and, more importantly, what did you actually type instead of "\b". Or maybe some command is missing before the recipe begins? TIA From debbugs-submit-bounces@debbugs.gnu.org Fri May 18 10:22:24 2018 Received: (at 31492) by debbugs.gnu.org; 18 May 2018 14:22:24 +0000 Received: from localhost ([127.0.0.1]:39906 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJgH2-0003aq-BS for submit@debbugs.gnu.org; Fri, 18 May 2018 10:22:24 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:44631) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJgH1-0003ae-DK for 31492@debbugs.gnu.org; Fri, 18 May 2018 10:22:23 -0400 Received: by mail-pf0-f169.google.com with SMTP id q22-v6so3833770pff.11 for <31492@debbugs.gnu.org>; Fri, 18 May 2018 07:22:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=G+FJ4KPf69fnTcjfh7OVY3dGj/o9hRsghtGj27tMyNc=; b=jW585hKcodQMKTxuloQo30p5c7m7QADY/vlRbWEjK3uDHkWLMaTG6Fs92+8VUiKUJr qeKKrU2Ulr9BocESnv9ZwEw340oaTRrVh58Wn9J3ZYA3SW+eoxMjHDJXlRBH2k5zcKBf mo1mFtPdZIoVOqN/5BfDkGdAAVf2eeIw1DvjjQcTu2rywiTIohrzFpcb3WTdEyISTLYB K+MyqnGidSuRMcvQF5Nt24MjsRYbCVuHK3sGx+IarIRqnE424M4O6XHYXUgVJnhBgBoH WE8jpxPZKeJBPsz5ui+tScwOIt0ZUwMvYrfbgxotrP3IkN9b2UY75lWxKTfzKE9XfjEB nurg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=G+FJ4KPf69fnTcjfh7OVY3dGj/o9hRsghtGj27tMyNc=; b=XbmohKP+5yFzeHrCZLb3UwnZy4wymrrUdpO6mHAJxhsbIcbNeedyAXXqkGzy6yd1+v OijSX6/4L8ny4+lcd6Sc3S2W8CCKcvrdOkhntF9xFepBfrtqNhc9L/9R1/WEg3lLCIgB 1Dc4GbZhg5odpfM3Zt1zlUD1UNyUKawOG4SRpzYg2aw7dhpeaNNaAdoxPMc6/Jaos6cP veTAqJhXrykKitnu/6FiU6NkSkVgjh3iNV+i7UPqPeLzHvfIOLM9b0XigI8hJf8DK7zf Sxy5u3CkH8sJxYjDSJucWB+HY5j7mVHRk9/SIdZyoI6xSV9YSdaTSymfA92hrIEldtPV pUuA== X-Gm-Message-State: ALKqPwda3Kc/bGfpUWP34d2kmEkpl4NliTY+Ck01+5QQZtl9qPMyGt+Z ABx24eWTJMnZd8Y/PGC3xtA= X-Google-Smtp-Source: AB8JxZp/ptVfbuBe1aT2sMKU8spg8Hjcqxk8ggWNjpJw8k1AIDfYyX3cr5SeL5Qgct3iQoH6JMQJfQ== X-Received: by 2002:a65:66d7:: with SMTP id c23-v6mr2805908pgw.76.1526653337480; Fri, 18 May 2018 07:22:17 -0700 (PDT) Received: from calancha-pc (228.225.128.101.dy.bbexcite.jp. [101.128.225.228]) by smtp.gmail.com with ESMTPSA id f9-v6sm10436382pgq.24.2018.05.18.07.22.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 07:22:16 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Fri, 18 May 2018 23:22:13 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Eli Zaretskii Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars In-Reply-To: <838t8hhwwu.fsf@gnu.org> Message-ID: References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -0.6 (/) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.6 (-) On Fri, 18 May 2018, Eli Zaretskii wrote: >> From: Tino Calancha >> Date: Fri, 18 May 2018 22:27:36 +0900 >> >> emacs -Q >> >> < C-M-% \b RET foo RET TAB TAB TAB >> U ; undo all replacements >> ;; Nothing is undid :-( > > I'm probably missing something, because I cannot reproduce the problem > I guess the explanation is in what does "<" mean and, more '<' stands for `beginning-of-buffer'. Then you have text to replace in the *scratch* buffer. Otherwise you at the end of the buffer and my regexp cannot match. From debbugs-submit-bounces@debbugs.gnu.org Fri May 18 11:07:30 2018 Received: (at 31492) by debbugs.gnu.org; 18 May 2018 15:07:30 +0000 Received: from localhost ([127.0.0.1]:39926 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJgye-0004cP-Fj for submit@debbugs.gnu.org; Fri, 18 May 2018 11:07:29 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40005) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJgyd-0004cD-4F for 31492@debbugs.gnu.org; Fri, 18 May 2018 11:07:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJgyU-0006U6-Sn for 31492@debbugs.gnu.org; Fri, 18 May 2018 11:07:22 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:54479) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJgyU-0006U2-Oe; Fri, 18 May 2018 11:07:18 -0400 Received: from [176.228.60.248] (port=4725 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fJgyT-0002tq-SP; Fri, 18 May 2018 11:07:18 -0400 Date: Fri, 18 May 2018 18:07:13 +0300 Message-Id: <837eo1huji.fsf@gnu.org> From: Eli Zaretskii To: Tino Calancha In-reply-to: (message from Tino Calancha on Fri, 18 May 2018 23:22:13 +0900 (JST)) Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) > From: Tino Calancha > Date: Fri, 18 May 2018 23:22:13 +0900 (JST) > cc: Tino Calancha , 31492@debbugs.gnu.org > > >> emacs -Q > >> > >> < C-M-% \b RET foo RET TAB TAB TAB > >> U ; undo all replacements > >> ;; Nothing is undid :-( > > > > I'm probably missing something, because I cannot reproduce the problem > > I guess the explanation is in what does "<" mean and, more > '<' stands for `beginning-of-buffer'. Then you have text to replace in > the *scratch* buffer. Otherwise you at the end of the buffer and my > regexp cannot match. Sorry, I'm still in the dark. After "emacs -Q", the current buffer is *scratch*, and in that buffer, typing '<' inserts that character into the buffer, it doesn't invoke beginning-of-buffer. And 'U' doesn't undo, either. These are self-inserting characters in Lisp Interaction mode. What am I missing? From debbugs-submit-bounces@debbugs.gnu.org Fri May 18 21:46:22 2018 Received: (at 31492) by debbugs.gnu.org; 19 May 2018 01:46:22 +0000 Received: from localhost ([127.0.0.1]:40336 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJqww-0004K7-FC for submit@debbugs.gnu.org; Fri, 18 May 2018 21:46:22 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:41496) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJqwu-0004Jr-Fn for 31492@debbugs.gnu.org; Fri, 18 May 2018 21:46:20 -0400 Received: by mail-pf0-f181.google.com with SMTP id v63-v6so4531424pfk.8 for <31492@debbugs.gnu.org>; Fri, 18 May 2018 18:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=i5O8Dy61vVjqs7QADCn3/86yiMpfm5KQNvlQTC1q6NM=; b=bbGqRyc8+m9HQksUig4jkMRgWM0hAADy5cVgpZ2q1RG6E9FR+TZeNW6E0fXAOUt2H7 yQw6JprduDhSfCirdZBm1LbWD+LjvJj1j2h3uyIwlAfULwo+S5wDCq3QsqyC93eCtZ0X 4ghCavlB41w8Ct8CAVbccOIp0xKyHfDgNwcEimr5KhB1NnDZ7azKjzaJGaoN1IwMbv8Q 70RPP/gZG6txs+QMKsbr16RjL2FlxT6AjnzBtz9m8KOyp6Yt0O1fd5a/bVLgTYP0aWpu /Sy+qeJj3STtMak4ngplZMhEE3OMs2/8e8W/Rg/T2bpruL4+NdRYtvyVoF33kRAXFkGf VLTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=i5O8Dy61vVjqs7QADCn3/86yiMpfm5KQNvlQTC1q6NM=; b=VM+qsfdMK218c1cXyX2YITT5dIRIlb+hdvGE6o5nAV6nuZyBpUVlCZvPLx94NVGIAT lUHY+fOancXN70MBJt4vxcILS+waGqYwVS59dp6sYApLubUsQsN9hjyUva4mz63KfFJm 4Atp/c8tdjtogOvPP3LnRk+e0YXukPphwp+zTGx3qpvSHMXoeeyrX1s1drRmEpMqEZgh z1xG3QIxK3C+GanpRKXo77FH5vTJGl+dk4P0H1wr9sps6/wCb2cWYsc9wQJGj0Dlvxo3 ZZUpCjN37VRVr0+aqsGPVkxzeQk2LHjY/9r95mFKKwCxpl9xakptxZxwoHXeTLaw0xvV 4szA== X-Gm-Message-State: ALKqPwcpifvC+6sXTeZ+oawFrdab8mXhBhotniVlY72Uno/OoI5sFPOW fzLNh2lpJe+neo4aJnx2gEg= X-Google-Smtp-Source: AB8JxZreSzbSGoFd07hs/iEf+h+jmikjcSi+wwp+23wPQZfD0njQcSZRkbU2Ra5b5FobJmsgv/KtVg== X-Received: by 2002:a63:7b1d:: with SMTP id w29-v6mr9284191pgc.417.1526694374376; Fri, 18 May 2018 18:46:14 -0700 (PDT) Received: from calancha-pc (228.225.128.101.dy.bbexcite.jp. [101.128.225.228]) by smtp.gmail.com with ESMTPSA id u68-v6sm14694532pfu.32.2018.05.18.18.46.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 18:46:13 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Sat, 19 May 2018 10:46:10 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Eli Zaretskii Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars In-Reply-To: <837eo1huji.fsf@gnu.org> Message-ID: References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On Fri, 18 May 2018, Eli Zaretskii wrote: >> From: Tino Calancha >> Date: Fri, 18 May 2018 23:22:13 +0900 (JST) >> cc: Tino Calancha , 31492@debbugs.gnu.org >> >>>> emacs -Q >>>> >>>> < C-M-% \b RET foo RET TAB TAB TAB >>>> U ; undo all replacements >>>> ;; Nothing is undid :-( >>> >> '<' stands for `beginning-of-buffer'. > Sorry, I'm still in the dark. Typing '<' inserts that character Opps... Sorry! That should read 'M-<'. And the TAB's should read SPC. The correct recipe is: M-< C-M-% \b RET foo RET SPC SPC U ;; All 'foo' keep there :-( This happen because the regexp "\b" has any printable character. If we try instead: M-< C-M-% is\b RET foo RET SPC SPC U ;; Now all 'foo' are gone :-) From debbugs-submit-bounces@debbugs.gnu.org Sat May 19 03:50:43 2018 Received: (at 31492) by debbugs.gnu.org; 19 May 2018 07:50:43 +0000 Received: from localhost ([127.0.0.1]:40435 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJwdW-0004C9-Tc for submit@debbugs.gnu.org; Sat, 19 May 2018 03:50:43 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43756) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJwdV-0004Bx-Eu for 31492@debbugs.gnu.org; Sat, 19 May 2018 03:50:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJwdN-0002K4-85 for 31492@debbugs.gnu.org; Sat, 19 May 2018 03:50:36 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_20 autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:42314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJwdM-0002Jz-Vq; Sat, 19 May 2018 03:50:33 -0400 Received: from [176.228.60.248] (port=1617 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fJwdM-0000Ih-B1; Sat, 19 May 2018 03:50:32 -0400 Date: Sat, 19 May 2018 10:50:30 +0300 Message-Id: <83zi0wgk3d.fsf@gnu.org> From: Eli Zaretskii To: Tino Calancha In-reply-to: (message from Tino Calancha on Sat, 19 May 2018 10:46:10 +0900 (JST)) Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) > From: Tino Calancha > Date: Sat, 19 May 2018 10:46:10 +0900 (JST) > cc: Tino Calancha , 31492@debbugs.gnu.org > > The correct recipe is: > > M-< > C-M-% \b RET foo RET SPC SPC > U > ;; All 'foo' keep there :-( Thanks, I see the problem now. However, isn't the root cause in replace--push-stack? The relevant element of the replacement stack (whose structure, btw, seems not to be documented anywhere), is (4 4 *scratch*), whereas I'd expect to see (1 4 *scratch) instead, because the replacement was at position 1; then setting match-data from this would DTRT. IOW, I'm afraid the looking-back solution is ad-hoc, and might not work in general, because the real problem is elsewhere. WDYT? > This happen because the regexp "\b" has any printable character. Why does it matter for \b to match a non-empty string? The undo-all command matches text against the _replacement_ string, not against the original search string. And the replacement string, "foo", is not empty. The problem here, AFAICT, is that we are looking for it in the wrong place, and that happens because the replacement stack tells us to look at position 4 instead of position 1. Right? > If we try instead: > > M-< > C-M-% is\b RET foo RET SPC SPC > U > ;; Now all 'foo' are gone :-) Yes, because in this case the replacement stack has the correct data. From debbugs-submit-bounces@debbugs.gnu.org Sat May 19 10:28:47 2018 Received: (at 31492) by debbugs.gnu.org; 19 May 2018 14:28:47 +0000 Received: from localhost ([127.0.0.1]:41150 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fK2ql-0000jZ-CX for submit@debbugs.gnu.org; Sat, 19 May 2018 10:28:47 -0400 Received: from mail-pl0-f44.google.com ([209.85.160.44]:40945) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fK2qk-0000jO-65 for 31492@debbugs.gnu.org; Sat, 19 May 2018 10:28:46 -0400 Received: by mail-pl0-f44.google.com with SMTP id t12-v6so6232201plo.7 for <31492@debbugs.gnu.org>; Sat, 19 May 2018 07:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=MbaGwwT1UHsNpr5fxK7vuW9Lm01luXhQ7ftnZXaQocw=; b=n2h4qxFna32RAfUsV7h4UsRxRlZ1ImsI3sCgu4EewhtdGGIyjKcxxp64uSemC7+EdZ fH4i0H8JvcUzguIun0NlKnwfkDENl1Ia5A1/IRYWxGe20OzsbEiRet+uUkYW0MkNW6/c 5l4FifRUj62culwg1usMYZrgpBRw3K/nJ3GygmrHfKr5EQyWJ96jNIVgB0iu1ZFt+bpG SMlt8ZxETq6zMxEwNF3KKhPAXIMKB6sfAApOn2FdRRAXQ+P3yCoQZTk6ixmC/zCHUDr7 uQnWWCVFWcZdcpfeLZRHhx1qCVvsORCBd7/tW4e14PBnLMRGkRrww/+R18QWXWOo5Tz5 NanA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=MbaGwwT1UHsNpr5fxK7vuW9Lm01luXhQ7ftnZXaQocw=; b=kezKqdpmGLS61I8ca9OAyOBnHnjI6r+ZJGnb4cZ2P+74RM34M1zwnw7qU4wrRx0Kmm icnxAulq33fmi+IJmtY37Hw/PPhiryWbPfnw4NWz9UNwSiFkMNLO0JlZQGeluQAPvy8e jtfRcnQVs6EOpachQ2I3GxbVNq1wT8EngbdrvRQC/6XILlHklIiiGJXGDFrd5kaPlDu9 f6lgBER3rj0eQlZza/vRZ7vtq43zgd8Upty+WDgF0zjcC7LaIcyqwZ2LUl3T3M12koYU TuTIOTRtOYdBou83enSUw/knb6LEMSeab4xta4dCl4g/HM4sJSApjTtEaFCfP2O9UC/5 Cxdg== X-Gm-Message-State: ALKqPwecOx7Q6X9SD9cpyxdfeesYd+koKNdK7bUjoWbmBnFozCXkOnH8 mPHJX4Sghjeb5QXB47YnJwwNzw== X-Google-Smtp-Source: AB8JxZrwv2J2kBIaDlk3jt1xpgUneKLt/VR0x9uoLouVtxuqogGbBiw5Vyretzaps186+AISmVbOrg== X-Received: by 2002:a17:902:8a95:: with SMTP id p21-v6mr13911840plo.325.1526740120224; Sat, 19 May 2018 07:28:40 -0700 (PDT) Received: from calancha-pc (228.225.128.101.dy.bbexcite.jp. [101.128.225.228]) by smtp.gmail.com with ESMTPSA id m11-v6sm12570433pgv.48.2018.05.19.07.28.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 19 May 2018 07:28:39 -0700 (PDT) From: Tino Calancha To: Eli Zaretskii Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> <83zi0wgk3d.fsf@gnu.org> Date: Sat, 19 May 2018 23:28:35 +0900 In-Reply-To: <83zi0wgk3d.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 19 May 2018 10:50:30 +0300") Message-ID: <87tvr3zpm4.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.6 (/) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.6 (-) Eli Zaretskii writes: > Thanks, I see the problem now. > > However, isn't the root cause in replace--push-stack? I am not sure; there is something else (see below). > The relevant > element of the replacement stack (whose structure, btw, seems not to > be documented anywhere), is (4 4 *scratch*), whereas I'd expect to see > (1 4 *scratch) instead, because the replacement was at position 1; > then setting match-data from this would DTRT. Yes, that is the logic. The thing is, for some unknown reason to me, the reported match-data is inexact when there are no printable chars in the regexp (maybe it's expected and I am wrong on my assumptions). > IOW, I'm afraid the looking-back solution is ad-hoc, and might not > work in general, because the real problem is elsewhere. WDYT? Look what happen in these examples: (with-temp-buffer (insert "foo") (goto-char 1) (progn (re-search-forward "o$" nil t) (save-match-data (replace-match "oZZZ")) (list (point) (match-beginning 0) (match-end 0)))) => (7 3 7) ;; Now, a regexp with no printable chars (with-temp-buffer (insert "foo") (goto-char 1) (progn (re-search-forward "$" nil t) (save-match-data (replace-match "ZZZ")) (list (point) (match-beginning 0) (match-end 0)))) => (7 7 7) ;; If this would be (7 4 7), then we could use `looking-at'; we are to ;; the right of the replacement, then we use `looking-back'. ;; But the match was at 4 not at 7 (with-temp-buffer (insert "foo") (goto-char 1) (progn (re-search-forward "$" nil t) (list (point) (match-beginning 0) (match-end 0)))) => (4 4 4) ;; We lost the information about the beginning of the match when ;; the regexps lack of printable characters. From debbugs-submit-bounces@debbugs.gnu.org Sun May 20 05:29:18 2018 Received: (at 31492) by debbugs.gnu.org; 20 May 2018 09:29:18 +0000 Received: from localhost ([127.0.0.1]:41628 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKKeT-0003jv-VC for submit@debbugs.gnu.org; Sun, 20 May 2018 05:29:18 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45236) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKKeS-0003jh-9N for 31492@debbugs.gnu.org; Sun, 20 May 2018 05:29:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKKeJ-00056C-Uj for 31492@debbugs.gnu.org; Sun, 20 May 2018 05:29:11 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05 autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:57314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKKeJ-000564-Qq; Sun, 20 May 2018 05:29:07 -0400 Received: from [176.228.60.248] (port=4218 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fKKeI-0006GH-85; Sun, 20 May 2018 05:29:06 -0400 Date: Sun, 20 May 2018 12:29:07 +0300 Message-Id: <83vabifzfg.fsf@gnu.org> From: Eli Zaretskii To: Tino Calancha In-reply-to: <87tvr3zpm4.fsf@gmail.com> (message from Tino Calancha on Sat, 19 May 2018 23:28:35 +0900) Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> <83zi0wgk3d.fsf@gnu.org> <87tvr3zpm4.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) > From: Tino Calancha > Cc: 31492@debbugs.gnu.org > Date: Sat, 19 May 2018 23:28:35 +0900 > > > The relevant > > element of the replacement stack (whose structure, btw, seems not to > > be documented anywhere), is (4 4 *scratch*), whereas I'd expect to see > > (1 4 *scratch) instead, because the replacement was at position 1; > > then setting match-data from this would DTRT. > Yes, that is the logic. The thing is, for some unknown reason to me, > the reported match-data is inexact when there are no printable chars > in the regexp (maybe it's expected and I am wrong on my assumptions). The reason for that is that match-data is recorded as markers, and so the positions move if text is inserted. In your example, the position of $ moved due to insertion, so the marker's position was updated as part of the replacement. > (with-temp-buffer > (insert "foo") > (goto-char 1) > (progn (re-search-forward "$" nil t) > (save-match-data (replace-match "ZZZ")) > (list (point) (match-beginning 0) (match-end 0)))) > => (7 7 7) > ;; If this would be (7 4 7), then we could use `looking-at'; we are to > ;; the right of the replacement, then we use `looking-back'. > > > ;; But the match was at 4 not at 7 > (with-temp-buffer > (insert "foo") > (goto-char 1) > (progn (re-search-forward "$" nil t) > (list (point) (match-beginning 0) (match-end 0)))) > => (4 4 4) Right, and so I submit that the problem is where the replacement stack is updated: it should account for these subtleties and adjust the stack positions accordingly, since it has the opportunity to look at the match position before the matched text is replaced. It is IMO suboptimal to make these adjustments where the stack is used, because you've lost the information about the actual match point, and you are deducing it using heuristics, which I'm not sure is 100% reliable. Thanks. From debbugs-submit-bounces@debbugs.gnu.org Sun May 20 07:51:26 2018 Received: (at 31492) by debbugs.gnu.org; 20 May 2018 11:51:26 +0000 Received: from localhost ([127.0.0.1]:41662 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKMs0-0000Zy-Rk for submit@debbugs.gnu.org; Sun, 20 May 2018 07:51:26 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:39938) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKMrz-0000Zm-Fx for 31492@debbugs.gnu.org; Sun, 20 May 2018 07:51:23 -0400 Received: by mail-pg0-f67.google.com with SMTP id l2-v6so5152340pgc.7 for <31492@debbugs.gnu.org>; Sun, 20 May 2018 04:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=y7PHizdnpNtCQWlbH5frQCF7JajnxnWm5NB07TpVXCQ=; b=ZqbBp6sRN6j+XH6eTLmyi1fK9ok3lqTe1htDb1XcSFqh5xAnDNApWyPLyMdLECTc4K 0N0K23dL4+naGQVwmJRq2+6rvGEYafS8exHO9OrSYTZcEn3Ur7nWuJR729nrqb0Jsgw+ 8xggfNUgGjtQLxaU94pNXY3yqlz05hSGkTYDXy9xk3RUFTn0KOfhMGqplkspXeBgN4Hu 9M18T7sq8/WUG3rN2yVsmlerzdMcVKZPFCYSfXpYtvW+2Dyluc6AcPQ0dPZ82pkCDsAe d7OpTxFenKtwbDGXCIcZDCNfJy/NffXch7lE+9UWu87TdepTLa/L7hrH8RYFiSr9owqv SHmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=y7PHizdnpNtCQWlbH5frQCF7JajnxnWm5NB07TpVXCQ=; b=IiwYIiy1biROKSl5rlci6JxdsdhqRbjrMXlM4BBDf7un9qtVEb7pKj/ByYoYvzkCQN HF1V/o0uT7xDKiGsPh1TRxBIHxGjy+rThzm42OH2RRY/1eqQ97WzQUNsHFPLcPrKErEE Cv5tcmraCwlLJLhRLCZ640SuWX62gkjcsSi6jXDN70QZI0D5TpdlwTiSr0nHfY5eVkZ8 nosC6vCAx8KHaNYLbQUwFQYCbgWbT4CRxfIF4L8q0xJaIa8khndbz9tLRZUDKSzWrByV bPNzAfI0K9m+rPIr4+mdgMLr04QGuyiW6oLMGooL3PeeI1RVZafw3EItqFnrxjyMKe8U MVfA== X-Gm-Message-State: ALKqPwdvMkZb5aCRHfmA84jnk0DbL5ng+zasspkFUHoqW6mMmI6nSUwM sGeEYrTFgEVn8WPXh4/UFjJV5A== X-Google-Smtp-Source: AB8JxZoyGmK83vDvQz21JlWtPogfs3sTahHmvQynT2CBIZzeTOvuHxP65Xkq33Vs3dYUOoVwju8nyg== X-Received: by 2002:a65:4945:: with SMTP id q5-v6mr10651987pgs.177.1526817077548; Sun, 20 May 2018 04:51:17 -0700 (PDT) Received: from calancha-pc (228.225.128.101.dy.bbexcite.jp. [101.128.225.228]) by smtp.gmail.com with ESMTPSA id v14-v6sm18662601pfn.105.2018.05.20.04.51.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 May 2018 04:51:16 -0700 (PDT) From: Tino Calancha To: Eli Zaretskii Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> <83zi0wgk3d.fsf@gnu.org> <87tvr3zpm4.fsf@gmail.com> <83vabifzfg.fsf@gnu.org> Date: Sun, 20 May 2018 20:51:10 +0900 In-Reply-To: <83vabifzfg.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 20 May 2018 12:29:07 +0300") Message-ID: <87sh6mwno1.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Eli Zaretskii writes: >> > The relevant >> > element of the replacement stack (whose structure, btw, seems not to >> > be documented anywhere), is (4 4 *scratch*), whereas I'd expect to see >> > (1 4 *scratch) instead, because the replacement was at position 1; >> > then setting match-data from this would DTRT. >> Yes, that is the logic. The thing is, for some unknown reason to me, >> the reported match-data is inexact when there are no printable chars >> in the regexp (maybe it's expected and I am wrong on my assumptions). > > The reason for that is that match-data is recorded as markers, and so > the positions move if text is inserted. In your example, the position > of $ moved due to insertion, so the marker's position was updated as > part of the replacement. Yeah, I have noticed that this afternoon. > Right, and so I submit that the problem is where the replacement stack > is updated: it should account for these subtleties and adjust the > stack positions accordingly, since it has the opportunity to look at > the match position before the matched text is replaced. I have a different approach: If the problem arise from using markers istead of integers, then how about we just use integers? Please take a look: --8<-----------------------------cut here---------------start------------->8--- commit cf13cb2dff040571b289e2ba8dcc0008394ffe3d Author: Tino Calancha Date: Sun May 20 20:43:30 2018 +0900 Fix corner case in query-replace-regexp undo This commit fixes Bug#31492. * lisp/replace.el(replace-save-match-data): New macro. (replace-match-maybe-edit): Preserve match data. * test/lisp/replace-tests.el (query-replace-undo-bug31492): Add test. diff --git a/lisp/replace.el b/lisp/replace.el index 3503b656d9..7d49b977fd 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2184,6 +2184,16 @@ replace-match-data new))) (match-data integers reuse t))) +(defmacro replace-save-match-data (&rest body) + "Like `save-match-data', but it uses integers instead of markers. +The value returned is the value of the last form in BODY." + (declare (indent 0) (debug t)) + (let ((match (gensym "match-data"))) + `(let ((,match (match-data 'integers))) + (unwind-protect + ,@body + (set-match-data ,match))))) + (defun replace-match-maybe-edit (newtext fixedcase literal noedit match-data &optional backward) "Make a replacement with `replace-match', editing `\\?'. @@ -2213,7 +2223,7 @@ replace-match-maybe-edit nil match-data match-data)))) noedit nil))) (set-match-data match-data) - (replace-match newtext fixedcase literal) + (replace-save-match-data (replace-match newtext fixedcase literal)) ;; `replace-match' leaves point at the end of the replacement text, ;; so move point to the beginning when replacing backward. (when backward (goto-char (nth 0 match-data))) diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el index 40a1a31cf7..40ee838e67 100644 --- a/test/lisp/replace-tests.el +++ b/test/lisp/replace-tests.el @@ -399,5 +399,25 @@ replace-tests--query-replace-undo ;; After undo text must be the same. (should (string= text (buffer-string)))))) +(ert-deftest query-replace-undo-bug31492 () + "Test for https://debbugs.gnu.org/31492 ." + (let ((text "a\nb\nc\n") + (count 0) + (inhibit-message t)) + (with-temp-buffer + (insert text) + (goto-char 1) + (cl-letf (((symbol-function 'read-event) + (lambda (&rest args) + (cl-incf count) + (let ((val (pcase count + ((or 1 2) ?\s) ; replace current and go next + (3 ?U) ; undo-all + (_ ?q)))) ; exit + val)))) + (perform-replace "^\\|\b\\|$" "foo" t t nil)) + ;; After undo text must be the same. + (should (string= text (buffer-string)))))) + ;;; replace-tests.el ends here --8<-----------------------------cut here---------------end--------------->8--- From debbugs-submit-bounces@debbugs.gnu.org Sun May 20 08:00:10 2018 Received: (at 31492) by debbugs.gnu.org; 20 May 2018 12:00:10 +0000 Received: from localhost ([127.0.0.1]:41675 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKN0T-0000nH-RM for submit@debbugs.gnu.org; Sun, 20 May 2018 08:00:09 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33638) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKN0R-0000lw-W8 for 31492@debbugs.gnu.org; Sun, 20 May 2018 08:00:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKN0H-00064I-Lg for 31492@debbugs.gnu.org; Sun, 20 May 2018 08:00:02 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05 autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:58340) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKN0H-00064D-I6; Sun, 20 May 2018 07:59:57 -0400 Received: from [176.228.60.248] (port=4749 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fKN0G-0007UI-7u; Sun, 20 May 2018 07:59:57 -0400 Date: Sun, 20 May 2018 14:59:57 +0300 Message-Id: <83sh6mfsg2.fsf@gnu.org> From: Eli Zaretskii To: Tino Calancha In-reply-to: <87sh6mwno1.fsf@gmail.com> (message from Tino Calancha on Sun, 20 May 2018 20:51:10 +0900) Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> <83zi0wgk3d.fsf@gnu.org> <87tvr3zpm4.fsf@gmail.com> <83vabifzfg.fsf@gnu.org> <87sh6mwno1.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) > From: Tino Calancha > Cc: 31492@debbugs.gnu.org > Date: Sun, 20 May 2018 20:51:10 +0900 > > If the problem arise from using markers istead of integers, then how > about we just use integers? Does this work with '^' and 'C-e', if they change text before a match that was already replaced and recorded? From debbugs-submit-bounces@debbugs.gnu.org Sun May 20 08:06:37 2018 Received: (at 31492) by debbugs.gnu.org; 20 May 2018 12:06:37 +0000 Received: from localhost ([127.0.0.1]:41679 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKN6j-0000ve-Gq for submit@debbugs.gnu.org; Sun, 20 May 2018 08:06:37 -0400 Received: from mail-pl0-f44.google.com ([209.85.160.44]:37495) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKN6h-0000vR-4c for 31492@debbugs.gnu.org; Sun, 20 May 2018 08:06:35 -0400 Received: by mail-pl0-f44.google.com with SMTP id w19-v6so7151341plq.4 for <31492@debbugs.gnu.org>; Sun, 20 May 2018 05:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=PJM8UUBTAxY4WX68mHZ/3M9CbgPxQA5xqjyB1Z/h/jo=; b=YFtXTiqgCORJy39Fin6+nJfvMPoaUZx0/n7imrCB9hZ3BkfmNoJJnLGIqFFUxOzhSC gFdlE2Umpc8gkCSYr37IzJkXzLUvY0zgoYYdgYIcwLnn5R886HofND0Tsoq6CqliILuv RYgYPKxK0NBBkiD7vW8r4LoNTJRahbt+qmKHVfbLRKJDvTWJk60nAWydFctzvUbVBnuS K1YdMk1Av0fZfQf8oNNnKpr0G89euAVTF3WMkJRLse6uB+a9kSx15vW0V8GEihFnrUZb MT92STwINV1GgA7aNasHwQJ0m8Ef91KIR8jl+NfyzyVirvwpXHknbZNVNO+GQhZH6k53 Mn0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=PJM8UUBTAxY4WX68mHZ/3M9CbgPxQA5xqjyB1Z/h/jo=; b=OA34/PxVKoYjzmdJXhJCFx7DMd1S6JJ8yM4kufyxs3XuSJqY0Evbbg19Sk42nKRFCZ 9qdx6k9K45p+1fxpr0WTJqrh9obHXk1kyT6Tsxptf5uHCdFH889BpR2EvP/8v/LN5+OY lR8mfJuiwR7esr6MepoQS3A+fs0ucB4FE5CgnA4XdYhsFYnvopCGNBI9YOYwJQX/rrO2 EY1DOeLbKP/V/Do2HL9Nj4NBpNd5AzaGhx+VKUuHfL1aVJgarIe/dGNNDNn/qfl/3b8M +SiGqchPEaPEJjDre7TqGKsQyAfvFqMPp8x4HcxuMNzNH3eOoSz9e/MXZsIAqlLxA+si /HqA== X-Gm-Message-State: ALKqPwdqu2VJ86vvyAjBr/9oiE7jpVFdVs8ZrW7kr5pHEdP6Yd3wHr3V d9x1K5DwhEfV3rwmA1lv0PU= X-Google-Smtp-Source: AB8JxZqrV3pGd/+SsY9heD1OFkLe6Wl4zaE6z0rtXre2zWBYkg/VpAqj1Zn4obh2kZJ5THxhYpH2VA== X-Received: by 2002:a17:902:a582:: with SMTP id az2-v6mr16285542plb.98.1526817989485; Sun, 20 May 2018 05:06:29 -0700 (PDT) Received: from calancha-pc (228.225.128.101.dy.bbexcite.jp. [101.128.225.228]) by smtp.gmail.com with ESMTPSA id v16-v6sm34571128pfk.164.2018.05.20.05.06.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 May 2018 05:06:28 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Sun, 20 May 2018 21:06:21 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Eli Zaretskii Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars In-Reply-To: <83sh6mfsg2.fsf@gnu.org> Message-ID: References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> <83zi0wgk3d.fsf@gnu.org> <87tvr3zpm4.fsf@gmail.com> <83vabifzfg.fsf@gnu.org> <87sh6mwno1.fsf@gmail.com> <83sh6mfsg2.fsf@gnu.org> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: -1.8 (-) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.8 (--) On Sun, 20 May 2018, Eli Zaretskii wrote: >> From: Tino Calancha >> Cc: 31492@debbugs.gnu.org >> Date: Sun, 20 May 2018 20:51:10 +0900 >> >> If the problem arise from using markers istead of integers, then how >> about we just use integers? > > Does this work with '^' and 'C-e', if they change text before a match > that was already replaced and recorded? I don't understand. Do you have a recipe? BTW, I found another issue in this feature. I will open another report. From debbugs-submit-bounces@debbugs.gnu.org Sun May 20 08:48:16 2018 Received: (at 31492) by debbugs.gnu.org; 20 May 2018 12:48:16 +0000 Received: from localhost ([127.0.0.1]:41721 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKNl1-0003ru-SP for submit@debbugs.gnu.org; Sun, 20 May 2018 08:48:16 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40367) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKNkz-0003rh-L3 for 31492@debbugs.gnu.org; Sun, 20 May 2018 08:48:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKNkr-0004Yi-6x for 31492@debbugs.gnu.org; Sun, 20 May 2018 08:48:08 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:58963) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKNkr-0004Yc-4h; Sun, 20 May 2018 08:48:05 -0400 Received: from [176.228.60.248] (port=4791 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fKNkq-0001rZ-JR; Sun, 20 May 2018 08:48:05 -0400 Date: Sun, 20 May 2018 15:48:06 +0300 Message-Id: <83r2m6fq7t.fsf@gnu.org> From: Eli Zaretskii To: Tino Calancha In-reply-to: (message from Tino Calancha on Sun, 20 May 2018 21:06:21 +0900 (JST)) Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> <83zi0wgk3d.fsf@gnu.org> <87tvr3zpm4.fsf@gmail.com> <83vabifzfg.fsf@gnu.org> <87sh6mwno1.fsf@gmail.com> <83sh6mfsg2.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) > From: Tino Calancha > Date: Sun, 20 May 2018 21:06:21 +0900 (JST) > cc: Tino Calancha , 31492@debbugs.gnu.org > > >> If the problem arise from using markers istead of integers, then how > >> about we just use integers? > > > > Does this work with '^' and 'C-e', if they change text before a match > > that was already replaced and recorded? > I don't understand. Do you have a recipe? Not a recipe, an idea: I'm bothered by the possibility of the saved positions becoming outdated if something changes text before the saved positions. Markers would move with the text, but positions won't. The question is: is such a situation possible? From debbugs-submit-bounces@debbugs.gnu.org Sun May 20 09:46:17 2018 Received: (at 31492) by debbugs.gnu.org; 20 May 2018 13:46:17 +0000 Received: from localhost ([127.0.0.1]:41753 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKOfA-0005BS-Qz for submit@debbugs.gnu.org; Sun, 20 May 2018 09:46:16 -0400 Received: from mail-pl0-f54.google.com ([209.85.160.54]:46047) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKOf9-0005BD-7Y for 31492@debbugs.gnu.org; Sun, 20 May 2018 09:46:15 -0400 Received: by mail-pl0-f54.google.com with SMTP id bi12-v6so7207740plb.12 for <31492@debbugs.gnu.org>; Sun, 20 May 2018 06:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=RMkP5vvlBjYK1vuBqOrJ+4IUAwuaW4+mOS8hr8/1jHY=; b=nk4Hg7eVJYlPwjIGZupPnqkLpqfgbmv+X55dSXsyrWtwryFv70q7tspv4JhEDeE9Xb Buyfh67eNccQYkA9vOEgNaqALVeDMnUGgsC508om8j4wDHjZzpwbKICtr7JyUiXKdi9u 11YI3bKk2K42BWK4qwNWK9iGpQw7MdNp6EueIq4qXc7JB3Wf7scvaefJOR3lzMrj5wzC l0tuPllO77ETkgrp96KArio6xzOuCXb2W11/7ewO+UjdfDdxCzxjPkmLLr7y4xU4Du/y Co/qAdiYLFtZp0R6amSJpn9R/wDJel+xegoazRcDLQZcquiIBCo01TERGe2sSKAWpajC zylg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=RMkP5vvlBjYK1vuBqOrJ+4IUAwuaW4+mOS8hr8/1jHY=; b=gNhFHW+STEtLsAsAOKbKAwVFT/vwRPv0+AdmAcBNXP5c5IRupeopb0wQw0RyPtgqqp YBrip2VZyO0a0/6QPq41t7OeimRcBeL7IFgAmGZYkqcUa7Fc4utdwp/EJrPYbRYW4VJP NFlt2Kv5JnX80aA8zb/X1XmjN4XfYYIgTVAA5bwe/00DVnM+UznGeJYqm7kUV0Tf057J PVFNIITboRMb5Zi9LSC1ECGOB6J3wCf5YgA5hHokOqtqSdsJXTgYtCqhPcJHE2OaS3lh VAInqlgobqRnIsXZg4iUDUf6yC29KulZZUmzMBASFRXlUOdM08d/Py9ksNjVPfc8Snmf mK9Q== X-Gm-Message-State: ALKqPwer3tbbXZo3gj/SaGAeY877jeD/WiCXYhAv2vPUTGt7aKiyBYzO PCpM5DzpL/vb4v+k3F21KFk= X-Google-Smtp-Source: AB8JxZqwxwebz/5bOkD+e7uzQwvjsu6OSqzMkq1HALcnGpyzdnaVjDKYEuRWWHl4hAxyiAht5NFHiw== X-Received: by 2002:a17:902:2702:: with SMTP id c2-v6mr16546542plb.297.1526823969421; Sun, 20 May 2018 06:46:09 -0700 (PDT) Received: from calancha-pc (228.225.128.101.dy.bbexcite.jp. [101.128.225.228]) by smtp.gmail.com with ESMTPSA id z8-v6sm13880309pgc.13.2018.05.20.06.46.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 May 2018 06:46:08 -0700 (PDT) From: Tino Calancha X-Google-Original-From: Tino Calancha Date: Sun, 20 May 2018 22:46:05 +0900 (JST) X-X-Sender: calancha@calancha-pc To: Eli Zaretskii Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars In-Reply-To: <83r2m6fq7t.fsf@gnu.org> Message-ID: References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> <83zi0wgk3d.fsf@gnu.org> <87tvr3zpm4.fsf@gmail.com> <83vabifzfg.fsf@gnu.org> <87sh6mwno1.fsf@gmail.com> <83sh6mfsg2.fsf@gnu.org> <83r2m6fq7t.fsf@gnu.org> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org, Tino Calancha X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On Sun, 20 May 2018, Eli Zaretskii wrote: > Not a recipe, an idea: I'm bothered by the possibility of the saved > positions becoming outdated if something changes text before the saved > positions. Markers would move with the text, but positions won't. > > The question is: is such a situation possible? Everything is possible (except, possibly, that I find a new job). You know what they say: In the risk is the pleasure. Otherwise we can use the first patch; the one with the test: (/= (match-beginning 0) (match-end 0)) From debbugs-submit-bounces@debbugs.gnu.org Sun May 20 11:47:20 2018 Received: (at 31492) by debbugs.gnu.org; 20 May 2018 15:47:21 +0000 Received: from localhost ([127.0.0.1]:42065 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKQYI-0007uX-UJ for submit@debbugs.gnu.org; Sun, 20 May 2018 11:47:20 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58365) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKQYH-0007uK-Mv for 31492@debbugs.gnu.org; Sun, 20 May 2018 11:47:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKQY9-0006ba-Bc for 31492@debbugs.gnu.org; Sun, 20 May 2018 11:47:12 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:60763) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKQY9-0006bM-7W; Sun, 20 May 2018 11:47:09 -0400 Received: from [176.228.60.248] (port=1392 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fKQY8-0006zm-Jz; Sun, 20 May 2018 11:47:08 -0400 Date: Sun, 20 May 2018 18:47:10 +0300 Message-Id: <83po1qfhxd.fsf@gnu.org> From: Eli Zaretskii To: Tino Calancha In-reply-to: (message from Tino Calancha on Sun, 20 May 2018 22:46:05 +0900 (JST)) Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> <83zi0wgk3d.fsf@gnu.org> <87tvr3zpm4.fsf@gmail.com> <83vabifzfg.fsf@gnu.org> <87sh6mwno1.fsf@gmail.com> <83sh6mfsg2.fsf@gnu.org> <83r2m6fq7t.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org, tino.calancha@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) > From: Tino Calancha > Date: Sun, 20 May 2018 22:46:05 +0900 (JST) > cc: Tino Calancha , 31492@debbugs.gnu.org > > > The question is: is such a situation possible? > Everything is possible (except, possibly, that I find a new job). Actually, I know a few things that are even less possible than that. > You know what they say: In the risk is the pleasure. Otherwise we > can use the first patch; the one with the test: > (/= (match-beginning 0) (match-end 0)) No, I like the 2nd one better. Thanks. From debbugs-submit-bounces@debbugs.gnu.org Sun May 20 21:51:57 2018 Received: (at 31492) by debbugs.gnu.org; 21 May 2018 01:51:57 +0000 Received: from localhost ([127.0.0.1]:42312 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKZzR-0003kG-5q for submit@debbugs.gnu.org; Sun, 20 May 2018 21:51:57 -0400 Received: from mail-pg0-f49.google.com ([74.125.83.49]:36761) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKZzQ-0003k1-5t for 31492@debbugs.gnu.org; Sun, 20 May 2018 21:51:56 -0400 Received: by mail-pg0-f49.google.com with SMTP id 63-v6so3495681pgg.3 for <31492@debbugs.gnu.org>; Sun, 20 May 2018 18:51:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=LRPNgN2Q5cENbTtMoljZR4O+yGh8sbeK2seqJxXcYsg=; b=tCE2G2ebTqJ/gzYVzIrFXFo3HIKFDwJ2xrGlkogXSNihmldBKVQbIqxbuwfN3sGUEy C0y+kAn7I08k73vkRgJdR8KuGSnxXkHxGn2GHty1lKFjJ0U/2OfBzQCDb24jLrllFQkS cwBKuR3BWyxYNKZwTyB/mjD5oaFt+7ZNm070TMilxTCNjsnLtIDI+mlG6X1TLr04HJW0 +8sOjuERrZMRuwrADQRtF1Imr2oCW233Mipsmd9UpT0yijxJYbkK21hQkQ0nBc/cp2S7 IIspWbRHta3gtdVancTFHwKhZXtVQPVSrv9GrO4atM44Qiw3xlgbp+Z3NxxTyPNG01qn LB/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=LRPNgN2Q5cENbTtMoljZR4O+yGh8sbeK2seqJxXcYsg=; b=DWHgk50rMdaZfdlsgoa23xwbsD+OtOJeffqpYc3tLjemv8RtRFk6/EYPwQDrTMy5Ay kNh4s1o7Q64kycRReRTPmvRPGHkYSjyeNWa7GsU7JNOf7kHxkuD4IvWvzJwLDn14UiEq qxyoeu2wsClTh011F/2wljFG/pFWcaZunW6J9Uu/6EtzTNzhTnq4AjC6GCilUVRzuybp MxYaswULzOOtScjku/Z4WX+oLoj8VGmf7S1q2gBvNzbQQbLKe0ijjn3zGmMg5aJs101r qQiu3hHhxuHPvkk4vx7ld5ze47jdJ6QrI6jhr66Vn23kdDmSVcWRQ79mIqqhqA7P9A0W Bybg== X-Gm-Message-State: ALKqPwfb/lPtCENlVM7XAO2YxcKR6Bz4/Txhf7VfqQWY5OEFw+CpF4Vw m8MoKwHZOJhZDd/uDkLXOiOCaQ== X-Google-Smtp-Source: AB8JxZpfHF+OYfkaFQx8o6lhHBZnWFhJ8+4bCsDOkTaggBs8HstcqM8IRJPGnUqXiwcHlY9naI1FDg== X-Received: by 2002:aa7:8492:: with SMTP id u18-v6mr18101910pfn.225.1526867509745; Sun, 20 May 2018 18:51:49 -0700 (PDT) Received: from calancha-pc (228.225.128.101.dy.bbexcite.jp. [101.128.225.228]) by smtp.gmail.com with ESMTPSA id k193-v6sm16083691pgc.39.2018.05.20.18.51.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 May 2018 18:51:48 -0700 (PDT) From: Tino Calancha To: Eli Zaretskii Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> <83zi0wgk3d.fsf@gnu.org> <87tvr3zpm4.fsf@gmail.com> <83vabifzfg.fsf@gnu.org> <87sh6mwno1.fsf@gmail.com> <83sh6mfsg2.fsf@gnu.org> <83r2m6fq7t.fsf@gnu.org> <83po1qfhxd.fsf@gnu.org> Date: Mon, 21 May 2018 10:51:43 +0900 In-Reply-To: <83po1qfhxd.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 20 May 2018 18:47:10 +0300") Message-ID: <87y3gdhj2o.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Eli Zaretskii writes: >> we can use the first patch; the one with the test: >> (/= (match-beginning 0) (match-end 0)) > > No, I like the 2nd one better. Following patch is equivalent to the 2nd and its 1-liner (excluded clarification comments): --8<-----------------------------cut here---------------start------------->8--- commit 565c30caa8d5b015fd34446bd8900c55b2f67544 Author: Tino Calancha Date: Mon May 21 10:46:50 2018 +0900 Fix corner case in query-replace-regexp undo This commit fixes Bug#31492. * lisp/replace.el (replace-match-maybe-edit): Preserve match data. * test/lisp/replace-tests.el (query-replace-undo-bug31492): Add test. diff --git a/lisp/replace.el b/lisp/replace.el index 3503b656d9..a17dd19b0d 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2214,6 +2214,10 @@ replace-match-maybe-edit noedit nil))) (set-match-data match-data) (replace-match newtext fixedcase literal) + ;; `query-replace' undo feature needs the beginning of the match position, + ;; but `replace-match' may change it, for instance, with a regexp like "^". + ;; Ensure that this function preserves the match data (Bug#31492). + (set-match-data match-data) ;; `replace-match' leaves point at the end of the replacement text, ;; so move point to the beginning when replacing backward. (when backward (goto-char (nth 0 match-data))) diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el index 40a1a31cf7..40ee838e67 100644 --- a/test/lisp/replace-tests.el +++ b/test/lisp/replace-tests.el @@ -399,5 +399,25 @@ replace-tests--query-replace-undo ;; After undo text must be the same. (should (string= text (buffer-string)))))) +(ert-deftest query-replace-undo-bug31492 () + "Test for https://debbugs.gnu.org/31492 ." + (let ((text "a\nb\nc\n") + (count 0) + (inhibit-message t)) + (with-temp-buffer + (insert text) + (goto-char 1) + (cl-letf (((symbol-function 'read-event) + (lambda (&rest args) + (cl-incf count) + (let ((val (pcase count + ((or 1 2) ?\s) ; replace current and go next + (3 ?U) ; undo-all + (_ ?q)))) ; exit + val)))) + (perform-replace "^\\|\b\\|$" "foo" t t nil)) + ;; After undo text must be the same. + (should (string= text (buffer-string)))))) + ;;; replace-tests.el ends here --8<-----------------------------cut here---------------end--------------->8--- From debbugs-submit-bounces@debbugs.gnu.org Mon May 21 11:05:57 2018 Received: (at 31492) by debbugs.gnu.org; 21 May 2018 15:05:57 +0000 Received: from localhost ([127.0.0.1]:43141 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKmNl-0001P2-T1 for submit@debbugs.gnu.org; Mon, 21 May 2018 11:05:57 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37172) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKmNk-0001Oo-2Q for 31492@debbugs.gnu.org; Mon, 21 May 2018 11:05:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKmNb-0007DU-OQ for 31492@debbugs.gnu.org; Mon, 21 May 2018 11:05:47 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:53824) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKmNb-0007DM-Kr; Mon, 21 May 2018 11:05:43 -0400 Received: from [176.228.60.248] (port=2907 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fKmNb-0005vY-4b; Mon, 21 May 2018 11:05:43 -0400 Date: Mon, 21 May 2018 18:05:47 +0300 Message-Id: <83a7stf3qs.fsf@gnu.org> From: Eli Zaretskii To: Tino Calancha In-reply-to: <87y3gdhj2o.fsf@gmail.com> (message from Tino Calancha on Mon, 21 May 2018 10:51:43 +0900) Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> <83zi0wgk3d.fsf@gnu.org> <87tvr3zpm4.fsf@gmail.com> <83vabifzfg.fsf@gnu.org> <87sh6mwno1.fsf@gmail.com> <83sh6mfsg2.fsf@gnu.org> <83r2m6fq7t.fsf@gnu.org> <83po1qfhxd.fsf@gnu.org> <87y3gdhj2o.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 31492 Cc: 31492@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) > From: Tino Calancha > Cc: 31492@debbugs.gnu.org > Date: Mon, 21 May 2018 10:51:43 +0900 > > Eli Zaretskii writes: > > > >> we can use the first patch; the one with the test: > >> (/= (match-beginning 0) (match-end 0)) > > > > No, I like the 2nd one better. > Following patch is equivalent to the 2nd and its 1-liner > (excluded clarification comments): Thanks, LGTM. If no comments emerge in a couple of days, please push. From debbugs-submit-bounces@debbugs.gnu.org Wed May 23 05:23:13 2018 Received: (at 31492-done) by debbugs.gnu.org; 23 May 2018 09:23:13 +0000 Received: from localhost ([127.0.0.1]:44791 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fLPzF-000753-9k for submit@debbugs.gnu.org; Wed, 23 May 2018 05:23:13 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:41665) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fLPzD-00074q-1s for 31492-done@debbugs.gnu.org; Wed, 23 May 2018 05:23:11 -0400 Received: by mail-pf0-f169.google.com with SMTP id v63-v6so10192829pfk.8 for <31492-done@debbugs.gnu.org>; Wed, 23 May 2018 02:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version; bh=W4gi5Pw59eZw9VBOBcn1t2nqJz8MybYsmGEsfyWMEKo=; b=cu4MXuMUQIWk7molvvX9u+5Q1mZXYNr0MywMTcHn7gheAgGxnahJEYEk/uqykjt32K dxnijzNA/rM0kszTVYjT/URCiGFVdojMPc9DrcfZi6WmhN/QfFHifS01HyyjXzDmC0Sd gxAjKmoVHtTV61R4MOUBXLOAnzaUHadyt1BElnK+win0/wC4zajNdWKEdIdTYU7Bdujq kOjS2gMi3PI2mhRg2j4ppBXSZCMuklolCw1r0WkwYH8rHgfoMZXyapFXUWPV6b35onoJ xNhGnrNpUOa7MZtHeuWmRdgq8M6DrAr8LVlbzp+UfF7Ikbv2xzH9sBupnTRNC1x6nBUz O6xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=W4gi5Pw59eZw9VBOBcn1t2nqJz8MybYsmGEsfyWMEKo=; b=np/Ojev1C3vVjq+rfcK5lYRqJO9jOxaGo2hNBcrwh5ntZmgEilzBjcHR8NMhKUjI4H sFMIxLrCxGUkRHPwDPyoPWp45hRBL1IMQCnkR+93JcmtW8QSyY8+Z8M4qIpMmfEcy1hl Ch4u6V5chMKkMDwvQhmKb49TRZ7rrf8AizH2+esAM84qHT7TCeNdwUW0L6UzSPMWDw3C JrworPFlzntEeYi/7EfaUHPhIcQjmnhuO4k2FiT9bKZl0G1KXE/RM7lnvHytw8TrZUzI vES9UTmood51NNd/zEPuDFgfkcX/E1MZXHTJW+IkpqEyko24yLoVBnHJb6A5xJIePSmT K41w== X-Gm-Message-State: ALKqPwe1DZkkN/tOKEgRjSVsSJ3nRE2lgZxxYYT3LeBb8Dv5cSDUrBXD NdjeHVyECIrky78ZeIkeLEqL4Q== X-Google-Smtp-Source: AB8JxZpZj+hvGxAogLr5y0YTZ66cLeDPxjJ5LHldxbef+1PzB1nKjFOWhOc0kPvI6x/zNVDndR8/bw== X-Received: by 2002:a63:934d:: with SMTP id w13-v6mr1748968pgm.212.1527067384723; Wed, 23 May 2018 02:23:04 -0700 (PDT) Received: from calancha-pc (228.225.128.101.dy.bbexcite.jp. [101.128.225.228]) by smtp.gmail.com with ESMTPSA id q75-v6sm36518788pfj.94.2018.05.23.02.23.02 for <31492-done@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 May 2018 02:23:03 -0700 (PDT) From: Tino Calancha To: 31492-done@debbugs.gnu.org Subject: Re: bug#31492: 26.1; query-replace-regexp undo fails in regexps w/o printable chars References: <8736yp14c7.fsf@gmail.com> <838t8hhwwu.fsf@gnu.org> <837eo1huji.fsf@gnu.org> <83zi0wgk3d.fsf@gnu.org> <87tvr3zpm4.fsf@gmail.com> <83vabifzfg.fsf@gnu.org> <87sh6mwno1.fsf@gmail.com> <83sh6mfsg2.fsf@gnu.org> <83r2m6fq7t.fsf@gnu.org> <83po1qfhxd.fsf@gnu.org> <87y3gdhj2o.fsf@gmail.com> <83a7stf3qs.fsf@gnu.org> Date: Wed, 23 May 2018 18:22:57 +0900 In-Reply-To: <83a7stf3qs.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 21 May 2018 18:05:47 +0300") Message-ID: <87603eohe6.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.8 (-) X-Debbugs-Envelope-To: 31492-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.8 (--) Eli Zaretskii writes: >> From: Tino Calancha >> Cc: 31492@debbugs.gnu.org >> Date: Mon, 21 May 2018 10:51:43 +0900 >> Following patch is equivalent to the 2nd and its 1-liner >> (excluded clarification comments): > > Thanks, LGTM. If no comments emerge in a couple of days, please push. Pushed into master branch as 'Fix corner case in query-replace-regexp undo' (bab73230d1be1fe394b7269c1365ef6fb1a5d9b3) From unknown Sun Jun 22 11:30:53 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 20 Jun 2018 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator