Skip to content

Commit

Permalink
Add persistent breakpoints with `dape-use-savehist'
Browse files Browse the repository at this point in the history
Suggested in #76

As dape currently only recognize breakpoints in buffers, dape opens
buffers which contained breakpoints on startup.  Another use is also
possible, if `dape-use-savehist` is set after `dape` is loaded ie. in
`:config` and `(add-hook 'dape-on-start-hooks 'dape-savehist-load)`
buffer breakpoint buffers will be opened on `dape` start instead.

An idea might be to implement dape breakpoints without overlays.
  • Loading branch information
svaante committed Feb 27, 2024
1 parent 3da0840 commit c204a11
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ Currently =Dape= does not come with any debug adapter configuration.
;; May also need to set/change gud (gdb-mi) key prefix
;; (setq gud-key-prefix "\C-x\C-a")

:init
;; To use window configuration like gud (gdb-mi)
;; :init
;; (setq dape-buffer-window-arrangement 'gud)

;; To save breakpoints and exceptions with `savehist-mode'
;; (setq dape-use-savehist t)

:config
;; Info buffers to the right
;; (setq dape-buffer-window-arrangement 'right)
Expand Down
43 changes: 41 additions & 2 deletions dape.el
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,11 @@ left-to-right display order of the properties."
"Function to run compile with."
:type 'function)

(defcustom dape-use-savehist nil
"Use `savehist-mode' to store breakpoints exceptions.
Make sure to set `dape-use-savehist' before loading `dape'."
:type 'boolean)

(defcustom dape-cwd-fn #'dape--default-cwd
"Function to get current working directory.
The function should take one optional argument and return a string
Expand Down Expand Up @@ -1278,8 +1283,7 @@ See `dape-request' for expected CB signature."
(with-current-buffer buffer
(or dape--source
(list
:name (file-name-nondirectory
(buffer-file-name buffer))
:name (file-name-nondirectory (buffer-file-name buffer))
:path (dape--path (buffer-file-name buffer) 'remote)))))))
(dape--with-request-bind
((&key breakpoints &allow-other-keys) error)
Expand Down Expand Up @@ -4328,6 +4332,41 @@ See `eldoc-documentation-functions', for more infomation."
`(dape-active-mode
(" [" (:eval (dape--mode-line-format)) "] ")))


;;; Savehist mode

(defvar dape--breakpoints-savehist nil
"Used to save and load `dape--breakpoints' in an printable format.")

(defun dape-savehist-load ()
"Load breakpoints and exceptions saved by `savehist-mode'."
(when dape-use-savehist
(add-to-list 'savehist-additional-variables #'dape--breakpoints-savehist)
(add-to-list 'savehist-additional-variables #'dape--exceptions)
(cl-loop for (file point . args) in dape--breakpoints-savehist
do (ignore-errors
(with-current-buffer (find-file-noselect file)
(save-excursion
(goto-char point)
(apply #'dape--breakpoint-place args)))))
(add-hook 'savehist-save-hook #'dape--breakpoints-savehist-save))
(remove-hook 'savehist-mode-hook #'dape-savehist-load))

(defun dape--breakpoints-savehist-save ()
"Store breakpoints in an printable format for `savehist-mode'."
(setq dape--breakpoints-savehist
(cl-loop with arg-symbols = '(dape-log-message dape-expr-message)
for ov in dape--breakpoints
for file = (buffer-file-name (overlay-buffer ov))
for point = (overlay-start ov)
for args = (mapcar (apply-partially 'overlay-get ov) arg-symbols)
when (and file point)
collect (append (list file point) args))))

(if (bound-and-true-p savehist-loaded)
(dape-savehist-load)
(add-hook 'savehist-mode-hook #'dape-savehist-load))


;;; Keymaps

Expand Down

0 comments on commit c204a11

Please sign in to comment.