Subject: bug#56682: Fix the long lines font locking related slowdowns

From: Ihor Radchenko <[email-masked]>
Date: Tue, 16 Aug 2022 21:29:20 +0800

Stefan Monnier <[email-masked]> writes:

>>>> There are valid cases when a major mode needs to examine
>>>> the whole buffer.
>>> Not if the whole buffer contains text which the major mode can't
>>> understand.  There are valid cases where a major mode needs to widen,
>>> indeed, but not when called from font-lock or from
>>> `indent-line-function`.
>> `org-indent-line' (the value of `indent-line-function' in Org mode) does
>> require invoking parser in order to determine the syntactic object at
>> point, which, in turn, needs to consider the full buffer contents.
>
> *All* indentation code needs to look at the context.  For that reason
> `indent-according-to-mode` already widens as appropriate before calling
> `indent-line-function`.  For that reason the function placed on
> `indent-line-function` *never* needs to widen (and should never widen).

Then, can Emacs throw an error if widen must not be allowed in certain
scenarios? In complex codebase like Org, we cannot guarantee that some
user-customized function does not widen. Or spurious advice. Debugging
absence of widening somewhere inside deep function calls will be a
nightmare.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92