From ce4239800ef1e125bcd64fb5fba2310bbaff2e95 Mon Sep 17 00:00:00 2001 From: Jon Pither Date: Fri, 26 Feb 2016 09:41:14 +0000 Subject: [PATCH] Fixes #1578 in windows process-buffer can be nil --- nrepl-client.el | 50 +++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) 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")