Subject: bug#25599: Why edit markers after insert?

From: nitish chandra <[email-masked]>
Date: Fri, 10 Mar 2017 01:09:31 +0530

The problem is being caused by insert invalidating some of the markers. So
before adjusting the markers, we can check if the marker is valid or not.
Following is a patch that does this.
From ca02c15de284ed4a62fc6409caf76c3608ca61da Mon Sep 17 00:00:00 2001
From: nitishch <[email-masked]>
Date: Fri, 10 Mar 2017 00:35:14 +0530
Subject: [PATCH] Check for invalid markers after insertion in undo

* lisp/simple.el: When undo-ing a text delete,
adjust the markers only after validating after
insert (Bug#25599)
---
 lisp/simple.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index f110c6f326..122178f767 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2569,8 +2569,12 @@ primitive-undo
                (goto-char pos))
              ;; Adjust the valid marker adjustments
              (dolist (adj valid-marker-adjustments)
-               (set-marker (car adj)
-                           (- (car adj) (cdr adj))))))
+               ;; insert might have invalidated some of the
+               ;; markers. We update only the currently valid
+               ;; markers. See bug#25599
+               (if (marker-buffer (car adj))
+                   (set-marker (car adj)
+                               (- (car adj) (cdr adj)))))))
           ;; (MARKER . OFFSET) means a marker MARKER was adjusted by OFFSET.
           (`(,(and marker (pred markerp)) . ,(and offset (pred integerp)))
            (warn "Encountered %S entry in undo list with no matching (TEXT . POS) entry"
-- 
2.11.0