From 532b7bade61503c922d7169b0aab08c60a0c8fc0 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 15 Apr 2024 16:06:54 -0400 Subject: [PATCH] (track-changes-fetch): Fix nested use case * 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 | 38 ++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lisp/emacs-lisp/track-changes.el b/lisp/emacs-lisp/track-changes.el index df4aad0d596..9e62b8bdf30 100644 --- a/lisp/emacs-lisp/track-changes.el +++ b/lisp/emacs-lisp/track-changes.el @@ -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. -- 2.39.5