On Dec 21, 2004, at 16:46, Eric Hsu wrote:
I missed a command from BBEdit that let you comment and uncomment text magically for different languages with the same keystroke (Text->Un/Comment), so I wrote a version for TextMate. [...]
Nice! :)
I changed the extension-grabbing code to this: “($t)=/.([^.]*)$/” to handle paths with multiple dots and I quoted TM_FILEPATH (for paths with spaces).
I also added: "cc,mm"=>["//","","/*","*/"] and m+h to the plist,c types.
So it's now: perl -e '$a={"cc,mm"=>["//","","/*","*/"],"pl,pm"=>["#",""],"plist,c,m,h"=>["/ *","*/"],"html,htm"=>["<!--","--
"],"tex,ltx"=>["%",""],"php"=>["#","","/*","*/","<!--","-->","/
/",""]};while(($k,$v)=each(%$a)){foreach(split(/\s*,\s*/ ,$k)){$c{"$_"}=$v;}}$_=shift@ARGV;($t)=/.([^.]*)$/; ($s,$f,@etc)=@{$c{$t}};$b=0;while(<STDIN>){push@in,$_;($in)=/^([ \t]*)/;$inl=0;foreach$j(1..(length($in))){$ch=substr($in,$j-1,1);if($ch eq" "){$inl++;}else{unless($inl%4){$inl+=4;}else{$inl+=$inl%4;}}}unless($i){ $ind=$in;$indl=$inl;$i++;}else{if($inl<$indl||$in eq""){$ind=$in;$indl=$inl;}}}$i=0; foreach(@in){if(chomp){$n="\n";}unless(/\S/){$o.=$_."\n"; next;}unless($b){$b=1;foreach$d(@{$c{$t}}){$i=1-$i;$d=quotemeta($d); if($i){if(/^\s*$d/){$y=1;$s=$d;}}elsif($y){$f=$d;last;}}}if($y){s/ ^(\s*)$s(\ )?/$1/;s/(\ )?$f(\s*)$/$1/;$o.=$_.$n;}else{s/^$ind//;$o.=$ind.$s." $_ ".$f.$n;}}print$o;' "$TM_FILEPATH"
If there is enough interest, I will release commented source code and make it into a nice .tmbundle.
Sounds like when you do, I should add that bundle to what's included by default with TM (if you don't mind)! :)