Function: nrepl-client-sentinel

nrepl-client-sentinel is a byte-compiled function defined in nrepl-client.el.

Signature

(nrepl-client-sentinel PROCESS MESSAGE)

Documentation

Handle sentinel events from PROCESS.

Notify MESSAGE and if the process is closed run nrepl-disconnected-hook and kill the process buffer.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260822.1520/nrepl-client.el
(defun nrepl-client-sentinel (process message)
  "Handle sentinel events from PROCESS.
Notify MESSAGE and if the process is closed run `nrepl-disconnected-hook'
and kill the process buffer."
  (if (string-match "deleted\\b" message)
      (message "[nREPL] Connection closed")
    (message "[nREPL] Connection closed unexpectedly (%s)"
             (substring message 0 -1)))
  (when (equal (process-status process) 'closed)
    (when-let* ((client-buffer (process-buffer process)))
      (when nrepl-client-disconnected-handler-function
        (funcall nrepl-client-disconnected-handler-function
                 client-buffer
                 (not (process-get process :keep-server))))
      (nrepl--clear-client-sessions client-buffer)
      (with-current-buffer client-buffer
        (goto-char (point-max))
        (insert-before-markers
         (propertize
          (format "\n*** Closed on %s ***\n" (replace-regexp-in-string "  +"
                                                                       " "
                                                                       (current-time-string)))
          'face 'error))
        (run-hooks 'nrepl-disconnected-hook)
        ;; Tear down the SSH tunnel, if any, so its `ssh' subprocess
        ;; doesn't outlive the connection.  The orderly path through
        ;; `cider--close-connection' already does this; we duplicate it
        ;; here so abnormal disconnects (server crash, network drop,
        ;; client process killed) don't leak the tunnel.
        (when (buffer-live-p nrepl-tunnel-buffer)
          (when-let* ((tunnel-proc (get-buffer-process nrepl-tunnel-buffer)))
            (when (process-live-p tunnel-proc)
              (delete-process tunnel-proc)))
          (kill-buffer nrepl-tunnel-buffer))
        (setq nrepl-tunnel-buffer nil)
        (let ((server-buffer nrepl-server-buffer))
          (when (and (buffer-live-p server-buffer)
                     (not (process-get process :keep-server)))
            (setq nrepl-server-buffer nil)
            (nrepl--maybe-kill-server-buffer server-buffer)))))))