简体   繁体   English

emacs python pdb重新启动调试sesson

[英]emacs python pdb restart debugging sesson

I am using Emacs to edit and debug python code and I would like to know how to restart my debugging session within emacs pdb with a single letter command. 我正在使用Emacs编辑和调试python代码,我想知道如何使用一个字母命令在emacs pdb中重新启动调试会话。 In perldb , there is a single command R that equates to restart the script, but I can't find the equivalent one-letter instruction for restart in python. perldb ,有一个命令R等同于restart脚本,但是我找不到在python中restart的等效单字母指令。

Is there a way to hook up R to do restart in pdb? 有没有办法连接R以便在pdb中restart

You could bind a function like pdb-restart (which may not exist) to 'R' via something like this: 您可以通过以下方式将诸如pdb-restart类的功能(可能不存在)绑定到“ R”:

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

Though this will really affect all gud sessions. 虽然这确实会影响所有的gud会话。 You can always set specific hooks to override this behavior if it is unwanted in other gud sessions. 如果在其他gud会话中不需要此行为,则始终可以设置特定的钩子来覆盖此行为。

EDIT: 编辑:

A better way could be to use pdb-mode-hook instead of modifying gud-mode-map : 更好的方法可能是使用pdb-mode-hook而不是修改gud-mode-map

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

I've tried to restart the pdb session myself and ended up having to write my own command to do it. 我尝试自己重新启动pdb会话,最终不得不编写自己的命令来执行此操作。 It first tries to send a nice 'restart' with comint-send-input, but if that doesn't work, it falls back to killing the buffer (along with the underlying pdb process), and restarts the pdb session, using the same directory and arguments as the last started pdb session. 它首先尝试使用comint-send-input发送一个不错的“重新启动”,但是,如果这样不起作用,则会退回到杀死缓冲区(以及底层pdb进程),然后使用相同的命令重新启动pdb会话。目录和参数作为上次启动的pdb会话。

(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 for 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"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM