Subject: Re: bug#41897: 28.0.50; JavaScript comment filling with mhtml-mode

From: Alan Mackenzie <[email-masked]>
Date: Tue, 23 Jun 2020 16:28:37 +0000

Hello, Dmitry.

On Tue, Jun 23, 2020 at 17:23:53 +0300, Dmitry Gutov wrote:
> On 23.06.2020 11:36, Alan Mackenzie wrote:

> >> If the latter (and it does serve as a cache this way), perhaps it
> >> could be cleared once, at the beginning of c-fill-paragraph, instead
> >> of adding a runtime cost to every edit?

> > The cost is tiny.  c-truncate-lit-pos-cache is a defsubst which does
> > nothing but three copies of

> >      (setq cache-limit (min beg cache-limit))

> > .  All the intricacies of manipulating the cache take place whilst it
> > is being used.

> >> Or if that's undesirable, js-fill-paragraph could do that.

> > No, it really has to be in a before-change-functions function, to
> > keep track of the bound of the valid cache.

> So it's really fine if it's called from HTML/CSS hunks as well?

Not only fine, but necessary.  The literal cache contains entries that
record things like "C comment between positions 23 and 130".  If somebody
inserts text before that comment, or inside of it, that cache entry is no
longer valid, and must be invalidated.  Hence the necessity of the
before-change function.

> And there's no way to just "reset" it to an appropriate value?

No.  Not without killing its utility as a cache.

> >> This way, I think it would automatically make it compatible with
> >> mmm-mode. Or at least more compatible.

> > Maybe putting the two c-foreign-* functions into mmm-mode would work.

> mmm-mode is a minor mode, it doesn't always deal with CC Mode.

The question to consider here is whether any sub-mode of mmm-mode uses CC
Mode's comment filling without initialising CC Mode.  js-mode and
mhtml-mode do this.

> And its configurations don't usually result in new major modes either.

> I wouldn't say it's very hard to make it work, but I don't see a "neat" 
> way to do either.

OK.

> Have you considered adding variables that hold the cache to 
> mhtml--crucial-variable-prefix as well? Would that make it work?

Not without the before-change function, no.  I'm trying to see what the
point of putting these variables into mhtml's crucial variables would be.

-- 
Alan Mackenzie (Nuremberg, Germany).