Skip to content

Commit 9a6c2eb

Browse files
committed
Remove sesman dependency from nrepl-client.el
Replace the hardcoded sesman-remove-object call in nrepl-client-sentinel with nrepl-client-disconnected-handler-function hook. CIDER sets this to cider--remove-session-on-disconnect. Also: - Remove the sesman require from nrepl-client.el - Change nrepl-repl-buffer-name-template from defconst to defvar with a generic default; CIDER sets it to "*cider-repl*" on load - Update commentary to remove CIDER-specific function references nrepl-client.el now depends only on: seq, subr-x, cl-lib, nrepl-dict, nrepl-bencode, and tramp.
1 parent 6e21e35 commit 9a6c2eb

4 files changed

Lines changed: 37 additions & 20 deletions

File tree

lisp/cider-connection.el

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
(require 'cider-popup)
3939
(require 'cider-util)
4040

41+
;; Override nrepl-client's default REPL buffer name.
42+
(setq nrepl-repl-buffer-name-template "*cider-repl %s(%r:%S)*")
43+
4144
(defcustom cider-session-name-template "%J:%h:%p"
4245
"Format string to use for session names.
4346
See `cider-format-connection-params' for available format characters."
@@ -915,6 +918,11 @@ PARAMS is a plist as received by `cider-repl-create'."
915918
(when (not (cider-clojure-major-mode-p))
916919
(cider-set-buffer-ns ns)))))
917920

921+
(defun cider--remove-session-on-disconnect (client-buffer kill-server-p)
922+
"Remove CLIENT-BUFFER from its sesman session.
923+
When KILL-SERVER-P is non-nil, also remove the associated server."
924+
(sesman-remove-object 'CIDER nil client-buffer kill-server-p 'no-error))
925+
918926
(defun cider--handle-notification (response)
919927
"Handle notification status in nREPL RESPONSE.
920928
Emits the notification message to the REPL buffer."
@@ -954,10 +962,11 @@ function with the repl buffer set as current."
954962
(sesman-add-object 'CIDER ses-name buffer 'allow-new)
955963
(unless (derived-mode-p 'cider-repl-mode)
956964
(cider-repl-mode))
957-
(setq nrepl-err-handler #'cider-default-err-handler
965+
(setq nrepl-err-handler-function #'cider-default-err-handler
958966
nrepl-need-input-handler-function #'cider-need-input
959967
nrepl-namespace-handler-function #'cider--update-buffer-ns
960968
nrepl-close-connection-handler-function #'cider--close-connection
969+
nrepl-client-disconnected-handler-function #'cider--remove-session-on-disconnect
961970
nrepl-format-buffer-name-function #'cider-format-connection-params
962971
nrepl-client-name "CIDER"
963972
nrepl-client-version cider-version

lisp/cider-eval.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ The handler simply inserts the result value in BUFFER."
641641
;; eval-error handler
642642
(lambda (_buffer)
643643
(setq failed t)
644-
(funcall nrepl-err-handler source-buffer)))))
644+
(funcall nrepl-err-handler-function source-buffer)))))
645645

646646
(defun cider--emit-interactive-eval-output (output repl-emit-function)
647647
"Emit output resulting from interactive code evaluation.
@@ -899,9 +899,9 @@ This is used by pretty-printing commands."
899899
cider-ancillary-buffers))
900900
(with-selected-window (get-buffer-window chosen-buffer)
901901
(cider-popup-buffer-quit-function t)))
902-
;; also call the default nrepl-err-handler, so that our custom behavior doesn't void the base behavior:
903-
(when nrepl-err-handler
904-
(funcall nrepl-err-handler source-buffer)))
902+
;; also call the default nrepl-err-handler-function, so that our custom behavior doesn't void the base behavior:
903+
(when nrepl-err-handler-function
904+
(funcall nrepl-err-handler-function source-buffer)))
905905
;; content type handler:
906906
nil
907907
;; truncated handler:

lisp/cider-repl.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ and responding to them.")
10601060
(cider-repl-maybe-trim-buffer buffer))
10611061
(dolist (f cider--repl-done-functions)
10621062
(funcall f buffer)))
1063-
nrepl-err-handler
1063+
nrepl-err-handler-function
10641064
(lambda (buffer value content-type)
10651065
(if-let* ((content-attrs (cadr content-type))
10661066
(content-type* (car content-type))

lisp/nrepl-client.el

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@
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
@@ -74,7 +73,6 @@
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.")
620623
Called with two arguments: BUFFER and NS (string).
621624
When 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'.
625633
It 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
665673
the optional CONTENT-TYPE-HANDLER which should be a function of the buffer,
666674
content, 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'
669677
is used. If any of the other supplied handlers are nil nothing happens for
670678
the 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

Comments
 (0)