Skip to content

Commit ea8f5ed

Browse files
committed
Merge pull request #1184 from Malabarba/kill-server-with-client
Kill server with client
2 parents 4c4080d + 9e66f87 commit ea8f5ed

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New features
66

7+
* [#1184](https://github.com/clojure-emacs/cider/pull/1184): When the user kills the repl buffer, CIDER will offer to kill the nrepl buffer and process too. Also, when the client (repl) process dies, the server (nrepl) process is killed too.
78
* [#1182](https://github.com/clojure-emacs/cider/pull/1182): New command `cider-browse-instrumented-defs`, displays a buffer listing all defitions currently instrumented by the debugger.
89
* [#1182](https://github.com/clojure-emacs/cider/pull/1182): Definitions currently instrumented by the debugger are marked with a red box in the source buffer.
910
* [#1174](https://github.com/clojure-emacs/cider/pull/1174): New command `cider-run`, runs the project's `-main` function.

cider-interaction.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,8 @@ and automatically removed when killed."
15721572
(when ancillary
15731573
(add-to-list 'cider-ancillary-buffers name)
15741574
(add-hook 'kill-buffer-hook
1575-
(lambda () (setq cider-ancillary-buffers (remove name cider-ancillary-buffers)))))
1575+
(lambda () (setq cider-ancillary-buffers (remove name cider-ancillary-buffers)))
1576+
nil 'local))
15761577
(current-buffer)))
15771578

15781579
(defun cider-emit-into-popup-buffer (buffer value)

nrepl-client.el

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,9 @@ older requests with \"done\" status."
626626
Display MESSAGE and if the process is closed kill the
627627
process buffer and run the hook `nrepl-disconnected-hook'."
628628
(message "nREPL: Connection closed (%s)" message)
629-
(if (equal (process-status process) 'closed)
630-
(run-hooks 'nrepl-disconnected-hook)))
629+
(when (equal (process-status process) 'closed)
630+
(run-hooks 'nrepl-disconnected-hook)
631+
(nrepl--maybe-kill-server-buffer 'process-only)))
631632

632633

633634
;;; Network
@@ -721,6 +722,19 @@ If NO-ERROR is non-nil, show messages instead of throwing an error."
721722

722723
;;; Client: Process Handling
723724

725+
(defun nrepl--maybe-kill-server-buffer (&optional process-only)
726+
"Kill the `nrepl-server-buffer' and its process, subject to user confirmation.
727+
If PROCESS-ONLY is non-nil, don't kill the buffer and don't ask for
728+
confirmation."
729+
(when (and (buffer-live-p nrepl-server-buffer)
730+
(or process-only
731+
(y-or-n-p "Also kill server process and buffer? ")))
732+
(let ((proc (get-buffer-process nrepl-server-buffer)))
733+
(when (process-live-p proc)
734+
(kill-process proc))
735+
(unless process-only
736+
(kill-buffer nrepl-server-buffer)))))
737+
724738
;; `nrepl-start-client-process' is called from `nrepl-server-filter'. It
725739
;; starts the client process described by `nrepl-client-filter' and
726740
;; `nrepl-client-sentinel'.
@@ -748,6 +762,7 @@ process."
748762

749763
(with-current-buffer client-buf
750764
(-when-let (server-buf (and server-proc (process-buffer server-proc)))
765+
(add-hook 'kill-buffer-hook #'nrepl--maybe-kill-server-buffer 'append 'local)
751766
(setq nrepl-project-dir (buffer-local-value 'nrepl-project-dir server-buf)
752767
nrepl-server-buffer server-buf))
753768
(setq nrepl-endpoint `(,host ,port)

0 commit comments

Comments
 (0)