Skip to content

Commit fd1aa58

Browse files
authored
dap-debug: remove compilation hook after use (#472)
Prevent hooks from piling up each time dap-debug is called with 'dap-compilation' set in launch.json. If they do, multiple debug sessions will be started after a successful compilation, not necessarily linked to the current debug target but to previous ones.
1 parent eda3299 commit fd1aa58

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

dap-mode.el

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,17 +1694,18 @@ be used to compile the project, spin up docker, ...."
16941694
(with-current-buffer (compilation-start dap-compilation t (lambda (&rest _)
16951695
"*DAP compilation*"))
16961696
(let (window)
1697-
(add-hook 'compilation-finish-functions
1698-
(lambda (buf status &rest _)
1699-
(if (string= "finished\n" status)
1700-
(progn
1701-
(when (and (not dap-debug-compilation-keep)
1702-
(window-live-p window)
1703-
(eq buf (window-buffer window)))
1704-
(delete-window window))
1705-
(funcall cb))
1706-
(lsp--error "Compilation step failed"))))
1707-
(setq window (display-buffer (current-buffer))))))
1697+
(cl-labels ((cf (buf status &rest _)
1698+
(remove-hook 'compilation-finish-functions #'cf)
1699+
(if (string= "finished\n" status)
1700+
(progn
1701+
(when (and (not dap-debug-compilation-keep)
1702+
(window-live-p window)
1703+
(eq buf (window-buffer window)))
1704+
(delete-window window))
1705+
(funcall cb))
1706+
(lsp--error "Compilation step failed"))))
1707+
(add-hook 'compilation-finish-functions #'cf)
1708+
(setq window (display-buffer (current-buffer)))))))
17081709
(funcall cb))))
17091710

17101711
(defun dap-debug-edit-template (&optional debug-args)

0 commit comments

Comments
 (0)