Skip to content

Commit

Permalink
On killing the client, ask the user about killing the server too
Browse files Browse the repository at this point in the history
  • Loading branch information
Malabarba committed Jul 5, 2015
1 parent a6357ae commit 9e66f87
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

### New features

* [#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.
* [#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.
* [#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.
* [#1174](https://github.com/clojure-emacs/cider/pull/1174): New command `cider-run`, runs the project's `-main` function.
Expand Down
19 changes: 17 additions & 2 deletions nrepl-client.el
Expand Up @@ -626,8 +626,9 @@ older requests with \"done\" status."
Display MESSAGE and if the process is closed kill the
process buffer and run the hook `nrepl-disconnected-hook'."
(message "nREPL: Connection closed (%s)" message)
(if (equal (process-status process) 'closed)
(run-hooks 'nrepl-disconnected-hook)))
(when (equal (process-status process) 'closed)
(run-hooks 'nrepl-disconnected-hook)
(nrepl--maybe-kill-server-buffer 'process-only)))


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

;;; Client: Process Handling

(defun nrepl--maybe-kill-server-buffer (&optional process-only)
"Kill the `nrepl-server-buffer' and its process, subject to user confirmation.
If PROCESS-ONLY is non-nil, don't kill the buffer and don't ask for
confirmation."
(when (and (buffer-live-p nrepl-server-buffer)
(or process-only
(y-or-n-p "Also kill server process and buffer? ")))
(let ((proc (get-buffer-process nrepl-server-buffer)))
(when (process-live-p proc)
(kill-process proc))
(unless process-only
(kill-buffer nrepl-server-buffer)))))

;; `nrepl-start-client-process' is called from `nrepl-server-filter'. It
;; starts the client process described by `nrepl-client-filter' and
;; `nrepl-client-sentinel'.
Expand Down Expand Up @@ -748,6 +762,7 @@ process."

(with-current-buffer client-buf
(-when-let (server-buf (and server-proc (process-buffer server-proc)))
(add-hook 'kill-buffer-hook #'nrepl--maybe-kill-server-buffer 'append 'local)
(setq nrepl-project-dir (buffer-local-value 'nrepl-project-dir server-buf)
nrepl-server-buffer server-buf))
(setq nrepl-endpoint `(,host ,port)
Expand Down

0 comments on commit 9e66f87

Please sign in to comment.