[TxMt] Re: Incremental Sequences for Replacement

Doug Schepers doug at schepers.cc
Mon Mar 1 21:41:56 UTC 2010


Hi, Hans-

Thanks for the reply.

Hans-Jörg Bibiko wrote (on 3/1/10 4:10 AM):
>
> for such cases I use this tmcommand:
> Input: selection or document
> Ouptut: new doc
> Command:
> #!/usr/bin/perl -w
> #!/usr/bin/perl -w
>
> $cnt=1;
> $inc=1;
>
> while(<>) {
> 	if(m/^\\i\((\d+)\s*,\s*(\d+)\)$/) {
> 		$cnt=$1;
> 		$inc=$2;
> 		next;
> 	}
> 	while(s/\\i/$cnt/) {$cnt+=$inc;}
> 	print;
> }
> Example text:
> Hello, this is a test.
> \i(2,5)
> Here my \i. item followed by item \i.
> Furthermore here is my \i. item.
>
>
> Then you get:
> Hello, this is a test.
> Here my 2. item followed by item 7.
> Furthermore here is my 12. item.
>
>
> If you do not set up \i(a,b) it simply starts at 1 incremented by 1.

I've been using TextMate for a while, but I haven't had the time to dig 
into its more powerful features.  I was able to create the command, but 
I don't quite understand the usage.

Here's an example use case: I have a document, and I want to write out a 
regex that matches on a certain pattern (Find: (<a) (class="([^"]*)") ) 
and add an id to each matching instance (Replace: $1 id="_\i(2,5)" $2 ), 
with changes applied inline into the current document.  With a command, 
how to I supply the pattern to match?  Is this possible?

Regards-
-Doug



More information about the textmate mailing list