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

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

[elpa] externals/dape c204a11474 3/4: Add persistent breakpoints with `d


From: ELPA Syncer
Subject: [elpa] externals/dape c204a11474 3/4: Add persistent breakpoints with `dape-use-savehist'
Date: Tue, 27 Feb 2024 12:58:15 -0500 (EST)

branch: externals/dape
commit c204a114748039cf01f46c8f375b6881e7560108
Author: Daniel Pettersson <daniel@dpettersson.net>
Commit: Daniel Pettersson <daniel@dpettersson.net>

    Add persistent breakpoints with `dape-use-savehist'
    
    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.
---
 README.org |  5 ++++-
 dape.el    | 43 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/README.org b/README.org
index 7d32295266..459bcc7825 100644
--- a/README.org
+++ b/README.org
@@ -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)
diff --git a/dape.el b/dape.el
index 251437305d..e843d4e62b 100644
--- a/dape.el
+++ b/dape.el
@@ -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
@@ -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)
@@ -4329,6 +4333,41 @@ See `eldoc-documentation-functions', for more 
infomation."
                (" [" (: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
 
 (defvar dape-global-map



reply via email to

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