[TxMt] Block / Line commenting

fatal fatal at starflam.com
Mon Nov 15 17:17:58 UTC 2004


I made a ruby script and use a command to pipe selected text thru it.
I like the "# " to be at the start of the line and I prefer to have the 
same shortcut to comment`/uncomment,
so the one on the wiki didn't suited me.

This puts or removes  "# " at the start  of selected lines depending on 
the first selected char. being # or not.

If you have Ruby installed:
-------
#!/usr/local/bin/ruby
	
block = ARGV.to_s
newBlock = ""

if block[0] == 35
	block.each {|line| newBlock << line.sub(/^# ?/, "")}
else
	block.each {|line| newBlock << "# " << line}
end
	
puts newBlock

-------------

Save this in a file ending in .rb
Then make a new command with:

-------
ruby path/to/script.rb "$TM_SELECTED_TEXT"
--------
And choose: 	Standard input "selected text"
			Standard output "Replace selected text"

You can do this with the language you want, of course.
Or some better scripter than me could do it for you in a nicer way.

--
Fred B.

On 15-nov.-04, at 13:20, Brian Gorby wrote:

> Is there a way in v1.0.1 to highlight a line or a block and have it 
> either commented or uncommented based on the current state of the line 
> (a la Scite)? Could this be done through the use of Macros?
>
> -Brian
>
> _______________________________________________
> textmate mailing list
> textmate at lists.macromates.com
> http://lists.macromates.com/mailman/listinfo/textmate
>




More information about the textmate mailing list