Subject: Re: bug#57804: An infinite loop in a `fontify-region' function causes Emacs to hang indefinitely

From: Paul Pogonyshev <[email-masked]>
Date: Wed, 14 Sep 2022 18:57:23 +0200

> We've previously discussed making a certain key sequence disable font
> locking in a buffer -- or blacklist the particular functions that's
> inflooping somehow.

I think from a user point of view a _special_ sequence is a bad idea,
as most users won't know about it.

Blacklisting I'd say is even worse, because that would mean a user
first have to expirience a hang of Emacs, find out _which_ function
caused it (remember, that Emacs is either unresponsive or is killed by
now), find out that it is possible to blacklist it and do it. Way too
much to expect from a user.

Besides, a function may not be outright malicious, only buggy in
certain corner-cases, so it would be much nicer to be able to
force-abort it when that happens. E.g. in my case this happened in
Logview mode, because it expected `widen' to, well, widen, but Emacs
`master' introduced half-cooked narrowed locking that broke that
expectation and then Logview fell into an infinite loop, because the
buffer was not in the state the mode expected it to be.

> For instance, if the user hits `C-g' three times (and Emacs doesn't idle
> in between), then we disable font-lock in that buffer.

That sounds much better. I know that `C-g' is what to press when Emacs
is stuck.

> There's also `max-redisplay-ticks' -- but I'm not sure that would have
> helped here?

If I add `(setf max-redisplay-ticks 100)' right after entering
`buggy-mode', it seems to have some effect, but not exactly what I'd
hope on. I suggest you try and see for yourself, hard to describe
them.

Paul