From: Alan Mackenzie <acm@muc.de>
To: "Simen Heggestøyl" <simenheg@runbox.com>
Cc: acm@muc.de, 41897@debbugs.gnu.org
Subject: bug#41897: 28.0.50; JavaScript comment filling with mhtml-mode
Date: 20 Jun 2020 17:18:27 -0000 [thread overview]
Message-ID: <20200620171827.7855.qmail@mail.muc.de> (raw)
In-Reply-To: <mailman.1991.1592327403.2541.bug-gnu-emacs@gnu.org>
Hello, Simen.
In article <mailman.1991.1592327403.2541.bug-gnu-emacs@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).
next parent reply other threads:[~2020-06-20 17:18 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <874krbaqg3.fsf@simenheg@gmail.com>
[not found] ` <mailman.1991.1592327403.2541.bug-gnu-emacs@gnu.org>
2020-06-20 17:18 ` Alan Mackenzie [this message]
2020-06-20 18:27 ` bug#41897: 28.0.50; JavaScript comment filling with mhtml-mode Simen Heggestøyl
[not found] ` <87d05ta8z9.fsf@simenheg@gmail.com>
2020-06-21 16:55 ` Alan Mackenzie
2020-06-22 19:17 ` Alan Mackenzie
2020-06-23 0:02 ` Dmitry Gutov
2020-06-23 8:36 ` Alan Mackenzie
2020-06-23 14:23 ` Dmitry Gutov
2020-06-23 16:28 ` Alan Mackenzie
2020-06-23 17:59 ` Dmitry Gutov
2020-06-23 19:17 ` Alan Mackenzie
2020-06-23 23:11 ` Dmitry Gutov
2020-06-24 17:43 ` Alan Mackenzie
2020-06-24 18:28 ` Dmitry Gutov
2020-06-25 16:33 ` Alan Mackenzie
2020-06-25 16:48 ` Dmitry Gutov
2020-06-25 18:07 ` Alan Mackenzie
2020-06-25 18:19 ` Dmitry Gutov
2020-06-25 19:13 ` Alan Mackenzie
2020-06-25 19:28 ` Dmitry Gutov
2020-06-25 20:11 ` Alan Mackenzie
2020-06-25 21:20 ` Dmitry Gutov
2020-06-27 11:06 ` Alan Mackenzie
2020-06-28 0:18 ` Dmitry Gutov
2020-06-25 20:53 ` Tom Tromey
2020-06-25 21:14 ` Dmitry Gutov
2020-06-26 16:31 ` Alan Mackenzie
2020-06-25 20:49 ` Tom Tromey
2020-06-26 16:46 ` Alan Mackenzie
2020-07-04 13:13 ` Alan Mackenzie
2020-06-16 17:08 Simen Heggestøyl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200620171827.7855.qmail@mail.muc.de \
--to=acm@muc.de \
--cc=41897@debbugs.gnu.org \
--cc=simenheg@runbox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.