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
On 15. Nov 2004, 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?
You can do a macro that does a regex replace in the selection. For example if you search for: “^(#)?(.*)$” it will match the line and place the leading # in capture register 1, if it exists. In the format string you can check whether capture register 1 captured anything and do conditional replacements, so make the replace string e.g. like this: “?1$2:#$2”. This will put a # in front of the line if it didn't already have one, otherwise it will remove it.
An alternative would be simply to pipe the selection through a script which does similar, I think such a script is available from the wiki (this could then be a command, which is probably easier to edit later, if you need to change it).
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@lists.macromates.com http://lists.macromates.com/mailman/listinfo/textmate
There is another text editor JeditX (not the jave program) http://www.artman21.net/product/JeditX/index_E.html that has a nice function called "FORMAT> Ruled Paper..." Which allows a nice presentation for printed code. It is also nice for working in with LaTeX and HTML. Any chance for such an implementation
Thank you, Robert Ullrey