]> git.eshelyaron.com Git - emacs.git/commitdiff
combine-change-calls-1: Fix case where `body` also changes other bufs
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 15 Sep 2022 20:31:00 +0000 (16:31 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Thu, 15 Sep 2022 20:31:18 +0000 (16:31 -0400)
* lisp/subr.el (combine-change-calls-1): Only set the current buffer's part
of the `*-change-functions` hooks.

lisp/subr.el

index 8769fec2b95c21f4ba40a0d5b22995ee3910711c..bfc2e207b2c1c09ab5e32c4e8c7763fa0cd9763b 100644 (file)
@@ -4823,16 +4823,26 @@ the function `undo--wrap-and-run-primitive-undo'."
       (let ((undo--combining-change-calls t))
        (if (not inhibit-modification-hooks)
            (run-hook-with-args 'before-change-functions beg end))
-       (let (;; (inhibit-modification-hooks t)
-              (before-change-functions
-               ;; Ugly Hack: if the body uses syntax-ppss/syntax-propertize
-               ;; (e.g. via a regexp-search or sexp-movement triggering
-               ;; on-the-fly syntax-propertize), make sure that this gets
-               ;; properly refreshed after subsequent changes.
-               (if (memq #'syntax-ppss-flush-cache before-change-functions)
-                   '(syntax-ppss-flush-cache)))
-              after-change-functions)
-         (setq result (funcall body)))
+       (let ((bcf before-change-functions)
+             (acf after-change-functions)
+             (local-bcf (local-variable-p 'before-change-functions))
+             (local-acf (local-variable-p 'after-change-functions)))
+         (unwind-protect
+              ;; FIXME: WIBNI we could just use `inhibit-modification-hooks'?
+              (progn
+                ;; Ugly Hack: if the body uses syntax-ppss/syntax-propertize
+                ;; (e.g. via a regexp-search or sexp-movement triggering
+                ;; on-the-fly syntax-propertize), make sure that this gets
+                ;; properly refreshed after subsequent changes.
+               (setq-local before-change-functions
+                            (if (memq #'syntax-ppss-flush-cache bcf)
+                                '(syntax-ppss-flush-cache)))
+                (setq-local after-change-functions nil)
+               (setq result (funcall body)))
+           (if local-bcf (setq before-change-functions bcf)
+             (kill-local-variable 'before-change-functions))
+           (if local-acf (setq after-change-functions acf)
+             (kill-local-variable 'after-change-functions))))
         (when (not (eq buffer-undo-list t))
           (let ((ap-elt
                 (list 'apply