From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: phillip.lord@russet.org.uk (Phillip Lord) Newsgroups: gmane.emacs.bugs Subject: bug#23871: 25.1.50; Undo unexpectedly leads to blank buffer Date: Fri, 01 Jul 2016 15:04:32 +0100 Message-ID: <878txlsbdb.fsf@russet.org.uk> References: <83h9cavdgj.fsf@gnu.org> <87poqyy2tc.fsf@metalevel.at> <87vb0qqrkz.fsf@russet.org.uk> <87h9c9zx75.fsf@metalevel.at> <834m89vmyv.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1467381935 11472 80.91.229.3 (1 Jul 2016 14:05:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 Jul 2016 14:05:35 +0000 (UTC) Cc: 23871@debbugs.gnu.org, Markus Triska To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jul 01 16:05:19 2016 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 1bIz4H-0001n6-Dp for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Jul 2016 16:05:17 +0200 Original-Received: from localhost ([::1]:33718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIz4G-0002ct-Fe for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Jul 2016 10:05:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIz48-0002bR-0p for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2016 10:05:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bIz42-0003ir-Nh for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2016 10:05:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49921) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIz42-0003in-HA for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2016 10:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bIz42-0003Ai-CP for bug-gnu-emacs@gnu.org; Fri, 01 Jul 2016 10:05:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: phillip.lord@russet.org.uk (Phillip Lord) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 01 Jul 2016 14:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23871 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 23871-submit@debbugs.gnu.org id=B23871.146738188312164 (code B ref 23871); Fri, 01 Jul 2016 14:05:02 +0000 Original-Received: (at 23871) by debbugs.gnu.org; 1 Jul 2016 14:04:43 +0000 Original-Received: from localhost ([127.0.0.1]:34025 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bIz3i-0003A8-M5 for submit@debbugs.gnu.org; Fri, 01 Jul 2016 10:04:42 -0400 Original-Received: from cloud103.planethippo.com ([31.216.48.48]:38271) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bIz3f-00039u-Ak for 23871@debbugs.gnu.org; Fri, 01 Jul 2016 10:04:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=russet.org.uk; s=default; h=Content-Type:MIME-Version:Message-ID: In-Reply-To:Date:References:Subject:Cc:To:From; bh=fb7PUaeOR/Ozt5PYS+GUh8pktEwDo1uWZ14AQJHQ+2g=; b=0qRyfFU0PXp8to6jdO/zUjnzlG p02szjPrYxkIa1SHoRRKF8NTWzRsguGqxkZ1sFoJ0FYCl0j+oIavkXRXV1Otq2kEre5SbLpE9xPBT zfHDiLI0mDK9cx10xAXoptONYKPWoRJdTaYyx5Y1tMZ5MzOuWskgkvBsScggECua0g5qUsx1RQL9g eRv3UsDqi5PEAgdLtFY/7Yt6oRmivqbaPo7sKu+hVZTc3AGwYeBxnpdsrMSwjrA2sALTdHLFNaK4c sXVWTuMcDfJ+CqebJtQTzjq+BeqgLng1/imchPqreXnDfEFtu4JWsPVfBP1xNnjIzmEKmWEwJLE2C Con0j40A==; Original-Received: from cpc1-benw10-2-0-cust373.gate.cable.virginm.net ([77.98.219.118]:39198 helo=russet.org.uk) by cloud103.planethippo.com with esmtpsa (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.86_1) (envelope-from ) id 1bIz3Z-003vfM-26; Fri, 01 Jul 2016 15:04:33 +0100 In-Reply-To: <834m89vmyv.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 01 Jul 2016 10:25:44 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.95 (gnu/linux) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cloud103.planethippo.com X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - russet.org.uk X-Get-Message-Sender-Via: cloud103.planethippo.com: authenticated_id: phillip.lord@russet.org.uk X-Authenticated-Sender: cloud103.planethippo.com: phillip.lord@russet.org.uk 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:120258 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Markus Triska >> Cc: Eli Zaretskii , 23871@debbugs.gnu.org >> Date: Fri, 01 Jul 2016 08:31:10 +0200 >> >> phillip.lord@russet.org.uk (Phillip Lord) writes: >> >> > I believe the following patch fixes #21722. >> >> I tried it, and can still reproduce both #21722 and #23871 also with the >> patch applied to the current emacs-25 branch. > > Which doesn't surprise me, since point is at the insertion position > just before the insertion, which is when record_insert is called, > AFAIU. > > I think the question here is why does undo record the position of > point at the end of the sexp, and not where point was when C-M-x was > invoked. It doesn't record point at all. It doesn't end up at the end of the sexp, rather at the beginning of the insertion (which happen to be the same place). > This has something to do with code that runs off C-M-x, I presume. I think it's because I forgot to call record_point when calling record_insert. The patch I sent yesterday put that back, but did it wrong. The following patch (attempts) to address the issue which is, unfortunately, a bit more extensive than the last. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-missing-point-information-in-undo.patch >From 906a5affc1fc04a9d1d3efffb7d5bfc21e6c2e44 Mon Sep 17 00:00:00 2001 From: Phillip Lord Date: Thu, 30 Jun 2016 22:06:00 +0100 Subject: [PATCH] Fix missing point information in undo * src/undo.c (record_insert): Use record_point instead of prepare_record. Addresses Bug# 21722 --- src/undo.c | 10 ++++++---- test/automated/simple-test.el | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/undo.c b/src/undo.c index be5b270..d8375a9 100644 --- a/src/undo.c +++ b/src/undo.c @@ -60,8 +60,6 @@ record_point (ptrdiff_t pt) at_boundary = ! CONSP (BVAR (current_buffer, undo_list)) || NILP (XCAR (BVAR (current_buffer, undo_list))); - prepare_record (); - /* If we are just after an undo boundary, and point wasn't at start of deleted range, record where it was. */ if (at_boundary) @@ -85,6 +83,10 @@ record_insert (ptrdiff_t beg, ptrdiff_t length) prepare_record (); + if (point_before_last_command_or_undo != beg + && buffer_before_last_command_or_undo == current_buffer) + record_point (point_before_last_command_or_undo); + /* If this is following another insertion and consecutive with it in the buffer, combine the two. */ if (CONSP (BVAR (current_buffer, undo_list))) @@ -163,6 +165,8 @@ record_delete (ptrdiff_t beg, Lisp_Object string, bool record_markers) if (EQ (BVAR (current_buffer, undo_list), Qt)) return; + prepare_record (); + if (point_before_last_command_or_undo != beg && buffer_before_last_command_or_undo == current_buffer) record_point (point_before_last_command_or_undo); @@ -170,12 +174,10 @@ record_delete (ptrdiff_t beg, Lisp_Object string, bool record_markers) if (PT == beg + SCHARS (string)) { XSETINT (sbeg, -beg); - prepare_record (); } else { XSETFASTINT (sbeg, beg); - prepare_record (); } /* primitive-undo assumes marker adjustments are recorded diff --git a/test/automated/simple-test.el b/test/automated/simple-test.el index 40cd1d2..c41d010 100644 --- a/test/automated/simple-test.el +++ b/test/automated/simple-test.el @@ -311,6 +311,7 @@ undo-test-point-after-forward-kill (undo-test-point-after-forward-kill)))) (defmacro simple-test-undo-with-switched-buffer (buffer &rest body) + (declare (indent 1) (debug t)) (let ((before-buffer (make-symbol "before-buffer"))) `(let ((,before-buffer (current-buffer))) (unwind-protect @@ -340,8 +341,24 @@ simple-test-undo-with-switched-buffer (point-min) (point-max)))))) +(ert-deftest missing-record-point-in-undo () + "Check point is being restored correctly. - +See Bug#21722." + (should + (= 5 + (with-temp-buffer + (generate-new-buffer " *temp*") + (emacs-lisp-mode) + (setq buffer-undo-list nil) + (insert "(progn (end-of-line) (insert \"hello\"))") + (beginning-of-line) + (forward-char 4) + (undo-boundary) + (eval-defun nil) + (undo-boundary) + (undo) + (point))))) (provide 'simple-test) ;;; simple-test.el ends here -- 2.9.0 --=-=-=--