bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#23871: 25.1.50; Undo unexpectedly leads to blank buffer


From: Phillip Lord
Subject: bug#23871: 25.1.50; Undo unexpectedly leads to blank buffer
Date: Fri, 01 Jul 2016 15:04:32 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.95 (gnu/linux)

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Markus Triska <triska@metalevel.at>
>> Cc: Eli Zaretskii <eliz@gnu.org>,  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.

>From 906a5affc1fc04a9d1d3efffb7d5bfc21e6c2e44 Mon Sep 17 00:00:00 2001
From: Phillip Lord <phillip.lord@russet.org.uk>
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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]