From c99815fffad7a320c35a516548fd67fedaf0e732 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 15 Sep 2022 16:31:00 -0400 Subject: [PATCH] combine-change-calls-1: Fix case where `body` also changes other bufs * lisp/subr.el (combine-change-calls-1): Only set the current buffer's part of the `*-change-functions` hooks. --- lisp/subr.el | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lisp/subr.el b/lisp/subr.el index 8769fec2b95..bfc2e207b2c 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -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 -- 2.39.2