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

From: Alan Mackenzie <[email-masked]>
Date: Tue, 23 Jun 2020 08:36:13 +0000

Hello, Dmitry.

On Tue, Jun 23, 2020 at 03:02:48 +0300, Dmitry Gutov wrote:
> Hi Alan,

> On 22.06.2020 22:17, Alan Mackenzie wrote:
> > +(defun c-foreign-truncate-lit-pos-cache (beg _end)
> > +  "Truncate CC Mode's literal cache.
> > +
> > +This function should be added to the `before-change-functions'
> > +hook by major modes that use CC Mode's filling functionality
> > +without initializing CC Mode.  Currently (2020-06) these are
> > +js-mode and mhtml-mode."
> > +  (c-truncate-lit-pos-cache beg))

> Could you explain this part?

> Is that literal cache looked up once during filling, or is it used 
> multiple times during the execution of c-fill-paragraph?

It's used several times during each filling operation.  This cache
persists between commands, too.

> 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.

> 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.

-- 
Alan Mackenzie (Nuremberg, Germany).