Commits

Alain Leufroy committed f505315

[python] refactor: add debug functions

  • Participants
  • Parent commits 643e81a

Comments (0)

Files changed (1)

python-refactor.el

+(defun py--debug-insert-before-statment (text)
+  "Insert some text before the current python statement"
+  (py-statement-backward)
+  (open-line-above)
+  (py-indent-line)
+  (insert text)
+  (py-indent-line)
+  (py-statement-backward)
+  (py-indent-line)
+)
+
+(defun py--debug-add-print (&optional name)
+  "Add print statement [print 'name=', name] for debugging purpose."
+  (py--debug-insert-before-statment
+   (concat "print '''" name " =''', " name)) ; repr(var) ?
+  )
+
+(defun py-debug-add-pdb ()
+  "Insert pdb statments as debuging break point."
+  (interactive)
+  (py--debug-insert-before-statment "import pdb;pdb.set_trace()")
+  )
+
+(defun py-debug-add-pyqt-pdb ()
+  "Insert pdb statments as debuging break point with PyQt4 input hook support."
+  (interactive)
+  (py--debug-insert-before-statment
+   (concat "import PyQt4,pdb;"
+           "PyQt4.QtCore.pyqtRemoveInputHook();"
+           "pdb.set_trace();"
+           "PyQt4.QtCore.pyqtRestoreInputHook();"))
+  )
+
+(defun py-debug-add-print-of-region (beg end)
+  "Insert [print 'region=', region] for debugging purpose"
+  (interactive "r")
+  (let ((name (buffer-substring beg end)))
+    (py--debug-add-print name))
+)
+
+(provide 'python-refactor)