[TxMt] Combining snippets and commands?

Allan Odgaard throw-away-1 at macromates.com
Tue Feb 21 22:56:25 UTC 2006


On 21/2/2006, at 23:47, Dr. Drang wrote:

>>> You could do this with ruby for instance:
>>> #!/usr/bin/env ruby
>>> print "[${1:description}][${2:id}]$0" + STDIN.read + "\n 
>>> [${2:id}]: ${3:href}"
>> oops, spoke too soon. You'll want to escape all $ in STDIN.read, so:
>> print "[${1:description}][${2:id}]$0" + STDIN.read.gsub('$','\\$')  
>> + "\n[${2:id}]: ${3:href}"
> I'll give it a try tonight. Thanks.

Also remember to escape ` and \. So that’d be:

    STDIN.read.gsub(/[$`\\]/, '\\\\\1')

Instead of a macro, it is also possible to set the commands input to  
entire document and then use TM_LINE_NUMBER and TM_LINE_INDEX as the  
carets location.




More information about the textmate mailing list