Browse Source

Refactor indium-breakpoint-remove-all

* indium-breakpoint.el (indium-breakpoint-remove-all): Refactor, with a new
  utility function `indium-breakpoint--breakpoints-in-buffer-do'.
workspaces
Nicolas Petton 3 years ago
parent
commit
3e5b51cddf
No known key found for this signature in database GPG Key ID: E8BCD7866AFCF978
1 changed files with 17 additions and 10 deletions
  1. +17
    -10
      indium-breakpoint.el

+ 17
- 10
indium-breakpoint.el View File

@ -73,8 +73,11 @@ CONDITION is true."
(defun indium-breakpoint-remove-all ()
"Remove all breakpoints from the current buffer's file."
(indium-breakpoint-remove-all-overlays)
(indium-breakpoint-unregister-breakpoints-from-backend))
(indium-breakpoint--breakpoints-in-buffer-do
(lambda (_ ov)
(save-excursion
(goto-char (overlay-start ov))
(indium-breakpoint-remove)))))
(defun indium-breakpoint-resolve (id script location)
"Update the breakpoint with ID for SCRIPT at LOCATION.
@ -114,14 +117,6 @@ This function does no unset breakpoints."
'indium-breakpoint-ov
t))
(defun indium-breakpoint-unregister-breakpoints-from-backend ()
"Remove all breakpoints from the current buffer.
This function does not remove any breakpoint overlay."
(seq-do (lambda (brk)
(indium-backend-unregister-breakpoint (indium-current-connection-backend)
(indium-breakpoint-id brk)))
(indium-current-connection-get-breakpoints-in-file buffer-file-name)))
(defun indium-breakpoint--add-overlay (breakpoint)
"Add an overlay for BREAKPOINT on the current line.
@ -234,6 +229,18 @@ If there is no overlay, make one."
;; Update/Restore breakpoints
(add-hook 'indium-update-script-source-hook #'indium-breakpoint--update-after-script-source-set)
(add-hook 'indium-script-parsed-hook #'indium-breakpoint--update-after-script-parsed)
;; Helpers
(defun indium-breakpoint--breakpoints-in-buffer-do (fn)
"Evaluate FN on all breakpoints in the current buffer.
FN takes two arguments, the breakpoint and its associated
overlay."
(let ((overlays (overlays-in (point-min) (point-max))))
(seq-doseq (ov overlays)
(when-let ((brk (overlay-get ov 'indium-breakpoint)))
(funcall fn brk ov)))))
(when (and (fboundp 'define-fringe-bitmap) (display-images-p))
(define-fringe-bitmap 'indium-breakpoint


Loading…
Cancel
Save