From c95769af8e57c934fa138abff38d7a45a1f35cc0 Mon Sep 17 00:00:00 2001 From: Jon Pither Date: Fri, 26 Feb 2016 09:55:17 +0000 Subject: [PATCH] Fixes #1578 in windows process-buffer can be nil --- CHANGELOG.md | 1 + nrepl-client.el | 50 +++++++++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a05a5455..e5adb6729 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ and try to associate the created connection with this project automatically. ### Bugs fixed +* [#1578](https://github.com/clojure-emacs/cider/issues/1578): Nrepl-server-filter called with dead process buffer in Windows. * [#1441](https://github.com/clojure-emacs/cider/issues/1441): Don't popup a buffer that's already displayed. * [#1557](https://github.com/clojure-emacs/cider/issues/1557): When a sibling REPL is started by hasn't yet turned into a cljs REPL, it won't hijack clj requests. * [#1562](https://github.com/clojure-emacs/cider/issues/1562): Actually disable cider-mode when it gets disabled. diff --git a/nrepl-client.el b/nrepl-client.el index be812c0e1..9764a98bd 100644 --- a/nrepl-client.el +++ b/nrepl-client.el @@ -1111,30 +1111,32 @@ the port, and the client buffer." (defun nrepl-server-filter (process output) "Process nREPL server output from PROCESS contained in OUTPUT." - (with-current-buffer (process-buffer process) - ;; auto-scroll on new output - (let ((moving (= (point) (process-mark process)))) - (save-excursion - (goto-char (process-mark process)) - (insert output) - (set-marker (process-mark process) (point))) - (when moving - (goto-char (process-mark process)) - (when-let ((win (get-buffer-window))) - (set-window-point win (point)))))) - ;; detect the port the server is listening on from its output - (when (string-match "nREPL server started on port \\([0-9]+\\)" output) - (let ((port (string-to-number (match-string 1 output)))) - (message "nREPL server started on %s" port) - (with-current-buffer (process-buffer process) - (let* ((client-proc (nrepl-start-client-process nil port process)) - (client-buffer (process-buffer client-proc))) - (setq nrepl-client-buffers - (cons client-buffer - (delete client-buffer nrepl-client-buffers))) - - (when (functionp nrepl-post-client-callback) - (funcall nrepl-post-client-callback client-buffer))))))) + ;; In Windows this can be false: + (when (buffer-live-p (process-buffer process)) + (with-current-buffer (process-buffer process) + ;; auto-scroll on new output + (let ((moving (= (point) (process-mark process)))) + (save-excursion + (goto-char (process-mark process)) + (insert output) + (set-marker (process-mark process) (point))) + (when moving + (goto-char (process-mark process)) + (when-let ((win (get-buffer-window))) + (set-window-point win (point)))))) + ;; detect the port the server is listening on from its output + (when (string-match "nREPL server started on port \\([0-9]+\\)" output) + (let ((port (string-to-number (match-string 1 output)))) + (message "nREPL server started on %s" port) + (with-current-buffer (process-buffer process) + (let* ((client-proc (nrepl-start-client-process nil port process)) + (client-buffer (process-buffer client-proc))) + (setq nrepl-client-buffers + (cons client-buffer + (delete client-buffer nrepl-client-buffers))) + + (when (functionp nrepl-post-client-callback) + (funcall nrepl-post-client-callback client-buffer)))))))) (declare-function cider--close-connection-buffer "cider-client")