Different comment syntaxes in within the same buffer?

Kristoffer Balintona <[email protected]>
Newsgroups gmane.emacs.help
Message-ID <CANVbq5kamRgW=L16NStFsQoYWBvABsgVUWrvq6f7s6Q4fkRYtQ@mail.gmail.com>
Hello,

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.

Detecting which comment syntax corresponds to the current buffer
position is no problem. What I'm wondering is whether there's a way to
dispatch to one comment syntax to another based on where one is in the
buffer, ideally without straying to far from the existing comment
variables afforded to major modes.

The only solution I've come up with is remapping the comment commands
('comment-line' and 'comment-dwim') to custom versions. But I was hoping
for a"cleaner" solution, if it exists,

-- 
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.