Function: cider--running-non-lein-nrepl-paths
cider--running-non-lein-nrepl-paths is a byte-compiled function
defined in cider-endpoint.el.
Signature
(cider--running-non-lein-nrepl-paths)
Documentation
Retrieve (directory, port) pairs of running nREPL servers other than Lein ones.
This also covers lein trampoline REPLs: the trampolined JVM carries no
"leiningen" marker at all in its command line (so the Lein scan can't
see it), but it does run clojure.main -i /tmp/form-init<...>.clj, which
is what the form-init pattern below matches.
Source Code
;; Defined in ~/.emacs.d/elpa/cider-20260822.1520/cider-endpoint.el
(defun cider--running-non-lein-nrepl-paths ()
"Retrieve (directory, port) pairs of running nREPL servers other than Lein ones.
This also covers `lein trampoline' REPLs: the trampolined JVM carries no
\"leiningen\" marker at all in its command line (so the Lein scan can't
see it), but it does run `clojure.main -i /tmp/form-init<...>.clj', which
is what the form-init pattern below matches."
(unless (eq system-type 'windows-nt)
(let* ((bb-indicator "--nrepl-server")
(non-lein-nrepl-pids
(thread-last (split-string
(cider--shell-command-to-string
;; some of the `ps ux` lines we intend to catch:
;; <username> 15411 0.0 0.0 37915744 16084 s000 S+ 3:02PM 0:00.02 bb --nrepl-server
;; <username> 13835 0.1 11.2 37159036 7528432 s009 S+ 2:47PM 6:41.29 java -cp src -m nrepl.cmdline
;; <username> 49859 0.0 0.4 443188240 105040 ?? SN 3:13PM 0:00.89 java -classpath ... clojure.main -i /tmp/form-init123.clj
(format "ps ux | grep -E 'java|%s' | grep -E 'nrepl.cmdline|%s|form-init' | grep -v -E 'leiningen|grep'"
bb-indicator
bb-indicator))
"\n")
;; whitespace-split (not single-space): ps pads
;; columns, and a short pid would otherwise yield ""
(mapcar (lambda (s)
(nth 1 (split-string s))))
(seq-filter #'identity))))
(when non-lein-nrepl-pids
(thread-last non-lein-nrepl-pids
(mapcar (lambda (pid)
(let* ((directory (cider--lsof-fn-field
(list "-a" "-d" "cwd" "-n" "-Fn" "-p" pid)))
;; -sTCP:LISTEN: only listening sockets.
;; Without it the first socket may be an
;; outbound connection, whose *remote*
;; port we'd then extract.
(port-line (cider--lsof-fn-field
(list "-n" "-P" "-Fn" "-i" "-sTCP:LISTEN" "-a" "-p" pid)))
(port (when port-line
(replace-regexp-in-string ".*:" "" port-line)))
(port (when (and port
(condition-case nil
(numberp (read port))
(error nil)))
port)))
(list directory port))))
(seq-filter #'cadr))))))