branch: externals/realgud commit 348f73a911f387e711b03e2ef975219d411fe8c1 Merge: d9a3a92 7242eea Author: R. Bernstein <ro...@users.noreply.github.com> Commit: GitHub <nore...@github.com>
Merge pull request #198 from jodonnell/refactor extract method for breakpoint stuff in realgud:track-from-region --- realgud/common/track.el | 93 ++++++++++++++++++++++++++----------------------- test/test-track.el | 23 ++++++++++++ 2 files changed, 72 insertions(+), 44 deletions(-) diff --git a/realgud/common/track.el b/realgud/common/track.el index 1bae618..281cd4d 100644 --- a/realgud/common/track.el +++ b/realgud/common/track.el @@ -223,59 +223,65 @@ evaluating (realgud-cmdbuf-info-loc-regexp realgud-cmdbuf-info)" ;; in frame-num. Otherwise, nil. (frame-num) (text-sans-loc) - (bp-loc) (cmdbuf (or opt-cmdbuf (current-buffer))) ) (unless (realgud:track-complain-if-not-in-cmd-buffer cmdbuf t) (if (realgud:eval-command-p text) (realgud:message-eval-results text)) - (if (not (equal "" text)) - (with-current-buffer cmdbuf - (if (realgud-sget 'cmdbuf-info 'divert-output?) - (realgud-track-divert-prompt text cmdbuf to)) - ;; FIXME: instead of these fixed filters, - ;; put into a list and iterate over that. - (realgud-track-termination? text) - (setq text-sans-loc (or (realgud-track-loc-remaining text) text)) - (realgud-track-bp-enable-disable text-sans-loc - (realgud-cmdbuf-pat "brkpt-enable") - 't) - (realgud-track-bp-enable-disable text-sans-loc - (realgud-cmdbuf-pat "brkpt-disable") - nil) - (setq frame-num (realgud-track-selected-frame text)) - (if (and frame-num (not loc)) - (setq loc (realgud-track-loc-from-selected-frame - text cmd-mark))) - - (setq bp-loc (realgud-track-bp-loc text-sans-loc cmd-mark cmdbuf)) - (if bp-loc - (let ((src-buffer (realgud-loc-goto bp-loc))) - (realgud-cmdbuf-add-srcbuf src-buffer cmdbuf) - (with-current-buffer src-buffer - (realgud-bp-add-info bp-loc) - ))) - (if loc - (let ((selected-frame - (or (not frame-num) - (eq frame-num (realgud-cmdbuf-pat "top-frame-num"))))) - (realgud-track-loc-action loc cmdbuf (not selected-frame) - shortkey-on-tracing?) - (realgud-cmdbuf-info-in-debugger?= 't) - (realgud-cmdbuf-mode-line-update)) - (dolist (bp-loc (realgud-track-bp-delete text-sans-loc cmd-mark cmdbuf)) - (let ((src-buffer (realgud-loc-goto bp-loc))) - (realgud-cmdbuf-add-srcbuf src-buffer cmdbuf) - (with-current-buffer src-buffer - (realgud-bp-del-info bp-loc) - )))) - ) - ) + (if (not (equal "" text)) + (with-current-buffer cmdbuf + (if (realgud-sget 'cmdbuf-info 'divert-output?) + (realgud-track-divert-prompt text cmdbuf to)) + ;; FIXME: instead of these fixed filters, + ;; put into a list and iterate over that. + (realgud-track-termination? text) + (setq text-sans-loc (or (realgud-track-loc-remaining text) text)) + (realgud-track-bp-enable-disable text-sans-loc + (realgud-cmdbuf-pat "brkpt-enable") + 't) + (realgud-track-bp-enable-disable text-sans-loc + (realgud-cmdbuf-pat "brkpt-disable") + nil) + (setq frame-num (realgud-track-selected-frame text)) + (if (and frame-num (not loc)) + (setq loc (realgud-track-loc-from-selected-frame + text cmd-mark))) + + (realgud:track-add-breakpoint (realgud-track-bp-loc text-sans-loc cmd-mark cmdbuf) cmdbuf) + + (if loc + (let ((selected-frame + (or (not frame-num) + (eq frame-num (realgud-cmdbuf-pat "top-frame-num"))))) + (realgud-track-loc-action loc cmdbuf (not selected-frame) + shortkey-on-tracing?) + (realgud-cmdbuf-info-in-debugger?= 't) + (realgud-cmdbuf-mode-line-update)) + (realgud:track-remove-breakpoints + (realgud-track-bp-delete text-sans-loc cmd-mark cmdbuf))) + ) ) + ) ) ) +(defun realgud:track-add-breakpoint (bp-loc cmdbuf) + "Add a breakpoint fringe in source window if BP-LOC." + (if bp-loc + (let ((src-buffer (realgud-loc-goto bp-loc))) + (realgud-cmdbuf-add-srcbuf src-buffer cmdbuf) + (with-current-buffer src-buffer + (realgud-bp-add-info bp-loc))))) + +(defun realgud:track-remove-breakpoints (bp-locs cmdbuf) + "Remove all breakpoints in source window found in BP-LOCS." + (dolist (bp-loc bp-locs) + (let ((src-buffer (realgud-loc-goto bp-loc))) + (realgud-cmdbuf-add-srcbuf src-buffer cmdbuf) + (with-current-buffer src-buffer + (realgud-bp-del-info bp-loc))))) + (defun realgud-track-hist-fn-internal(fn) "Update both command buffer and a source buffer to reflect the selected location in the location history. If we started in a @@ -582,7 +588,6 @@ of the breakpoints found in command buffer." ; that struct is the regexp hash to match positions. By setting the ; the fields of realgud-cmdbuf-info appropriately we can accomodate a ; family of debuggers -- one at a time -- for the buffer process. - (setq cmdbuf (or cmdbuf (current-buffer))) (with-current-buffer cmdbuf (unless (realgud:track-complain-if-not-in-cmd-buffer cmdbuf t) diff --git a/test/test-track.el b/test/test-track.el index cbc4da0..6e99c05 100644 --- a/test/test-track.el +++ b/test/test-track.el @@ -26,6 +26,8 @@ (declare-function realgud:eval-command-p 'realgud-track) (declare-function realgud-set-command-name-hash-to-buffer-local 'realgud-track) (declare-function realgud:truncate-eval-message 'realgud-track) +(declare-function realgud:track-add-breakpoint 'realgud-track) +(declare-function realgud:track-remove-breakpoints 'realgud-track) (test-simple-start) @@ -127,6 +129,27 @@ trepan: That's all, folks... (assert-equal (realgud:truncate-eval-message "cat") "cat")) +(note "realgud:track-remove-breakpoints") +(with-temp-file "test_file.py" + (insert "if 1:\n x = x + 1\n")) + +(setq test-buffer (find-file "test_file.py")) +(realgud-cmdbuf-init test-buffer "trepan" + (gethash "trepan" realgud-pat-hash)) + +(setq bp-num 1) +(setq debugger-bp-output (format "Breakpoint %d set at line %d\n\tin file %s." + bp-num 1 buffer-file-name)) +(save-excursion + (setq bp-loc (realgud-track-bp-loc debugger-bp-output nil)) + (let ((num-overlays (length (overlays-in 0 (point-max))))) + (realgud:track-add-breakpoint bp-loc test-buffer) + (assert-equal (+ 1 num-overlays) (length (overlays-in 0 (point-max)))) + (realgud:track-remove-breakpoints (list bp-loc) (current-buffer)) + (assert-equal num-overlays (length (overlays-in 0 (point-max)))))) +(kill-buffer "test_file.py") +(delete-file "test_file.py") + ;; (setq debugger-bp-output (format "Breakpoint %d set at line %d\n\tin file %s.\n" ;; bp-num line-number test-filename)) ;; (setq bp-loc (realgud-track-bp-loc debugger-bp-output nil))