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

From: Eli Zaretskii <[email-masked]>
Date: Wed, 14 Sep 2022 21:18:33 +0300

> Cc: [email-masked], Paul Pogonyshev <[email-masked]>
> From: Lars Ingebrigtsen <[email-masked]>
> Date: Wed, 14 Sep 2022 19:52:45 +0200
> 
> So I think there's scope for us to do something practical here with this
> annoying problem.  It's hard enough to develop font locking code without
> Emacs suddenly (and unbreakably) hanging on you when you've typed in
> some buggy code.

Just run your development version under a debugger, and you will
always be able to interrupt any loop, anywhere.

And I think you greatly underestimate the conceptual difficulty here.
Your conclusions are specific to this toy program.  But in real-life
use cases, it is entirely unclear how to handle this:

  . the fact that redisplay is called several times in a row doesn't
    necessarily mean we have a bug, there are packages out there which
    cause that due to stuff they do in various hooks (like linum.el,
    which moves overlays etc.)
  . the buggy code could be in some function registered with jit-lock
    or run from some hook invoked by redisplay that have nothing to do
    with font-lock, in which case turning off font-lock will not solve
    anything

IOW, the general solution to this is not apparent, and I'm not sure it
exists, the only solution I'm aware of is to run unstable code under a
debugger.