简体   繁体   English

Emacs中的Python调试器:是否设置类似于perldb的键绑定?

[英]Python debugger in Emacs: set keybindings similar to perldb?

I am starting to use the pdb Python debugger in Emacs, and I am used to the keys in the perl debugger, which I would like to also be able to use in pdb . 我开始在Emacs中使用pdb Python调试器,并且已经习惯了perl调试器中的键,我也希望能够在pdb使用它。 How can I configure the debugger in Emacs to have the same keybindings as in Perl, like "restart=R" or "print=x"? 如何在Emacs中配置调试器以使其具有与Perl中相同的键绑定,例如“ restart = R”或“ print = x”?

I don't mind if this is only specific to debugging in Emacs and not the pdb debugger in the console, I am going to do all my debugging in Emacs anyway. 我不介意这是否仅适用于Emacs中的调试,而不是控制台中的pdb调试器,无论如何,我都将在Emacs中进行所有调试。

Here is the code I use to do force a pdb restart, which first sends a restart via comint-send-input, but falls back to killing and restarting the pdb process with the same arguments and default-directory if that fails. 这是我用来强制pdb重新启动的代码,该代码首先通过comint-send-input发送一个重新启动,但是如果失败,将回退到使用相同的参数和默认目录杀死并重新启动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"))

(defun comint-insert-send (input)
  (insert input)
  (comint-send-input))

(defun last-lines-match (regexp &optional n)
  (unless n (setf n 3))
  (re-search-backward regexp (line-beginning-position (- 0 n)) t))

You can bind pdb-restart to 'R' via something like this: 您可以通过以下方式将pdb-restart绑定到“ R”:

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

As for print, in pdb, you can simply do p pythonexpression , so there isn't much to short-cut. 至于打印,在pdb中,您可以简单地执行p pythonexpression ,因此p pythonexpression不多。 However, you can bind x to 'print ' using the following: 但是,您可以使用以下方法将x绑定到'print':

(define-key gud-mode-map "x" (lambda () (interactive)  (insert "print ")))

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

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