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

From: Lars Ingebrigtsen <[email-masked]>
Date: Wed, 14 Sep 2022 18:41:53 +0200

Paul Pogonyshev <[email-masked]> writes:

> C-g doesn't help anymore. The only thing you can do is to kill and start Emacs anew.

[...]

> (define-derived-mode buggy-mode nil "buggy"
>   (setf font-lock-defaults '(nil nil t nil (font-lock-fontify-region-function . buggy-fontifier)))
>   (font-lock-mode 1))
>
> (defun buggy-fontifier (start end loudly)
>   (add-face-text-property start (min (+ start 15) end) 'bold)
>   (while t
>     "whoopsie")
>   nil)

Yes, it's really unfortunate that you can't get out of errors like this
without killing Emacs.

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

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.

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