In general, given a major mode with a defined comment syntax, what do I have to define or change to add a new comment syntax? By "adding", I mean setting some new characters so that they
- work with commands such as
- are preserved nicely by
- get in all other ways treated as comments usually work in programming modes, including the proper spacing after the comment string
(Syntax highlighting will be specific to the mode, I guess, but if there is something more general -- please tell.)
Also, of course I'd like to have a function (or functions?) to apply the new comment syntax like with
comment-line, which I can then bind to some keys, without having to implement all by myself, if possible.
There are description of some commands and variables here, but that doesn't answer all questions completely. For examle, some modes seem to include the space after the actual comment character into
comment-start, while others don't -- why? Does it make a difference?
The only similar question I could find was this, but it's a bit more specific, and I don't know really what the provided answers do. For C and C++, there must certainly be a way that handles both
/**/ comments, but that's not elaborated there... Also, I don't want to define a whole new major mode just for comments. This question is close, but unanswered.
My concrete use case: I'm working with julia-mode, where there normally are line comments starting with
#. The syntax handling of that is, I think, defined here by setting
"# " and
"#+\\s-*". What would I have to do to make line comments starting with
#+ be handled the same, preserving the standard comments? (For the curious, these kinds of comments are used in Weave.)
(setq comment-start "#' " comment-start-skip "#+'?\\s-*")
but that doesn't quite do what I want:
comment-linenow inserts comments starting with
#', but I'd like it to keep using standard comments (just
#). It manages to uncomment lines starting with both
fill-paragraphbasically ignores the
', and behaves as with normal
#' bla\n #' blubbecomes
#' bla ' blubinstead of
#' bla blub, while doing the right thing without the single quotes).
What I want is to keep everything related to only
# the same, but respect the compounds
#+ in formatting and uncommenting. And have extra commands to insert them, equivalent to