[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Major modes using `widen' is a good, even essential, programming pra

From: Stefan Monnier
Subject: Re: Major modes using `widen' is a good, even essential, programming practice.
Date: Sat, 06 Aug 2022 17:05:24 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

> Narrowing is primarily a user feature.  Users can arbitrarily narrow a
> buffer to ANY contiguous region of text.  So when a major mode needs to
> examine text even slightly distant from point, it MUST widen, to be sure
> that the text to be examined is within the visible region.


> Also, in font locking, a major mode might need to examine text
> arbitrarily far from the fontification region.


But the two cases are quite different: the font-lock case goes through
font-lock, which knows very well that the whole buffer is needed, so *it*
widens, making it unnecessary for the major mode to do so.

The same holds for `indent-line-function` where the generic code widens
before calling that function.

In both cases, it's then very important that the major mode does not
redundantly widen on its own because it's not just redundant but it
breaks those cases where widening is wrong (most commonly because of
something like MMM-mode).

So, yes, calling widen is normal for a command provided by a major mode.
But it's almost always a bug for a major mode function called by
font-lock or by the indentation code.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]