From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#31492: 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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1526652083 27273 195.159.176.226 (18 May 2018 14:01:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 18 May 2018 14:01:23 +0000 (UTC) To: 31492@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 18 16:01:19 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fJfwb-0006wH-9U for geb-bug-gnu-emacs@m.gmane.org; Fri, 18 May 2018 16:01:17 +0200 Original-Received: from localhost ([::1]:39158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJfyi-00040U-Cg for geb-bug-gnu-emacs@m.gmane.org; Fri, 18 May 2018 10:03:28 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJfQT-00063q-NE for bug-gnu-emacs@gnu.org; Fri, 18 May 2018 09:28:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJfQQ-0001RH-HG for bug-gnu-emacs@gnu.org; Fri, 18 May 2018 09:28:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59645) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fJfQQ-0001RA-C9 for bug-gnu-emacs@gnu.org; Fri, 18 May 2018 09:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fJfQQ-0002FG-6a for bug-gnu-emacs@gnu.org; Fri, 18 May 2018 09:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 18 May 2018 13:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 31492 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15266500808620 (code B ref -1); Fri, 18 May 2018 13:28:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 May 2018 13:28:00 +0000 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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) Original-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) 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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" Xref: news.gmane.org gmane.emacs.bugs:146257 Archived-At: 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