[TxMt] insert breakpoints in python code

Dougal dougal at gmail.com
Fri Apr 13 12:48:41 UTC 2007


This would be much simpler to do with a real snippet, rather than a command.
Choose "New Snippet" from the bottom-left of the bundle editor, and then
just type "import pdb; pdb.set_trace()" in the big box. This can be tab- or
shortcut-activated.

Also, I don't really know python, but I'm guessing that you only need to
import pdb once per file; afterwards, you can just use pdb.set_trace().

On 4/13/07, Yi Qiang <yqiang at gmail.com> wrote:
>
> 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
>
>
>
> ______________________________________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20070413/bbbee0c3/attachment.html>


More information about the textmate mailing list