Sublime Forum

Comment line for GLSL syntax

#1

Good day :3
My Sublime Text version is 3.2.2

I am used to Ctrl+/ shortcut to comment selected line(s) in sublime for a bunch of languages: C++, C#, Lua, js, md files, python, git config, json… All work just fine from the box, without additional tune-up.

But there is one language with what it fails: GLSL shader files. Personally I name those files with .frag .vert or .glsl extensions. Syntax highlight works fine in those files. But Ctrl+/ does not do anything =( If I save those files as, for example, .cpp file, then syntax highlight (as this is close to C++) is fine and Ctrl+/ works fine, but it is not the way…

At the moment I am tired of printing and deleting double slashes // myself :slight_smile: Is there a way to tune up my siblime to do that for me? Or maybe there is “half measure” workaround to somehow tell sublime that .glsl files belong to C++ syntax?

0 Likes

#2

Commenting support requires that the syntax author provides extra metadata to tell Sublime how to comment things, so it sounds like the package that’s providing that syntax doesn’t have that.

Not worry though because you can add it yourself.

The first thing you want to do is open up a GLSL file using it’s own syntax, and then use Tools > Developer > Show Scope Name and make a note of the first line in the popup; that is the scope that uniquely identifies this type of file.

Next, create a file named glslComments.tmPreferences in your User package (only the extension really matters, and you can use Preferences > Browse Packages to find the User package if you don’t know where it is).

In the file, put the following content, but replace the GLSL_SCOPE_HERE with the one that you got from the popup above, then save the file.

As soon as you save the file, you should see the Sublime console tell you that it is generating meta info summary; if you see that, you should be good to go.

if you don’t see the text, double check the location and name of the file; if it’s in the wrong place or doesn’t have that extension, Sublime doesn’t know what to do with it.

The metainformation here is a duplicate of that used for C/C++ ; you can extend it as needed if there are other ways to comment, etc.

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Comments</string>
    <key>scope</key>
    <string>GLSL_SCOPE_HERE</string>
    <key>settings</key>
    <dict>
        <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>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_DISABLE_INDENT_2</string>
                <key>value</key>
                <string>yes</string>
            </dict>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_START_3</string>
                <key>value</key>
                <string>/// </string>
            </dict>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_START_4</string>
                <key>value</key>
                <string>//! </string>
            </dict>
        </array>
    </dict>
</dict>
</plist>
1 Like

#3

Are you using this syntax package?

https://packagecontrol.io/packages/OpenGL%20Shading%20Language%20(GLSL)

It should already have support for comments.

0 Likes

#4

Solution with that package worked! Thank you :slight_smile:

But I also wanted to check the .tmPreferences file solution.
And I did it today, it worked too =)
Thank you, it is nice to know that way!

0 Likes