Function: dape-config-autoport
dape-config-autoport is a natively compiled function defined in
dape.el.
Signature
(dape-config-autoport CONFIG)
Documentation
Handle :autoport in CONFIG keys port, command-args, and command-env.
If port is the symbol :autoport, replace it with a random free port
number. In addition, replace all occurences of :autoport (symbol or
string) in command-args and all property values of command-env with
the value of config key port.
Source Code
;; Defined in /nix/store/1fiaif8pifqj2jh65rbg3fkhg3i56q42-emacs-packages-deps/share/emacs/site-lisp/elpa/dape-0.27.1/dape.el
(defun dape-config-autoport (config)
"Handle :autoport in CONFIG keys `port', `command-args', and `command-env'.
If `port' is the symbol `:autoport', replace it with a random free port
number. In addition, replace all occurences of `:autoport' (symbol or
string) in `command-args' and all property values of `command-env' with
the value of config key `port'."
(when (eq (plist-get config 'port) :autoport)
;; Stolen from `Eglot'
(let ((port-probe
(make-network-process :name "dape-port-probe-dummy"
:server t
:host "localhost"
:service 0)))
(plist-put config
'port
(unwind-protect
(process-contact port-probe :service)
(delete-process port-probe)))))
(when-let* ((port (plist-get config 'port))
(port-string (number-to-string port))
(replace-fn (lambda (arg)
(cond
((eq arg :autoport) port-string)
((stringp arg) (string-replace ":autoport" port-string arg))
(t arg)))))
(when-let* ((command-args (plist-get config 'command-args)))
(plist-put config 'command-args (seq-map replace-fn command-args)))
(when-let* ((command-env (plist-get config 'command-env)))
(plist-put config 'command-env
(cl-loop for (key value) on command-env by #'cddr
collect key
collect (apply replace-fn (list value))))))
config)