Skip to content

Commit

Permalink
Fixes clojure-emacs#1578 in windows process-buffer can be nil
Browse files Browse the repository at this point in the history
  • Loading branch information
jonpither committed Feb 26, 2016
1 parent 6c7e9d1 commit ce42398
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions nrepl-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit ce42398

Please sign in to comment.