Sublime Forum

In PHP, different color coding for different comment types

#1

Hey all,

Glad to see the Sublime 3 development rolling along.

In my work environment, we tend to use two of the PHP comment tag styles in different ways. We will usually use double-slash (//) to indicate a removed piece of code, whereas we’ll use the hash mark (#) for a one-line comment.

So, if you have something like this…

# This code is meant to amuse yet frighten players echo 'It is pitch black. You are likely to be eaten by a grue.'; // echo 'All your base are belong to us';

Ideally I would pick a very muted color for the ‘//’ comments but perhaps something more visible for the '#'s.

I think the color-themes assign both of these (// and #) as “comments”, so color changes impact both. Would the trick be to find where ‘//’ and ‘#’ were defined, give them their own names (‘comment-details’ verses ‘comment-deactivate’) and then be able to assign different colors for each (when using PHP)?

Thanks,
Roy

0 Likes

#2

You have scopes for each comment type!:

  1. comment.block.php /* */
  2. comment.line.double-slash.php //
  3. comment.line.number-sign.php #

Just add this into your theme file and update colors (hint: search for comment in existing theme, to nicely group stuff together)

<dict>
  <key>name</key>
  <string>Block Comment</string>
  <key>scope</key>
  <string>comment.block.php</string>
  <key>settings</key>
  <dict>
    <key>foreground</key>
    <string>#CC0000</string>
  </dict>
</dict>

<dict>
  <key>name</key>
  <string>Slash Comment</string>
  <key>scope</key>
  <string>comment.line.double-slash.php</string>
  <key>settings</key>
  <dict>
    <key>foreground</key>
    <string>#00CC00</string>
  </dict>
</dict>

<dict>
  <key>name</key>
  <string>Hash Comment</string>
  <key>scope</key>
  <string>comment.line.number-sign.php</string>
  <key>settings</key>
  <dict>
    <key>foreground</key>
    <string>#0000CC</string>
  </dict>
</dict>
0 Likes