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">
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)
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.
# !this works
+ Doesn't work in CSS, although it works for other syntaxes with C-style comments (/* xxx */). Need to investigate.
+ 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)