[TxMt] insert breakpoints in python code

Yi Qiang yqiang at gmail.com
Fri Apr 13 06:21:25 UTC 2007


Hello,
I am a relatively new TextMate user and am still learning all the ins  
and outs of it, but it certainly is a lot of fun :)  When I am doing  
python development, a lot of times I just want to set a breakpoint in  
my code, and the way to do that in python is:

import pdb; pdb.set_trace()

Typing that each time got boring, so I wrote this little snippet for  
it.  I would like some feedback, especially with the way I am  
figuring out the right indentation level :)

------------------------------------------------------------------------
#!/usr/bin/env python
# This TextMate command inserts a breakpoint ABOVE the currently  
selected line
# Yi Qiang (yqiang _at_ gmail dot com)

import os
import sys

text = sys.stdin.readlines()
line_number = int(os.getenv('TM_LINE_NUMBER')) - 1 # TM counts from 1
spaces = (len(text[line_number]) - len(text[line_number].expandtabs 
(4).lstrip()))
debug_string = (' ' * (spaces)) + 'import pdb; pdb.set_trace()\n'
text.insert(line_number, debug_string)
sys.stdout.write(''.join(text))

------------------------------------------------------------------------ 
-

Cheers,
Yi

--
http://www.yiqiang.net





More information about the textmate mailing list