Emacs调试Python用什么插件呢?

以前总是调用PyCharm来调试。今天发现了realgud,不知道大家都用什么来调试Python?猫大的lsp-bridge好像还不支持调试吧。

import pdb
pdb.set_trace()
M-x pdb
M-x dape
1 个赞

发现dape比realgud好看。推荐!

我发现dape调试的时候有个dape-active-mode 的 minor-mode. 我想仅在这个minor-mode 下的时候 f8执行dape-step命令,而其他状态执行blink-search命令。试了半天不成功啊。 咋写呢?

  (defun my-f8 ()
	"Runs dape-next if dape-active-mode is enabled, otherwise opens recent files."
	(interactive)
	(if (bound-and-true-p dape-active-mode)
		(call-interactively 'dape-next)
	  (call-interactively 'dape)
	  ))

然后

(global-set-key [f8] 'my-f8)

直接 try-catch 堆屎山,一把梭。

(defun my~dape-start-or-continue ()
    "Try `dape-continue' and fall back to `dape'."
    (interactive)
    (require 'dape)
    (condition-case err
            (call-interactively #'dape-continue)
        (error (call-interactively #'dape))))

1 个赞

完整的配置

  (defun my-f7 ()
	"Runs dape-step-in if dape-active-mode is enabled, otherwise opens recent files."
	(interactive)
	(if (bound-and-true-p dape-active-mode)
		(call-interactively 'dape-step-in)
      (call-interactively 'recentf-open-files)))

  (defun my-f8 ()
	"Runs dape-next if dape-active-mode is enabled, otherwise run dape."
	(interactive)
	(if (bound-and-true-p dape-active-mode)
		(call-interactively 'dape-next)
	  (call-interactively 'dape)
	  ))

  (defun my-s-f8 ()
	"Runs dape-next if dape-active-mode is enabled, otherwise run dape."
	(interactive)
	(if (bound-and-true-p dape-active-mode)
		(call-interactively 'dape-quit)
	  ))

  (defun my-f9 ()
	"Runs dape-step-in if dape-active-mode is enabled, otherwise go to some line."
	(interactive)
	(if (bound-and-true-p dape-active-mode)
		(call-interactively 'dape-continue)
      (call-interactively 'goto-line)))


(global-set-key [f7] 'my-f7)
(global-set-key [f8] 'my-f8)
(global-set-key [M-f8] 'my-s-f8)
(global-set-key [f9] 'my-f9)