[TxMt] [Python Bundle] Suggestions "stolen" from Ruby Bundle and bugs from the latest SVN

Ryan Wilcox ryanwilcox at mac.com
Mon Dec 11 16:09:47 UTC 2006


Hello fellow Python Bundle users,

I've been learning more about the Ruby bundle, and I have some ideas on how to make the Python bundle better. Some of them are blatantly stolen from the Ruby bundle, some of them I came up independently myself when I was using BBEdit, and thought they would be useful in the Python bundle.


#1: Create Dictionary From:
    I thought Ruby could take the selected text and make a hash out of
    it. (looking in the TextMate book now of course I can't find it).
    I wrote something similar, turning the following text into a
    dictionary:
    
    a = 1
    b = 2
    
    --> result: {'a': '1', 'b': '2'}

    You'll find my script at the bottom of this email
    
#2: Support for syntax coloring doctests

    Wouldn't it be cool to have doctests syntax colored like code, and
    not comments?
    
    Likewise, it looks like the folding marker for Python comments
    folds on a blank line. That means folding doesn't work very well
    for doctests or comments with blank lines in it.
    
#3: super() in class snippet

    It would be cool if the class snippet inserted super(...) into the
    constructor for the class. (Is this possible with clever
    mirroring?)

_______________________________
    
Bugs:
    * Evaluate Selection As Python doesn't work
        (Traceback (most recent call last):
          File "/tmp/temp_textmate.KE9sFL", line 5, in ?
            from traceback import format_exc
            ImportError: cannot import name format_exc
        )
        
    * Documentation For Current Word doesn't work
        (global name sh is not defined)        
        
_______________________________
        
Looking forward to everybody's thoughts on these improvements!,
_Ryan Wilcox

-- 
Wilcox Development Solutions:          <http://www.wilcoxd.com>
Toolsmiths for the Internet Age            PGP: 0x2F4E9C31

_____________________________________________________________________

#!/usr/bin/env python

import fileinput
import re

"""
dictMaker takes a formatted string and generates a Python dictionary
from it.

Basically: it's easier to type in my format then to deal with all
the quoting required for dictionary creation

The Format is:

key = value

NOTE that at this time quotes are made around the values. So if you're
strings just don't add them (elsewise just find and replace the extra
quotes)

"""

a = re.compile("(\w+) = (.+)")
output = {}

for my_line in fileinput.input():
    mtch = a.search(my_line)
    output[ mtch.group(1) ] = mtch.group(2)
    
print output    

_____________________________________________________________________



More information about the textmate mailing list