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: Mon, 21 May 2018 10:51:43 +0900 Message-ID: <87y3gdhj2o.fsf@gmail.com> 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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1526867415 29367 195.159.176.226 (21 May 2018 01:50:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 21 May 2018 01:50:15 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 31492@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon May 21 03:50:10 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 1fKZxh-0007Uj-HS for geb-bug-gnu-emacs@m.gmane.org; Mon, 21 May 2018 03:50:09 +0200 Original-Received: from localhost ([::1]:48311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKZzo-0004Pd-LA for geb-bug-gnu-emacs@m.gmane.org; Sun, 20 May 2018 21:52:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKZzb-0004PW-8M for bug-gnu-emacs@gnu.org; Sun, 20 May 2018 21:52:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKZzW-0003eQ-E7 for bug-gnu-emacs@gnu.org; Sun, 20 May 2018 21:52:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:34415) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fKZzW-0003eJ-AG for bug-gnu-emacs@gnu.org; Sun, 20 May 2018 21:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fKZzV-0003kZ-R8 for bug-gnu-emacs@gnu.org; Sun, 20 May 2018 21:52:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 May 2018 01:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31492 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 31492-submit@debbugs.gnu.org id=B31492.152686751714404 (code B ref 31492); Mon, 21 May 2018 01:52:01 +0000 Original-Received: (at 31492) by debbugs.gnu.org; 21 May 2018 01:51:57 +0000 Original-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 Original-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 Original-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) Original-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) In-Reply-To: <83po1qfhxd.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 20 May 2018 18:47:10 +0300") 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:146338 Archived-At: 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---