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

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

Hello, Dmitry.

On Tue, Jun 23, 2020 at 20:59:22 +0300, Dmitry Gutov wrote:
> Hi Alan,

> On 23.06.2020 19:28, Alan Mackenzie wrote:

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

> But isn't CC Mode confused by chunks of text with a totally different 
> syntax?

It might well be, probably is.  But this isn't CC Mode we're talking
about - just a tiny part of its low level functionality, namely the bit
dealing with literals and filling them.

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

> > No.  Not without killing its utility as a cache.

> What do you mean? Even if the cache is reset at the beginning of a 
> function, if the function refers to it multiple times, the first time 
> should refill the cache, and the rest of the calls will be able to make 
> use of it properly.

That's what I mean.  The cache persists over commands, reducing the
amount of recalculation needed, particularly for fast typing.  Refilling
it from scratch on every keypress would likely make it sluggish.

Anyhow, it works fine at the moment, so why change it?

[ .... ]

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

> js-mode can be one of its submodes. c-mode as well, but none of CC Mode
> family of major modes ever worked okay with it, I think.

Having several major modes in a single buffer has always been problematic
in Emacs.  Personally, I think there needs to be amendments in the
low-level C code to support it properly, but I'm not able to do this work
on my own, and there doesn't seem to be enough enthusiasm on other
people's part to help out.

> js-mode mostly works, aside from features like this one.

With the current patch, comment filling should work fine in js-mode.

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

> Hopefully, it would make the submode regions inside independent 
> "islands", so to speak. Each of them having its own cache structure 
> (used or not).

Ah, OK.  So, buffer positions would be offsets from the island start, or
something like that.

> TBH I'm not sure if mhtml-mode does the save-and-restore dance which 
> would be necessary for this. mmm-mode does, though.

mhtml-mode does do saving and restoring of local variables.  I can't
judge how well in comparison with, say, mmm-mode.

-- 
Alan Mackenzie (Nuremberg, Germany).