[TxMt] Re: Force Tabs with snippets

Constantinos Neophytou ♎ jaguarcy at gmail.com
Sat Jun 2 10:52:02 UTC 2007


I think this could probably be accomplished with a simple python (or  
ruby) script that took the line as input, then did
print "%-100s" % thetext
or something like that and replaced the line? (or place it in a macro  
that first selects the line, and the command replaces the selection...)


As for the original question, woulnd't it be failry straight forward  
to have something like:

sometext⇥more text
somemoretext⇥and a bit more
whateverelse⇥some more

then opt-shift-up, and parse the selection through a small python  
script that splits each line on the tab character, finds the longest  
first half of a line, and aligns everything using spaces...

in fact, this seems to work as a command (takes the first tab it  
finds in every line, and adds enough spaces before it so that all the  
first tabs in each line align):

Command
Input: Selected Text or Nothing
Output: Replace Selected Text
Activation: Key Equivalent (i set it to cmd-opt-shift-r)
Command:

#!/usr/bin/env python
import os

selectedText = ''
splitMarker = "\t"
joinMarker = "\t"

if 'TM_SELECTED_TEXT' in os.environ:
	selectedText = os.environ['TM_SELECTED_TEXT']
	lines = selectedText.splitlines()
	length = 0
	for i in range(len(lines)):
		sec = lines[i].split(splitMarker)
		length = max(length, len(sec[0]))
	l = "%%-%ds" % length
	for j in range(len(lines)):
		sec = lines[j].split(splitMarker)
		sec[0] = l % sec[0]
		print joinMarker.join(sec)


This is very rough, i wrote it while writing this email, but it seems  
to work. Using it in the above proposed method also seems to work  
(i.e. write all the data in a column block, have the first tab where  
you want everything to align, opt-shift-up, opt-cmd-shift-R)

Note instead of the first tab, the align 'marker' can be anything...

On Jun 2, 2007, at 12:38 PM, Piero D''Ancona wrote:

> Allan Odgaard <throw-away-1 at ...> writes:
>
>>
>> On 2. Jun 2007, at 06:54, Helmut Granda wrote:
>>
>>> for example is it possible to write a snippet to do something  
>>> like...
>>>
>>> text (move to column 100)moreText
>>>
>>> does that makes sense? sort of tabbing but using column numbers
>>> instead (margins?)
>>
>> Other than actually inserting the required number of spaces, no,
>> there is no such shortcut.
>>
>>
>
> If the text to be inserted is always the same, you can record
> a macro which inserts some text, moves to the right (press
> right arrow 100 times) then inserts some more text...
>
>
>
>
>
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate

-- 
What's your Dream?
Make it happen with www.dostpost.com



-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1288 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20070602/4b0b67cf/attachment.p7s>


More information about the textmate mailing list