[TxMt] Re: merging columns of text

Roberto Aguilar roberto.c.aguilar at gmail.com
Fri Apr 9 16:53:25 UTC 2010


On Apr 9, 2010, at 5:00 AM, textmate-request at lists.macromates.com wrote:
> Message: 1
> Date: Thu, 8 Apr 2010 16:37:52 -0700
> From: Steven W Riggins <mailinglists at geeksrus.com>
> Subject: [TxMt]  merging columns of text
> To: Textmate Mailing List <textmate at lists.macromates.com>
> Message-ID: <EB031447-6AE7-4675-8BDC-5C2F5CD83D5F at geeksrus.com>
> Content-Type: text/plain; charset=us-ascii
> 
> if I have
> 
> one
> two
> three
> four
> 
> on the clipboard, can I paste it in front of (line by line)
> 
> duck
> cows
> chickens
> geese
> 
> Thanks! (Simple example of my task)

If your final task is as simple as your example, toss this in a command snippet.

-Roberto.

#!/usr/bin/env python
import os
import sys

from subprocess import PIPE, Popen

selection = os.environ.get('TM_SELECTED_TEXT').splitlines()

if not selection:
    print 'Cut text to go second, then make selection for text that goes first'
    sys.exit(1)

clipboard = Popen(["pbpaste"], stdout=PIPE).communicate()[0].splitlines()

selection_len = len(selection)
clipboard_len = len(clipboard)

if selection_len != clipboard_len:
    sys.exit("Selection (%d) and clipboard (%d) don't have the same number of lines" % (selection_len, clipboard_len))

print '\n'.join([' '.join(x) for x in zip(selection, clipboard)])




More information about the textmate mailing list