C-x C-p for import pdb; pdb.set_trace()
I worked through most of the Learn Emacs Lisp in 15 minute tutorial and learned enough to write something useful:
;; Inset import pdb; pdb.set_trace() on C-x, C-p (defun pdb-set-trace () ;; http://www.emacswiki.org/emacs/InteractiveFunction (interactive) (insert "import pdb; pdb.set_trace()\n")) (global-set-key [(control ?x) (control ?p)] 'pdb-set-trace)
Once you place this function in your Emacs init file, when you press the keys C-x and C-p,
import pdb; pdb.set_trace() will magically appear in your Python program (well, anywhere for that matter, since there is no check in place). This is something which I know will be very useful to me. If you don’t like the key combination, you can change it in the last line of the above function.
If you don’t know Emacs lisp, you should try to work through the tutorial. Although, I must say I did make various attempts long time back to learn Common Lisp and Clojure, so it was not so unfamiliar to me.
[…] via Planet Python http://echorand.me/2013/11/30/c-x-c-p-for-import-pdb-pdb-set_trace/ […]
You can also do this with simple abbrevs . For example, I have ‘pdbs’ expanding to what you posted, also ‘pudbs’ for the same thing with pudb, and ‘pudbb’ + ‘pudbi’ together allowing for conditional breakpoints when called from specific test cases.
Thanks! I will take a look.