emacs python pdb restart debugging sesson -


i using emacs edit , debug python code , know how restart debugging session within emacs pdb single letter command. in perldb, there single command r equates restart script, can't find equivalent one-letter instruction restart in python.

is there way hook r restart in pdb?

here code use that. first tries send nice 'restart' comint-send-input, if doesn't work, falls killing buffer (along underlying pdb process), , restarts pdb session, using same directory , arguments last started pdb session.

(defun pdb-restart ()   (interactive)   (comint-insert-send "restart")   (sleep-for .5)   (when       (or        (last-lines-match "raise restart.* restart")        (last-lines-match "restart")        (not (get-buffer-process (current-buffer)))        )      (let (       (kill-buffer-query-functions nil );disable confirming process kill       (pdbcmd (car-safe (symbol-value (gud-symbol 'history nil 'pdb))))       (default-directory default-directory)       )       (kill-this-buffer)       (cd default-directory)       (pdb pdbcmd))     )   (comint-insert-send "n") ) (defun comint-insert-send (input)   (insert input)   (comint-send-input) ) (defun last-lines-match (regexp &optional n)   (setq n (or n 3))   (re-search-backward regexp (line-beginning-position (- 0 n)) t)) 

you can bind pdb-restart 'r' via this:

(define-key gud-mode-map "r" 'pdb-restart) 

though affect gud sessions. can set specific hooks override behavior if unwanted in other gud sessions.

edit:

a cleaner way use pdb-mode-hook:

(add-hook 'pdb-mode-hook '(define-key (current-local-map) "r" 'pdb-restart)) 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -