all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: phillip.lord@russet.org.uk (Phillip Lord)
To: Eli Zaretskii <eliz@gnu.org>
Cc: 23871@debbugs.gnu.org, Markus Triska <triska@metalevel.at>
Subject: bug#23871: 25.1.50; Undo unexpectedly leads to blank buffer
Date: Fri, 01 Jul 2016 15:04:32 +0100	[thread overview]
Message-ID: <878txlsbdb.fsf@russet.org.uk> (raw)
In-Reply-To: <834m89vmyv.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 01 Jul 2016 10:25:44 +0300")

[-- Attachment #1: Type: text/plain, Size: 1202 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-missing-point-information-in-undo.patch --]
[-- Type: text/x-diff, Size: 3185 bytes --]

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	other threads:[~2016-07-01 14:04 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-29 21:47 bug#23871: 25.1.50; Undo unexpectedly leads to blank buffer Markus Triska
2016-06-30 16:38 ` Eli Zaretskii
2016-06-30 18:00   ` Markus Triska
2016-06-30 18:21     ` Eli Zaretskii
2016-06-30 18:52       ` Eli Zaretskii
2016-06-30 21:45     ` Phillip Lord
2016-07-01  6:31       ` Markus Triska
2016-07-01  7:25         ` Eli Zaretskii
2016-07-01 14:04           ` Phillip Lord [this message]
2016-07-01 20:38             ` Markus Triska
2016-07-01 22:12               ` Phillip Lord
2016-07-01 20:49             ` Markus Triska
2016-07-01 22:21               ` Phillip Lord
2016-07-02  5:35                 ` Markus Triska
2016-07-02  7:35                 ` Eli Zaretskii
2016-07-02 20:21                   ` Phillip Lord
2016-07-02 20:53                     ` Markus Triska
2016-07-03  3:33                       ` Eli Zaretskii
2016-07-03  9:37                       ` Phillip Lord
2016-07-03 10:08                         ` Markus Triska
2016-07-03 12:55                           ` Phillip Lord
2016-07-03 15:30                             ` Eli Zaretskii
2016-07-03 20:21                               ` Phillip Lord
2016-07-03 18:05                             ` Markus Triska
2016-07-03 20:23                               ` Phillip Lord
2016-07-03 22:03                                 ` Markus Triska
2016-07-04 14:38                                   ` Eli Zaretskii
2016-07-05 16:36                                     ` Eli Zaretskii
2016-07-05 19:44                                       ` Phillip Lord
2016-07-05 20:02                                         ` Markus Triska
2016-07-05 19:47                                       ` Markus Triska
2016-07-05 20:00                                         ` Eli Zaretskii
2016-07-03 15:12                           ` Eli Zaretskii
2016-07-03 18:09                             ` Markus Triska
2016-07-03 19:20                               ` Eli Zaretskii
2016-07-03 20:37                             ` Phillip Lord
2016-07-03  3:31                     ` Eli Zaretskii
2016-07-03  9:39                       ` Phillip Lord
2016-07-03 21:33                     ` Stefan Monnier
2016-07-04 20:34                       ` Phillip Lord
2016-07-04 21:32                         ` Stefan Monnier
2016-07-05  8:43                           ` Phillip Lord
2016-07-05 20:32                             ` Markus Triska
2016-07-05 22:00                               ` Stefan Monnier
2016-07-05 22:17                                 ` Phillip Lord
2016-07-05 22:09                               ` Phillip Lord
2016-07-05 23:03                                 ` Markus Triska
2016-07-06 16:02                                   ` Phillip Lord
2016-07-06 17:59                                     ` Markus Triska
2016-08-12 23:03                                 ` npostavs
2016-08-13  8:02                                   ` Markus Triska
2016-07-05  8:46                           ` undo refactoring Phillip Lord
2016-07-05 21:50                             ` Stefan Monnier
2016-07-05 22:22                               ` Phillip Lord

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878txlsbdb.fsf@russet.org.uk \
    --to=phillip.lord@russet.org.uk \
    --cc=23871@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=triska@metalevel.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.