From 24c1c877cf2c06faffa55d5f3a5d488a0067ad35 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Sun, 24 Apr 2022 18:01:43 +0800 Subject: [PATCH] org-fold-core-fontify-region: Calculate jit-lock-bounds accurately * lisp/org-fold-core.el (org-fold-core-fontify-region): Collect all the return values of `font-lock-default-fontify-region' on visible regions and extend jit-lock-bounds accordingly. --- lisp/org-fold-core.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lisp/org-fold-core.el b/lisp/org-fold-core.el index 4056ae004..6786009ec 100644 --- a/lisp/org-fold-core.el +++ b/lisp/org-fold-core.el @@ -1467,7 +1467,16 @@ folded regions.") (< next end)) (setq next (org-fold-core-next-folding-state-change nil next end)))) (save-excursion - (setq font-lock-return-value (font-lock-default-fontify-region pos next loudly)) + ;; Keep track of the actually fontified region. + (pcase (font-lock-default-fontify-region pos next loudly) + (`(jit-lock-bounds ,beg . ,end) + (pcase font-lock-return-value + (`(jit-lock-bounds ,oldbeg . ,oldend) + (setq font-lock-return-value + `(jit-lock-bounds + ,(min oldbeg beg) + ,(max oldend end)))) + (value (setq font-lock-return-value value))))) (save-match-data ;; Only run within regions that are not yet touched by ;; fontification.