This is an old thread but I found it useful and wanted to submit my bug fixes and updates.
First I used http://en.wikipedia.org/wiki/Comment_%28computer_programming%29#In_context to learn about various comment formats.
[quote=“quodlibet”]# !this works
#!this doesn’t[/quote]
Changed the “\S+” in the first regex to “\S^!]*” which replaces everything except “!”. The “\S+” matched the exclamation mark and removed it. I included the “\S” at the start because Fortran 90 uses “!” to denote a comment. I also added an HTML-specific string so it isn’t thrown off by the “!” in “<!–”.
Of course this won’t work with languages like Haskell which place no text before the comment. You could probably fix this by including a space before the “!”.
Can’t figure this one out.
I found a package called “Scope Hunter” that tells you the scope of the text under your cursor. In a CSS comment it shows “source.css” and “comment.block.css” just like my PHP example which shows “source.php.embedded.block.html” and “comment.block.php” (both have “source” and “comment” scopes).
HTML didn’t work for me either but Sublime doesn’t include “source” in the scope for HTML files. I assume that Sublime knows what a comment is regardless of its context so I took “source” out and now HTML works.
ScopeHunter: https://packagecontrol.io/packages/ScopeHunter
The second line in the symbolTransformations below was added.
Here is my modified version of the code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Comment Bang</string>
<key>scope</key>
<string>comment</string>
<key>settings</key>
<dict>
<key>showInSymbolList</key>
<integer>1</integer>
<key>symbolTransformation</key>
<string>
s/^(<!--|\S)^!]*\s*//g # strip opening punctuation + spacing
s/\s*(\*\/|-->|-\}|#>)$//g # strip closing text on block comments
s/^^!].*//g # remove all comments that DON'T begin with a bang
s/^!\s*//g # strip the leading exclamation and spacing
s/^(.*?)\n.*/$1/g # keep only 1st line (in case of multiline comment)
</string>
</dict>
<key>uuid</key>
<string>7fdae8f0-c6c7-11e1-9b21-0800200c9a66</string>
</dict>
</plist>