Hi,
I took a stab at this.
Save the following to Packages/User/Comment Bang.tmPreferences (or whatever):
- Code: Select all
<?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/^[^!].*//g # remove all comments that DON'T begin with a bang
s/^!\s*//g # strip bang and subsequent spaces (if any)
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>
I'm pretty to new to writing regular expressions, so this is probably not the most efficient way to do it, but it works so long as you put at least one space or tab before the bang.
So:
# !this works
#!this doesn't
BUGS:
+ Doesn't work in CSS, although it works for other syntaxes with C-style comments (/* xxx */). Need to investigate.
TODO:
+ Strip common punctuation from end of single comments (such as, -->)
+ Re-write so that you don't need to space before the bang (while still ignoring HTML punctuation)