How to add both inline and block comments for new C-like language?


#1

In TextMate/Sublime Text, I added both inline and block comment support to a custom language bundle using the following config:

{    shellVariables = (
        {    name = 'TM_COMMENT_START';
            value = '// ';
        },
        {    name = 'TM_COMMENT_START_2';
            value = '/*';
        },
        {    name = 'TM_COMMENT_END_2';
            value = '*/';
        },
        {    name = 'TM_COMMENT_DISABLE_INDENT_2';
            value = 'yes';
        },
    );
}

This enables the following shortcuts:

TextMate > Bundles > Source > Comments > Comment Line
Sublime Text > Edit > Comment > Toggle Comment

  • Ctrl+/ (On Windows and Linux)
  • Command ⌘+/ (On Mac)

TextMate > Bundles > Source > Comments > Insert Block Comment
Sublime Text > Edit > Comment > Toggle Block Comment

  • Ctrl+Shift+/ (On Windows and Linux)
  • Command ⌘+Alt+/ (On Mac)

When I converted the bundle using the Atom --convert option, the resulting output was missing the block comment support:

".source.nesc":
  editor:
    commentStart: "// "

What’s the best way to support /* --- */ and // comments in a new C-like language package in Atom?


#2

I believe Atom only supports line or block comments depending on what is listed in the language definition. It has been a while since I’ve delved into the code for this behavior though.


#3

It would be great to toggle block comments, not just line comments. For example, suppose I write

class Foo extends Bar {
  @override|
  someMethod() {}
}

where the | shows the cursor position. I’d like to toggle a block comment on that line so that it becomes

class Foo extends Bar {
  /**
   * @override|
   */
  someMethod() {}
}