0

I would like to have the text TODO: as a different color within the comments for any language. I use the keyword TODO: with the packages TODOreview and SublimeLinter-annotations and It would be nice to differentiate the word TODO: from other comments.

I've tried the following regex for C++.tmLanguage with no success. And scoping the regex with comment.todo within the tmTheme

/\/\/.*?(TODO:)/
(TODO:)
(?:\#|\/\/)[^\n\r]TODO:(?<![\?>])
/TODO:(?<![\?>])/

Full example:

C++.tmLanguage
<dict>
    <key>match</key>
    <string>(\/\/.)*?(TODO:)</string>
    <key>name</key>
    <string>comment.todo</string>
</dict>

theme.tmTheme
<dict>
    <key>name</key>
    <string>Comment Todo</string>
    <key>scope</key>
    <string>comment.todo</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#9B859D</string>
    </dict>
</dict>
moonman
  • 51
  • 1
  • 6

1 Answers1

0

Thats not how syntax definition work in SublimeText and Textmate. you can not give scope to a specific string like "TODO" in all different syntaxes. But don't worry there's always a way.

  1. One solution is to go and edit all your favorite syntaxes. (Not recommended) make a small stand-alone syntax file that just finds the word TODO and give it a scope. Now, open all your other syntax files, find their comment rule definition, and include this external syntax definition. Look how HTML syntax is including Javascript or CSS syntax that'll give you an idea.

  2. Use Sublime's plugin api to dynamically add a scope to TODO words, you should be careful to select TODO phrases inside the comments. Check out the plugin API reference for add_regions(key, [regions], <scope>, <icon>, <flags>)

  3. There are already a couple of plugins on package control that can do such a thing. namely, SublimeLinter (might need some configuration) and TodoReview

Allen Bargi
  • 14,674
  • 9
  • 59
  • 58