GNU bug report logs - #41897
28.0.50; JavaScript comment filling with mhtml-mode

Previous Next

Package: emacs;

Reported by: Simen Heggestøyl <simenheg <at> runbox.com>

Date: Tue, 16 Jun 2020 17:10:01 UTC

Severity: normal

Found in version 28.0.50

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 41897 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Simen Heggestøyl <simenheg <at> runbox.com>
Cc: acm <at> muc.de, 41897 <at> debbugs.gnu.org
Subject: Re: bug#41897: 28.0.50; JavaScript comment filling with mhtml-mode
Date: 20 Jun 2020 17:18:27 -0000
Hello, Simen.

In article <mailman.1991.1592327403.2541.bug-gnu-emacs <at> gnu.org> you wrote:
> In js-mode, the following JavaScript comment is filled as expected when
> fill-paragraph (M-q) is used with point within it:

> /*
>  * This is a long comment that should break over multiple lines when fill-paragraph is used.
>  */

> Is filled as:

> /*
>  * This is a long comment that should break over multiple lines when
>  * fill-paragraph is used.
>  */

> In mhtml-mode however, the same JavaScript comment:

> <html>
>   <script>
>     /*
>      * This is a long comment that should break over multiple lines when fill-paragraph is used.
>      */
>   </script>
> </html>

> Is filled as:

> <html>
>   <script>
>     /* * This is a long comment that should break over multiple lines
>      when fill-paragraph is used.  */
>   </script>
> </html>

Yes.  This is happening because the mechanism mhtml-mode is using to
"switch to" js-mode is imperfect.  Having more than one major mode in a
buffer is a difficult problem for Emacs, and there are currently no
really satisfactory solutions.

"Switching to" another mode essentially means setting buffer local
variable copies.  In the existing code, a variable essential to filling,
adaptive-fill-regexp, isn't getting set to a value suitable for js-mode.

Also, there was an error in the js-mode setting of the variable
comment-start-skip.

The patch below fixes both these errors, and seems to allow your test
case to work.  However, it is an incomplete solution - in particular,
filling caused by typing at the end of a long line still isn't working
properly.  Still, it may be better than nothing, at least for now.  I
intend to carry on working on this bug.

You haven't said what version of Emacs you're running.  The patch
applies cleanly both to the upcoming emacs-27 branch and the master
branch at GNU savannah.  To apply it, cd into ..../emacs/lisp, and
execute:

    $ patch -p2 < this-email

.  Then byte-compile the two changed files and load them (possibly by
restarting Emacs).

Here's the patch:



diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 04b449ecd2..f5b6a4c260 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -4570,7 +4570,7 @@ js-mode
 
   ;; Comments
   (setq-local comment-start "// ")
-  (setq-local comment-start-skip "\\(//+\\|/\\*+\\)\\s *")
+  (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
   (setq-local comment-end "")
   (setq-local fill-paragraph-function #'js-fill-paragraph)
   (setq-local normal-auto-fill-function #'js-do-auto-fill)
diff --git a/lisp/textmodes/mhtml-mode.el b/lisp/textmodes/mhtml-mode.el
index 1ae07c0a30..069329f4e4 100644
--- a/lisp/textmodes/mhtml-mode.el
+++ b/lisp/textmodes/mhtml-mode.el
@@ -73,7 +73,8 @@ mhtml-tag-relative-indent
 
 (defconst mhtml--crucial-variable-prefix
   (regexp-opt '("comment-" "uncomment-" "electric-indent-"
-                "smie-" "forward-sexp-function" "completion-" "major-mode"))
+                "smie-" "forward-sexp-function" "completion-" "major-mode"
+                "adaptive-fill-" "fill-"))
   "Regexp matching the prefix of \"crucial\" buffer-locals we want to capture.")
 
 (defconst mhtml--variable-prefix


-- 
Alan Mackenzie (Nuremberg, Germany).





This bug report was last modified 5 years and 42 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.