I'm developing a major mode for a language that has doc comments. They look like this:
(** Foos three bars.
Better call this as [foo 1 b c].
Though of course [foo a b 1] works as well. **)
Definition foo a b c := a + b - c.
In that context [
and ]
work as sorts of unescapes: anything between them is really code, not comments.
Is there a generic approach this? IOW, is there a way to tell font-lock: in comments, treat anything between []
as code?
I can see a bunch of cool applications for this beyond my major mode: for example doctests in python (where >>>
should introduce code), or javadoc, or doxygen, etc.
"""Foos the bars
>>> foo 1 2 3 # should be highlighted as code
0
>>> foo 4 5 6 # should be highlighted as code
3"""
I considered making [
a comment closer, and ]
a comment opener, but it looks very brittle: it will confuse navigation commands, and nested comments, and will require a strange comment setup to allow multiple closers per opener; and it won't work outside of comments, either.