]> git.eshelyaron.com Git - emacs.git/commitdiff
(track-changes-fetch): Fix nested use case
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 15 Apr 2024 20:06:54 +0000 (16:06 -0400)
committerEshel Yaron <me@eshelyaron.com>
Sat, 20 Apr 2024 11:01:34 +0000 (14:01 +0300)
* lisp/emacs-lisp/track-changes.el (track-changes-fetch):
Don't presume that if there's nothing to do we're on
`track-changes--clean-trackers`.

(cherry picked from commit 3ac1a7b6fe6d324339ca5c36ffdce3985f6c55a1)

lisp/emacs-lisp/track-changes.el

index df4aad0d59630e59040092f5ba897135fef70216..9e62b8bdf3034ea741ae2c4dab3eb2928b1072a2 100644 (file)
@@ -335,23 +335,27 @@ and re-enable the TRACKER corresponding to ID."
                             (substring before (- (length before)
                                                  (- endb prevend)))))
               (setq lenbefore (length before)))))))
-    (if (null beg)
-        (progn
-          (cl-assert (null states))
-          (cl-assert (memq id track-changes--clean-trackers))
-          (cl-assert (eq (track-changes--tracker-state id)
-                         track-changes--state))
-          ;; Nothing to do.
-          nil)
-      (cl-assert (not (memq id track-changes--clean-trackers)))
-      (cl-assert (<= (point-min) beg end (point-max)))
-      ;; Update the tracker's state *before* running `func' so we don't risk
-      ;; mistakenly replaying the changes in case `func' exits non-locally.
-      (setf (track-changes--tracker-state id) track-changes--state)
-      (unwind-protect (funcall func beg end (or before lenbefore))
-        ;; Re-enable the tracker's signal only after running `func', so
-        ;; as to avoid recursive invocations.
-        (cl-pushnew id track-changes--clean-trackers)))))
+    (unwind-protect
+        (if (null beg)
+            (progn
+              (cl-assert (null states))
+              ;; We may have been called in the middle of another
+              ;; `track-changes-fetch', in which case we may be in a clean
+              ;; state but not yet on `track-changes--clean-trackers'
+              ;;(cl-assert (memq id track-changes--clean-trackers))
+              (cl-assert (eq (track-changes--tracker-state id)
+                             track-changes--state))
+              ;; Nothing to do.
+              nil)
+          (cl-assert (not (memq id track-changes--clean-trackers)))
+          (cl-assert (<= (point-min) beg end (point-max)))
+          ;; Update the tracker's state *before* running `func' so we don't risk
+          ;; mistakenly replaying the changes in case `func' exits non-locally.
+          (setf (track-changes--tracker-state id) track-changes--state)
+          (funcall func beg end (or before lenbefore)))
+      ;; Re-enable the tracker's signal only after running `func', so
+      ;; as to avoid recursive invocations.
+      (cl-pushnew id track-changes--clean-trackers))))
 
 ;;;; Auxiliary functions.