emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/realgud 7cc1230 047/140: extract method for breakpoint


From: Rocky Bernstein
Subject: [elpa] externals/realgud 7cc1230 047/140: extract method for breakpoint stuff in realgud:track-from-region
Date: Sat, 25 May 2019 19:35:30 -0400 (EDT)

branch: externals/realgud
commit 7cc123013cdae5b8f46353ca990d03fc193c713a
Author: Jacob O'Donnell <address@hidden>
Commit: Jacob O'Donnell <address@hidden>

    extract method for breakpoint stuff in realgud:track-from-region
---
 realgud/common/track.el | 41 +++++++++++++++++++++++------------------
 test/test-track.el      | 23 +++++++++++++++++++++++
 2 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/realgud/common/track.el b/realgud/common/track.el
index 1bae618..164edc4 100644
--- a/realgud/common/track.el
+++ b/realgud/common/track.el
@@ -223,18 +223,17 @@ 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 (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,
+              ;; 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))
@@ -249,13 +248,8 @@ evaluating (realgud-cmdbuf-info-loc-regexp 
realgud-cmdbuf-info)"
                  (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)
-                     )))
+              (realgud:track-add-breakpoint (realgud-track-bp-loc 
text-sans-loc cmd-mark cmdbuf) cmdbuf)
+
              (if loc
                  (let ((selected-frame
                         (or (not frame-num)
@@ -264,18 +258,30 @@ evaluating (realgud-cmdbuf-info-loc-regexp 
realgud-cmdbuf-info)"
                                               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)
-                      ))))
+                (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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]