Re: Different comment syntaxes in within the same buffer?

Kristoffer Balintona <[email protected]>
Newsgroups gmane.emacs.help
Message-ID <CANVbq5kRcGBd1Y910LZ-uBsfahs1q-RKWYXDipQiTCLqcgrUEg@mail.gmail.com>
On Fri, Apr 10 2026, Stefan Monnier via Users list for the GNU Emacs
text editor wrote:

>> I would like to ask the Lispers here whether there is a good solution
>> for having different comment syntaxes in the same buffer depending on
>> the point's position. For more context, a lot of web templating
>> languages (e.g., Svelte, Astro) have multiple syntaxes in the same file.
>> For example, Astro filles have a "frontmatter" section where JavaScript
>> can go, then after the frontmatter section goes CSS and/or HTML.
>
> Presumably you'd like Emacs to handle correctly not just the comments
> but also the highlighting of the rest, as well as the indentation,
> etc...
>
> IOW, you need a major mode that understands that the file is split into
> several sub parts each one using a different major mode.
> AKA "multi major modes".
>
> There are various packages that provide solutions for that, such as
> `mmm-mode` and `polymode`.
>
> The built-in `mhtml-mode` also does it for the specific case of HTML
> files including CSS and Javascript elements.

My specific case is that I'm using astro-ts-mode[1] for .astro files. So
although it can fontify the buffer just fine, it uses the same syntax
for comments regardless of where I am in it.

(If I could figure out how to have Emacs use a different comment syntax
when appropriate, then I was thinking I could open a PR to the package
maintainer to add the functionality.)

Ideally I'd use the existing astro tree-sitter grammar (rather than
`mmm-mode` or `polymode`, which I'm not familiar with) since it already
does its job well.


Footnotes:
[1]  https://git.isincredibly.gay/srxl/astro-ts-mode
-- 
Kind regards,
Kristoffer
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.