Function: nrepl--port-from-file

nrepl--port-from-file is a byte-compiled function defined in nrepl-client.el.

Signature

(nrepl--port-from-file FILE)

Documentation

Attempts to read port from a file named by FILE.

Discards it if it can be determined that the port is not active.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260414.1619/nrepl-client.el
(defun nrepl--port-from-file (file)
  "Attempts to read port from a file named by FILE.

Discards it if it can be determined that the port is not active."
  (when (file-exists-p file)
    (when-let* ((port-string (with-temp-buffer
                               (insert-file-contents file)
                               (buffer-string)))
                ;; extract the number, most of all for not passing garbage to `lsof' (which might even be a security risk):
                (port-number (nrepl--port-string-to-number port-string)))
      (if (eq system-type 'windows-nt)
          port-string
        (unless (equal ""
                       (shell-command-to-string (format "lsof -i:%s" port-number)))
          port-string)))))