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.
quodlibet wrote:+ Re-write so that you don't need to space before the bang (while still ignoring HTML punctuation)
quodlibet wrote:# !this works
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 "!".
quodlibet wrote:+ Doesn't work in CSS, although it works for other syntaxes with C-style comments (/* xxx */). Need to investigate.
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
quodlibet wrote:+ Strip common punctuation from end of single comments (such as, -->)
The second line in the symbolTransformations below was added.
Here is my modified version of the code:
- 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/\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)