Commits

Anonymous committed 505fd68

Make connect keys more robust

  • Participants
  • Parent commits be2b863

Comments (0)

Files changed (1)

       (define-key (current-global-map)
         (read-kbd-macro k)
         (lexical-let ((port (+ 4004 n)))
-          (lambda ()
-            (interactive)
-            (let ((conn (find port
-                              nrepl-connection-list
-                              :test (lambda (port conn)
-                                      (= port (cadr (nrepl-connection-infos (get-buffer conn))))))))
-              (if conn
-                  (progn
-                    (setq nrepl-connection-list (cons conn (delete conn nrepl-connection-list)))
-                    (nrepl-show-current-connection))
-                (nrepl-connect "127.0.0.1" port))
-              (nrepl-switch-to-repl-buffer (car nrepl-connection-list)))))))))
+          (lambda (arg)
+            (interactive "P")
+            (let* ((conn (find port
+                               (nrepl-connection-buffers)
+                               :test (lambda (port conn)
+                                       (= port (cadr (nrepl-connection-infos (get-buffer conn)))))))
+                   (conn (or conn (process-buffer (nrepl-connect "127.0.0.1" port)))))
+              (nrepl-make-repl-connection-default conn)
+              (let ((nrepl-connection-buffer conn))
+                (nrepl-switch-to-repl-buffer arg))
+              (nrepl-show-current-connection))))))))
 
 (nrepl-define-connect-keys)