[TxMt] Re: How can I add a sequencial number to this Find/Replace?

Graham P Heath graham.p.heath at gmail.com
Fri Feb 20 20:34:37 UTC 2015


Don’t copy that line. Just its results.

16
17
[…snip...]
31
32
 
Graham P Heath


On February 20, 2015 at 1:16:44 PM, jgalt (jgaltusa at gmail.com) wrote:

Thanks Graham, that worked great but I am having one problem.  The first line of your formula gets placed into my first placeholder.

Example: <PortalObj portalFlags="16" numOfRows="1" initialRow=$ seq 16 32>


On 2/20/15 9:41 AM, "Graham P Heath" <graham.p.heath at gmail.com> wrote:

You can combine Multiple Carets and Copy + Paste to achieve this easily.

Find a list of the numbers you want to use, I assume you’re capable of generating the list in some way, but I like using the `seq` command in the terminal such as:

$ seq 16 32
16
17
[…snip...]
31
32

Note: It is important that they be separated by new line characters.

Copy this list.

Select your first placeholder: “##"

 <PortalOBj portalFlags="16" numbOfRows="1" initialRow=“##”>

Press Control + W, this selects the next placeholder. Repeat until your selection contains all of your placeholders.

Paste.

Graham P Heath

 

On February 20, 2015 at 8:29:30 AM, René Schwaiger (sanssecours at f-m.fm) wrote:
 
Hi jgaltUSA,

> On 20 Feb 2015, at 9:50 , jgaltUSA <jgaltUSA at gmail.com> wrote:
>  
> I am a newbie to textmate and I am trying to perform a find and replace. I want to replace the matched text with a sequential number.  
>  
> Here is my current replacement string: $1##$2  
>  
> How can I replace the ## with a sequential number?  

I do not think that what you want is possible using only regular expressions and “Find & Replace”. It is possible and not to complex using a programming language. The following code does what you want:

    #!/usr/bin/env python

    from re import compile
    from sys import stdin, stdout

    regex = compile(
        """(<PortalOBj portalFlags="16" numbOfRows="1" initialRow=")\d+(">)""")
    index = 16

    def create_subtitute_function():
        def substitute(match):
            global index
            replacement = "{}{}{}".format(match.group(1), index, match.group(2))
            index += 1
            return replacement

        return substitute

    text = regex.sub(create_subtitute_function(), stdin.read())
    stdout.write(text)

I attached a bundle which contains a command that uses the above code. To install the bundle just double click it. You can apply the substitution on some text by pressing the key combination “^⌥⌘R”. Since the above is my code I would be careful when you use the command though :).

> For example, I want the first sequential number to be 16.  
>  
> Here is a screen capture:   
>  
> Thanks!

Kind regards,
  René

P.S.: You can create a screenshot of a single window by using the key combination “⇧⌘4”. After that just hit “Space” and a click on the window you would like to make a screenshot of. This way you do not need to crop the picture.


_______________________________________________
textmate mailing list
textmate at lists.macromates.com
http://lists.macromates.com/listinfo/textmate


_______________________________________________
textmate mailing list
textmate at lists.macromates.com
http://lists.macromates.com/listinfo/textmate

_______________________________________________  
textmate mailing list  
textmate at lists.macromates.com  
http://lists.macromates.com/listinfo/textmate
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20150220/9e4ff211/attachment.html>


More information about the textmate mailing list