From b8e31106ce3061e0c26e3212aa181eb52662cfda Mon Sep 17 00:00:00 2001 From: Paul Weibert Date: Sun, 1 Jan 2023 17:59:49 +0100 Subject: [PATCH 1/5] Support Breakpoints in Multiple Files * Traverse open python mode buffers and retrieve breakpoints that were set by elpy * Specify breakpoints using full file path and line number --- elpy-shell.el | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/elpy-shell.el b/elpy-shell.el index a659bb31..07293d5c 100644 --- a/elpy-shell.el +++ b/elpy-shell.el @@ -1218,14 +1218,15 @@ switches focus to Python shell buffer." (when (version<= "25" emacs-version) - (defun elpy-pdb--refresh-breakpoints (lines) + (defun elpy-pdb--refresh-breakpoints (buffer-lines) "Add new breakpoints at lines LINES of the current buffer." ;; Forget old breakpoints (python-shell-send-string-no-output "import bdb as __bdb; __bdb.Breakpoint.bplist={}; __bdb.Breakpoint.next=1;__bdb.Breakpoint.bpbynumber=[None]") (python-shell-send-string-no-output "import pdb; __pdbi = pdb.Pdb()") - (dolist (line lines) + (dolist (line buffer-lines) (python-shell-send-string-no-output - (format "__pdbi.set_break('''%s''', %s)" (buffer-file-name) line)))) + (format "__pdbi.set_break('''%s''', %s)" (nth 1 line) (nth 0 line)))) + ) (defun elpy-pdb--start-pdb (&optional output) "Start pdb on the current script. @@ -1259,19 +1260,32 @@ With a prefix argument, ignore the existing breakpoints." (error "Debugging only work for buffers visiting a file") (elpy-shell--ensure-shell-running) (save-buffer) - (let ((bp-lines (elpy-pdb--get-breakpoint-positions))) - (if (or arg (= 0 (length bp-lines))) - (progn - (elpy-pdb--refresh-breakpoints '()) - (elpy-pdb--start-pdb t)) - (elpy-pdb--refresh-breakpoints bp-lines) - (elpy-pdb--start-pdb) - (python-shell-send-string "continue"))) + (let (buffer-breakpoint-lst) + (dolist (elt (buffer-list)) + (with-current-buffer elt + (if (string= major-mode "python-mode") + (progn + (dolist (breakpt (elpy-pdb--get-breakpoint-positions)) + (message "Buffer full name: %s" (buffer-file-name)) + (setq buffer-breakpoint-lst (cons (list breakpt buffer-file-name) buffer-breakpoint-lst)) + ) + ) + ) + ) + ) + (if (or arg (= 0 (length buffer-breakpoint-lst))) + (progn + (elpy-pdb--refresh-breakpoints '()) + (elpy-pdb--start-pdb t)) + (elpy-pdb--refresh-breakpoints buffer-breakpoint-lst) + (elpy-pdb--start-pdb) + (python-shell-send-string "continue") + ) + ) (elpy-shell-display-buffer))) (defun elpy-pdb-break-at-point () "Run pdb on the current buffer and break at the current line. - Ignore the existing breakpoints. Pdb can directly exit if the current line is not a statement that is actually run (blank line, comment line, ...)." From c4c7a1814c2e839a52a3405102bea211810056b7 Mon Sep 17 00:00:00 2001 From: Paul Weibert Date: Sun, 1 Jan 2023 19:08:28 +0100 Subject: [PATCH 2/5] * Update documentation --- docs/ide.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/ide.rst b/docs/ide.rst index 5306770f..30dc42ac 100644 --- a/docs/ide.rst +++ b/docs/ide.rst @@ -676,7 +676,8 @@ Note that this interface is only available for Emacs 25 and above. .. command:: elpy-pdb-debug-buffer :kbd: C-c C-u d - Run pdb on the current buffer. If no breakpoints has been set using + Run pdb on the current buffer. If no breakpoints has been set in any + open buffer with elpy mode using :command:`elpy-pdb-toggle-breakpoint-at-point`, the debugger will pause at the beginning of the buffer. Else, the debugger will pause at the first breakpoint. Once pdb is started, the `pdb commands`_ From 5ffe9aa7e343dce17b38a53c0b2362aeac6d0e17 Mon Sep 17 00:00:00 2001 From: pweibert <57200448+pweibert@users.noreply.github.com> Date: Sun, 23 Jul 2023 09:49:10 +0200 Subject: [PATCH 3/5] Remove debug print message --- elpy-shell.el | 1 - 1 file changed, 1 deletion(-) diff --git a/elpy-shell.el b/elpy-shell.el index 07293d5c..aae5da29 100644 --- a/elpy-shell.el +++ b/elpy-shell.el @@ -1266,7 +1266,6 @@ With a prefix argument, ignore the existing breakpoints." (if (string= major-mode "python-mode") (progn (dolist (breakpt (elpy-pdb--get-breakpoint-positions)) - (message "Buffer full name: %s" (buffer-file-name)) (setq buffer-breakpoint-lst (cons (list breakpt buffer-file-name) buffer-breakpoint-lst)) ) ) From 212e39a50bdcbd2296431e1de22b2e05adad4900 Mon Sep 17 00:00:00 2001 From: pweibert <57200448+pweibert@users.noreply.github.com> Date: Mon, 24 Jul 2023 10:11:47 +0200 Subject: [PATCH 4/5] Correct typo ide.rst --- docs/ide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ide.rst b/docs/ide.rst index 30dc42ac..89af0638 100644 --- a/docs/ide.rst +++ b/docs/ide.rst @@ -676,7 +676,7 @@ Note that this interface is only available for Emacs 25 and above. .. command:: elpy-pdb-debug-buffer :kbd: C-c C-u d - Run pdb on the current buffer. If no breakpoints has been set in any + Run pdb on the current buffer. If no breakpoints have been set in any open buffer with elpy mode using :command:`elpy-pdb-toggle-breakpoint-at-point`, the debugger will pause at the beginning of the buffer. Else, the debugger will pause From 73c5a8d4b5a309647b57dcd49b026863bfe0336e Mon Sep 17 00:00:00 2001 From: pweibert <57200448+pweibert@users.noreply.github.com> Date: Mon, 24 Jul 2023 10:14:32 +0200 Subject: [PATCH 5/5] Update elpy-shell.el --- elpy-shell.el | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/elpy-shell.el b/elpy-shell.el index aae5da29..441a18cb 100644 --- a/elpy-shell.el +++ b/elpy-shell.el @@ -1266,21 +1266,14 @@ With a prefix argument, ignore the existing breakpoints." (if (string= major-mode "python-mode") (progn (dolist (breakpt (elpy-pdb--get-breakpoint-positions)) - (setq buffer-breakpoint-lst (cons (list breakpt buffer-file-name) buffer-breakpoint-lst)) - ) - ) - ) - ) - ) + (setq buffer-breakpoint-lst (cons (list breakpt buffer-file-name) buffer-breakpoint-lst))))))) (if (or arg (= 0 (length buffer-breakpoint-lst))) (progn (elpy-pdb--refresh-breakpoints '()) (elpy-pdb--start-pdb t)) (elpy-pdb--refresh-breakpoints buffer-breakpoint-lst) (elpy-pdb--start-pdb) - (python-shell-send-string "continue") - ) - ) + (python-shell-send-string "continue"))) (elpy-shell-display-buffer))) (defun elpy-pdb-break-at-point ()