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

From: Alan Mackenzie <[email-masked]>
Date: Sat, 27 Jun 2020 11:06:48 +0000

Hello, Dmitry.

On Fri, Jun 26, 2020 at 00:20:07 +0300, Dmitry Gutov wrote:
> On 25.06.2020 23:11, Alan Mackenzie wrote:

> > Sluggish performance isn't about "usually" and 98% of the time; it's
> > about unusual constellations and the other 2%.

> Still, a slow-ish fill-paragraph is nowhere near as bad as, say, 
> slowdown during typing.

We're talking about a long pause at the end of each line when typing in
a longish block comment whilst auto-fill-mode is enabled.

> >>> Then why not do in mmm-mode what I'm doing in CC Mode, mhtml-mode and
> >>> js-mode, i.e. add ad hoc code to handle precisely the case of js-mode?

> >> That would be something every user that configures a submode class using
> >> js-mode have to be aware of. That's not easy to document, or even if we
> >> made sure it's documented, to be sure that users read it.

> > Are you telling me that mmm-mode couldn't keep a watch out for js-mode,
> > leaving other libraries untroubled?  Again, the trouble here appears to
> > arise from using something (a mode) without first initialising it.

> Sounds like special-casing js-mode, before-change-functions and this 
> particular function all together. Basically, like a magic constant in 
> the code.

> This is ultimately doable, but I'm not sure how to write a patch for it 
> which wouldn't leave me feeling dirty after.

If I understand correctly, there is already special case code for js-mode
anyway, in mmm-erb.el.  The :creation-hook for js-mode is currently set
to mmm-erb-mark-as-special, a function shared with ruby-mode.

Would it really be all that distressing to write a new :creation-hook for
js-mode which additionally initialises the part of CC Mode which needs
it?  We'd be talking about something like

    (defun mmm-js-init ()
      "Doc string."
      (overlay-put mmm-current-overlay 'mmm-special-tag t)
      (c-foreign-init-lit-pos-cache)
      (add-hook 'before-change-functions #'c-foreign-truncate-lit-pos-cache nil t))

.  Would that really be so bad?  It would even be possible to move the
explicit add-hook into a small function in CC Mode and call that instead.
But I think it's better to see the add-hook where it might make a
difference.

That's all assuming I've understood mmm-mode properly.

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).