Sublime Forum

Toggle comments does not work for custom languages

#1

Toggling comments does not work when using custom languages which are derived from standard languages.

I’m using the Seti_UI theme which adds icons for some specific files, e.g. Gruntfile.js which has a different icon than normal JavaScript files. This way you can find relevant files more quickly.

In Seti_Ui there are the .tmLanguage and .tmPreferences files:

You can see that the file type extends source.js.

When opening a Gruntfile.js the syntax highlighting is set to Gulpfile JS, not JavaScript. Commenting lines using the toggle_comment command does not work in this case.

After setting the syntax highlighting to JavaScript, everything works fine.

1 Like

#2

I just found out that the language file needs to define the way comments are handled. It works for me now.

Anyway, I think that behavior could be inherited from the original language, i.e. JavaScript.

The working version for icon_gruntfile.tmPreferences looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>scope</key>
        <string>source.gruntfile</string>
        <key>settings</key>
        <dict>
            <key>icon</key>
            <string>file_type_gruntfile</string>
            <key>shellVariables</key>
            <array>
              <dict>
                <key>name</key>
                <string>TM_COMMENT_START</string>
                <key>value</key>
                <string>// </string>
              </dict>
              <dict>
                <key>name</key>
                <string>TM_COMMENT_START_2</string>
                <key>value</key>
                <string>/*</string>
              </dict>
              <dict>
                <key>name</key>
                <string>TM_COMMENT_END_2</string>
                <key>value</key>
                <string>*/</string>
              </dict>
            </array>
        </dict>
    </dict>
</plist>
2 Likes

#3

That would be the case if the Gruntfile syntax defined its base scope as source.js.gruntfile instead of source.gruntfile, because then all the settings applying to JavaScript files (i.e. comment markers) apply to the gruntfile too.

1 Like

#4

I didn’t know that. It worked. Thanks a lot!

0 Likes