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: Sat, 02 Jul 2016 21:21:28 +0100 Message-ID: <87k2h37pvb.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> <878txlsbdb.fsf@russet.org.uk> <87furtccdv.fsf@metalevel.at> <877fd5q9te.fsf@russet.org.uk> <83bn2gtruk.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1467490947 23790 80.91.229.3 (2 Jul 2016 20:22:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 2 Jul 2016 20:22:27 +0000 (UTC) Cc: 23871@debbugs.gnu.org, triska@metalevel.at To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jul 02 22:22:16 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 1bJRQd-0006Hn-IG for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 Jul 2016 22:22:15 +0200 Original-Received: from localhost ([::1]:39987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJRQc-0004N1-EV for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 Jul 2016 16:22:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJRQW-0004Mu-G6 for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2016 16:22:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bJRQQ-0004NI-By for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2016 16:22:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:50773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJRQQ-0004NE-96 for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2016 16:22:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bJRQQ-0000h0-4k for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2016 16:22: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: Sat, 02 Jul 2016 20:22: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.14674908972629 (code B ref 23871); Sat, 02 Jul 2016 20:22:02 +0000 Original-Received: (at 23871) by debbugs.gnu.org; 2 Jul 2016 20:21:37 +0000 Original-Received: from localhost ([127.0.0.1]:34877 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bJRQ0-0000gL-V6 for submit@debbugs.gnu.org; Sat, 02 Jul 2016 16:21:37 -0400 Original-Received: from cloud103.planethippo.com ([31.216.48.48]:35738) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bJRPz-0000g7-9c for 23871@debbugs.gnu.org; Sat, 02 Jul 2016 16:21:35 -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=lIosCRABMRYvMw1MjLnOLW89Y49EVYTeBEFekLOzQQY=; b=fP8TNnoNj6qar6c6ANWPn4CLlX 72L4rwiJaoyX6WVvNpraFuz0+SupqjhpoWkxadLnoNT0ueKoEvbdSfc44GbUsmkKSxPuX+AUE31r6 uYMipVsVj7Yd5miTeRfYCeKvKowcaxf6yispX/NU6DXaByiX6U6AmbhtgA++ZpQ1EowIJdbEP0s3s qKiTASkV/HiF7wdm+iHfXqIMJUKIGyj6CL3IxHW+LOksDw2MKdDJsv8QsEqogi9q/UU64CbeWqp13 2OZAoIjcC8RN9bnpy/4KxXSLFIIkc+KLoE434CkERyTDpvWsbKu07lFjAAWsE6zvom6z24wUGXfgG YD15VFqA==; Original-Received: from cpc1-benw10-2-0-cust373.gate.cable.virginm.net ([77.98.219.118]:53495 helo=russet.org.uk) by cloud103.planethippo.com with esmtpsa (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.86_1) (envelope-from ) id 1bJRPt-0047Ig-6Q; Sat, 02 Jul 2016 21:21:29 +0100 In-Reply-To: <83bn2gtruk.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 02 Jul 2016 10:35:31 +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:120305 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: phillip.lord@russet.org.uk (Phillip Lord) >> Cc: Eli Zaretskii , 23871@debbugs.gnu.org >> Date: Fri, 01 Jul 2016 23:21:01 +0100 >> >> (let ((p (start-process "bc" (current-buffer) "bc"))) >> (process-send-string p "2^10\n") >> (goto-char (point-max))) >> >> The strange thing here is that it's not specifically an undo problem. >> Point doesn't move after eval-defun. > > The problem, AFAIU, is in point movements _during_ eval-defun: they > seem to not be recorded in buffer-undo-list. The undo list I get > after C-M-x is this: > > (nil (117 . 122) (t 22391 27551 0 0)) > So, I don't think this is a regression caused by my patch at all. It is an bug that has been there since I altered undo.c last year. The problem was caused because of undo only records point after a boundary (or the first element). I'd changed things during slightly when I update undo.c so that the timestamp list got added before checking whether I was at a boundary, hence blocking addition of the point restoration information. This is why I found the problem so erratic to replicate; it only occurs immediately the first change to a buffer. I believe the following patch addresses the issue. Phil --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-missing-point-information-in-undo.patch >From d4e9e44402fdf248ba4bc895e914d4cc5580f229 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, and do so unconditionally. (prepare_record): Do not record first change. (record_point): Now conditional on state before the last command. (record_delete): Call record_point unconditionally. Addresses Bug# 21722 --- src/undo.c | 26 +++++++++++++------------- test/automated/simple-test.el | 19 ++++++++++++++++++- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/undo.c b/src/undo.c index be5b270..f5a5ea1 100644 --- a/src/undo.c +++ b/src/undo.c @@ -40,16 +40,13 @@ prepare_record (void) /* Allocate a cons cell to be the undo boundary after this command. */ if (NILP (pending_boundary)) pending_boundary = Fcons (Qnil, Qnil); - - if (MODIFF <= SAVE_MODIFF) - record_first_change (); } /* Record point as it was at beginning of this command. - PT is the position of point that will naturally occur as a result of the + BEG is the position of point that will naturally occur as a result of the undo record that will be added just after this command terminates. */ static void -record_point (ptrdiff_t pt) +record_point (ptrdiff_t beg) { /* Don't record position of pt when undo_inhibit_record_point holds. */ if (undo_inhibit_record_point) @@ -60,13 +57,16 @@ record_point (ptrdiff_t pt) at_boundary = ! CONSP (BVAR (current_buffer, undo_list)) || NILP (XCAR (BVAR (current_buffer, undo_list))); - prepare_record (); + if (MODIFF <= SAVE_MODIFF) + record_first_change (); /* If we are just after an undo boundary, and point wasn't at start of deleted range, record where it was. */ - if (at_boundary) + if (at_boundary + && point_before_last_command_or_undo != beg + && buffer_before_last_command_or_undo == current_buffer ) bset_undo_list (current_buffer, - Fcons (make_number (pt), + Fcons (make_number (point_before_last_command_or_undo), BVAR (current_buffer, undo_list))); } @@ -85,6 +85,8 @@ record_insert (ptrdiff_t beg, ptrdiff_t length) prepare_record (); + record_point (beg); + /* If this is following another insertion and consecutive with it in the buffer, combine the two. */ if (CONSP (BVAR (current_buffer, undo_list))) @@ -163,19 +165,17 @@ record_delete (ptrdiff_t beg, Lisp_Object string, bool record_markers) if (EQ (BVAR (current_buffer, undo_list), Qt)) return; - if (point_before_last_command_or_undo != beg - && buffer_before_last_command_or_undo == current_buffer) - record_point (point_before_last_command_or_undo); + prepare_record (); + + record_point (beg); 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 --=-=-=--