[TxMt] update: Universal Un/Comment

Eric Hsu erichsu at math.sfsu.edu
Wed Dec 22 22:17:02 UTC 2004

hi folks,

I am startled but gratified at the response to the Un/Comment hack. 
I added a number of fixes and options people have been asking for and 
packaged it up into a .tmbundle so you don't have to copy in the 
hideous Perl 1-liner (but you can... attached below). In the bundle, 
I also included the source code, which is released as Niceware. 
That's like the Perl Artistic License, except that you have to be 
nice to me when you criticize the code.

The bundle lives at <http://math.sfsu.edu/hsu/textmate>.

- I added some options.  To invoke them, put them on the command line, e.g.

perl -e '...' "$TM_FILEPATH" first-column comment .tex

- so if you want separate comment/uncomment, make two commands with 
one option 'comment' and the other 'uncomment'
- I added a bunch of filetype endings, including the ones in Chris 
T's beautiful Ruby script.
- fixed Ollivier Robert's newline bug
- Drew McLellan: I added CSS, but sadly, I can only comment each 
line, not the whole thing. I hope that is still useable.

# 'first-column' puts the first comment marker at the line start
# 'comment' always comments (for people who want the smartness, but 
not the toggleness)
# 'uncomment' always uncomments. If you foolishly use both comment 
and this, comment wins.
# 'comment-whitespace' comments whitespace which we normally skip.
# '.tex' will force the use of TeX style comments. You can substitute 
your favorite  ending, like '.java' or '.pl'. The leading dot is 
important. Last type listed wins.
# 'toggle' changes the comment status line by line. Normally, the 
whole thing is a block.

best wishes, Eric

If you install the thing as a tmbundle, you can also install it as a command as

Before: do nothing
STDIN: Selected
STDOUT: Replace Selected

To install it as a command as a one-liner, with no path issues:

Before: do nothing
perl -e 
",""],"inf,f90"=>["!",""],};$tab=4;while(($k,$v)=each(%$markers)){foreach(split(/\s*,\s*/,$k)){$c{"$_"}=$v;}}$_=shift at ARGV;($type)=/\.([^.]*)$/;foreach$option(@ARGV){if($option=~/^\.(.*)$/){$type=$1;}$opt->{$option}++;}unless($c{"$type"}){$type="pl";}($start,$finish, at etc)=@{$c{$type}};$isntfirst=0;while(<STDIN>){push at in,$_;($indent)=/^([ 
$_";if($finish){$out.=" ".$finish;}$out.=$lineend;}}}print$out;' 

STDIN: Selected
STDOUT: Replace Selected

Eric Hsu, Assistant Professor of Mathematics
San Francisco State University
erichsu at math.sfsu.edu

More information about the textmate mailing list