Subject: bug#52297: 29.0.50; Error in c-force-redisplay timer

From: Alan Mackenzie <[email-masked]>
Date: Wed, 9 Feb 2022 20:06:18 +0000

Hello again, Martin.

On Wed, Feb 09, 2022 at 19:21:20 +0100, martin rudalics wrote:
>  > Thanks.  With that file, I can reproduce the bug.  I'll set about fixing
>  > it.

> TIA, martin

I think the problem is that the buffer wasn't set in the timer function,
so c-force-redisplay was, in the bug scenario, trying to fontify a
spurious buffer.

Would you try out the following patch, please, which fixes this bug.
I'm optimistic it will have fixed the main bug.

Thanks!

diff -r 67fe5c0a9d03 cc-fonts.el
--- a/cc-fonts.el	Mon Jan 31 17:34:20 2022 +0000
+++ b/cc-fonts.el	Wed Feb 09 19:58:26 2022 +0000
@@ -2256,12 +2256,13 @@
 ;; redisplay.
 (defvar c-re-redisplay-timer nil)
 
-(defun c-force-redisplay (start end)
+(defun c-force-redisplay (buffer start end)
   ;; Force redisplay immediately.  This assumes `font-lock-support-mode' is
   ;; 'jit-lock-mode.  Set the variable `c-re-redisplay-timer' to nil.
-  (save-excursion (c-font-lock-fontify-region start end))
-  (jit-lock-force-redisplay (copy-marker start) (copy-marker end))
-  (setq c-re-redisplay-timer nil))
+  (with-current-buffer buffer
+    (save-excursion (c-font-lock-fontify-region start end))
+    (jit-lock-force-redisplay (copy-marker start) (copy-marker end))
+    (setq c-re-redisplay-timer nil)))
 
 (defun c-fontify-new-found-type (type)
   ;; Cause the fontification of TYPE, a string, wherever it occurs in the
@@ -2291,6 +2292,7 @@
 			 (not c-re-redisplay-timer))
 		(setq c-re-redisplay-timer
 		      (run-with-timer 0 nil #'c-force-redisplay
+				      (current-buffer)
 				      (match-beginning 0) (match-end 0)))))))))))
 
 

-- 
Alan Mackenzie (Nuremberg, Germany).