Subject: Re: bug#58578: 29.0.50; Font lock randomly breaks in some buffers and gets worse over time

From: Eli Zaretskii <[email-masked]>
Date: Mon, 17 Oct 2022 09:42:57 +0300

> From: Stefan Kangas <[email-masked]>
> Date: Mon, 17 Oct 2022 04:40:50 +0000
> 
> I'm seeing broken font lock in long running sessions, seemingly at
> random.  After it goes on for a while, font lock breaks down completely
> in some buffers, and it seemingly gets worse over time.  In some cases,
> the only remedy has been to restart Emacs.
> 
> This has been going on for a couple of weeks at least, and I thought I
> was doing something wrong, so I haven't reported it.  I also haven't
> seriously tried to reproduce it in "emacs -Q", so I've only seen using
> my own init file.  (I haven't made any changes in that configuration
> recently that would obviously relate to font-locking.)
> 
> I've failed at my attempts to understand it, so I hope that someone can
> help me with ideas on how to debug this.  What makes this a bit
> discouraging to debug is that it usually only shows up after more than a
> day of use (sometimes several days, AFAIR), and it's unbearable to work
> in "emacs -Q" for that long.  I also have no idea where to even begin
> looking.
> 
> I have seen it in more than one major mode, both built-in and
> third-party modes (from the top of my head, I've seen it in `c-mode' and
> `org-mode' too).

Some questions/ideas for you:

What happens if you toggle font-lock-mode off and on again in the
affected buffers?  For CC Mode and Org Mode, what happens if you kill
the buffer and revisit the file?

Is it possible that long-line-optimizations-p returns non-nil in the
affected buffers?

Do you see any relevant messages in *Messages* when this happens?

Did you make _any_ changes in your init files lately?  If so, I
suggest to undo them one by one to see if any of them are responsible.