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
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@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
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
Dougal wrote:
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.
I think the point was to put it the line before the current line.
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().
Python doesn't care if you import something multiple times. So I'm guessing he does it that way to a) make sure it always gets imported, b) ensure it always gets cleaned up (i.e. all the import statements go away) when he comments or deletes those lines, and c) keep the code he uses to set a breakpoint consistent.
-Jacob