Function: dape--live-connection

dape--live-connection is a natively compiled function defined in dape.el.

Signature

(dape--live-connection TYPE &optional NOWARN REQUIRE-SELECTED)

Documentation

Return connection instance of TYPE.

TYPE is expected to be one of the following symbols:
- parent: Parent connection.
- last: Last created child connection or parent which has an active
  thread.
- running: Last created child connection or parent which has an active
  thread but no stopped threads.
- stopped: Last created child connection or parent which has stopped
  threads.

If NOWARN is non-nil does not error on no active process. If REQUIRE-SELECTED is non-nil require returned connection to be the selected one, this has no effect when TYPE is parent. See dape--connection-selected.

Source Code

;; Defined in /nix/store/1fiaif8pifqj2jh65rbg3fkhg3i56q42-emacs-packages-deps/share/emacs/site-lisp/elpa/dape-0.27.1/dape.el
;;; Connection

(defun dape--live-connection (type &optional nowarn require-selected)
  "Return connection instance of TYPE.
TYPE is expected to be one of the following symbols:
- parent: Parent connection.
- last: Last created child connection or parent which has an active
  thread.
- running: Last created child connection or parent which has an active
  thread but no stopped threads.
- stopped: Last created child connection or parent which has stopped
  threads.

If NOWARN is non-nil does not error on no active process.
If REQUIRE-SELECTED is non-nil require returned connection to be the
selected one, this has no effect when TYPE is parent.
See `dape--connection-selected'."
  (let* ((connections (dape--live-connections))
         (selected (cl-find dape--connection-selected connections))
         (ordered
          `(,@(when selected
                (list selected))
            ,@(unless (and require-selected selected)
                (reverse connections))))
         (conn
          (pcase type
            ('parent (or (and selected (dape--root-of selected))
                         (and connections (dape--root-of (car connections)))))
            ('last (cl-find-if #'dape--thread-id ordered))
            ('running (cl-find-if (lambda (conn)
                                    (and (dape--thread-id conn)
                                         (not (dape--stopped-threads conn))))
                                  ordered))
            ('stopped (cl-find-if (lambda (conn)
                                    (and (dape--stopped-threads conn)))
                                  ordered)))))
    (unless (or nowarn conn)
      (user-error "No %sdebug connection"
                  ;; `parent' and `last' does not make sense to the user
                  (if (memq type '(running stopped))
                      (format "%s " type) "")))
    conn))