Hi Alan, thanks for working on this. Alan Mackenzie writes: > The patch below fixes both these errors, and seems to allow your test > case to work. Yes, this seems to fix it in both emacs-27 and master, thanks. However in emacs-27 with the patch applied I now get a strange side-effect: After filling the comment, mhtml-mode seems to lose track of where the JavaScript portion of the buffer is. Please see the attached image. The position where point is should still be recognized as HTML+JS, but it's recognized as plain HTML+ instead after filling. This doesn't happen on master. > You haven't said what version of Emacs you're running. I put the version number in the bug subject but forgot to mention it in the description, sorry about that. -- Simen