3838; ;
3939; ; The nREPL communication process can be broadly represented as follows:
4040; ;
41- ; ; 1) The server process is started as an Emacs subprocess (usually by
42- ; ; `cider-jack-in' , which in turn fires up an nREPL server). Note that
43- ; ; if a connection was established using `cider-connect' there won't be
44- ; ; a server process.
41+ ; ; 1) The server process is started as an Emacs subprocess (e.g. via
42+ ; ; `nrepl-start-server-process' ). Note that if a connection was
43+ ; ; established directly there won't be a server process.
4544; ;
4645; ; 2) The server's process filter (`nrepl-server-filter' ) detects the
4746; ; connection port from the first plain text response from the server and
7473(require 'cl-lib )
7574(require 'nrepl-dict )
7675(require 'nrepl-bencode )
77- (require 'sesman )
7876(require 'tramp )
7977
8078; ;; Custom
@@ -159,7 +157,9 @@ To be used for tooling calls (i.e. completion, eldoc, etc)")
159157
160158(defconst nrepl-message-buffer-name-template " *nrepl-messages %s(%r:%S)*" )
161159(defconst nrepl-error-buffer-name " *nrepl-error*" )
162- (defconst nrepl-repl-buffer-name-template " *cider-repl %s(%r:%S)*" )
160+ (defvar nrepl-repl-buffer-name-template " *nrepl-repl %s(%r:%S)*"
161+ " Template for naming REPL buffers.
162+ See `nrepl-format-buffer-name-function' for the format specifiers." )
163163(defconst nrepl-server-buffer-name-template " *nrepl-server %s*" )
164164(defconst nrepl-tunnel-buffer-name-template " *nrepl-tunnel %s*" )
165165
@@ -314,9 +314,10 @@ and kill the process buffer."
314314 (substring message 0 -1 )))
315315 (when (equal (process-status process) 'closed )
316316 (when-let* ((client-buffer (process-buffer process)))
317- (sesman-remove-object 'CIDER nil client-buffer
318- (not (process-get process :keep-server ))
319- 'no-error )
317+ (when nrepl-client-disconnected-handler-function
318+ (funcall nrepl-client-disconnected-handler-function
319+ client-buffer
320+ (not (process-get process :keep-server ))))
320321 (nrepl--clear-client-sessions client-buffer)
321322 (with-current-buffer client-buffer
322323 (goto-char (point-max ))
@@ -607,8 +608,10 @@ which we can eventually reuse."
607608; ; After being decoded, responses (aka, messages from the server) are dispatched
608609; ; to handlers. Handlers are constructed with `nrepl-make-response-handler' .
609610
610- (defvar nrepl-err-handler nil
611- " Evaluation error handler." )
611+ (define-obsolete-variable-alias 'nrepl-err-handler 'nrepl-err-handler-function " 1.17.0" )
612+ (defvar nrepl-err-handler-function nil
613+ " Function to call on evaluation errors.
614+ Called with one argument: the REPL buffer." )
612615
613616(defvar nrepl-need-input-handler-function nil
614617 " Function to call when the server requests stdin input.
@@ -620,6 +623,11 @@ When nil, need-input requests are ignored.")
620623Called with two arguments: BUFFER and NS (string).
621624When nil, namespace changes are ignored." )
622625
626+ (defvar nrepl-client-disconnected-handler-function nil
627+ " Function to call when a client connection is closed.
628+ Called with two arguments: CLIENT-BUFFER and KILL-SERVER-P.
629+ Used by the client to clean up session state on disconnect." )
630+
623631(defun nrepl--mark-id-completed (id )
624632 " Move ID from `nrepl-pending-requests' to `nrepl-completed-requests' .
625633It is safe to call this function multiple times on the same ID."
@@ -665,7 +673,7 @@ Handlers are functions of the buffer and the value they handle, except for
665673the optional CONTENT-TYPE-HANDLER which should be a function of the buffer,
666674content, the content-type to be handled as a list `(type attrs)'.
667675
668- If the optional EVAL-ERROR-HANDLER is nil, the default `nrepl-err-handler'
676+ If the optional EVAL-ERROR-HANDLER is nil, the default `nrepl-err-handler-function '
669677is used. If any of the other supplied handlers are nil nothing happens for
670678the corresponding type of response."
671679 (lambda (response )
@@ -694,7 +702,7 @@ the corresponding type of response."
694702 (when (member " interrupted" status)
695703 (message " Evaluation interrupted. " ))
696704 (when (member " eval-error" status)
697- (funcall (or eval-error-handler nrepl-err-handler) buffer))
705+ (funcall (or eval-error-handler nrepl-err-handler-function ) buffer))
698706 (when (member " namespace-not-found" status)
699707 (message " Namespace `%s' not found. " ns))
700708 (when (and (member " need-input" status)
@@ -794,7 +802,7 @@ command and e.g. notify the user about them."
794802 (when (member " done" status)
795803 (nrepl-dbind-response response (ex err eval-error id)
796804 (when (and ex err eval-error)
797- (funcall nrepl-err-handler))
805+ (funcall nrepl-err-handler-function ))
798806 (when id
799807 (with-current-buffer connection
800808 (nrepl--mark-id-completed id)))
0 commit comments