@@ -923,6 +923,7 @@ With the prefix argument, prompt for all these parameters."
923923 (interactive " P" )
924924 (let ((params (thread-first params
925925 (cider--update-project-dir)
926+ (cider--check-existing-session)
926927 (cider--update-jack-in-cmd))))
927928 (nrepl-start-server-process
928929 (plist-get params :project-dir )
@@ -944,6 +945,7 @@ prompt for all these parameters."
944945 ; ; cider--update-jack-in-cmd relies indirectly on the above dynamic vars
945946 (let ((params (thread-first params
946947 (cider--update-project-dir)
948+ (cider--check-existing-session)
947949 (cider--update-jack-in-cmd))))
948950 (nrepl-start-server-process
949951 (plist-get params :project-dir )
@@ -967,8 +969,10 @@ cljs REPL only when the ClojureScript dependencies are met."
967969 ; ; cider--update-jack-in-cmd relies indirectly on the above dynamic vars
968970 (let ((params (thread-first params
969971 (cider--update-project-dir)
972+ (cider--check-existing-session)
970973 (cider--update-jack-in-cmd)
971974 (cider--update-cljs-type)
975+ ; ; already asked, don't ask on sibling connect
972976 (plist-put :do-prompt nil ))))
973977 (nrepl-start-server-process
974978 (plist-get params :project-dir )
@@ -1032,6 +1036,7 @@ prefix argument, prompt for all the parameters."
10321036 (thread-first params
10331037 (cider--update-project-dir)
10341038 (cider--update-host-port)
1039+ (cider--check-existing-session)
10351040 (plist-put :repl-init-function nil )
10361041 (plist-put :session-name nil )
10371042 (plist-put :repl-type " clj" ))))
@@ -1047,6 +1052,7 @@ parameters regardless of their supplied or default values."
10471052 (thread-first params
10481053 (cider--update-project-dir)
10491054 (cider--update-host-port)
1055+ (cider--check-existing-session)
10501056 (cider--update-cljs-type)
10511057 (cider--update-cljs-init-function)
10521058 (plist-put :session-name nil )
@@ -1062,6 +1068,7 @@ non-nil, don't start if ClojureScript requirements are not met."
10621068 (let* ((params (thread-first params
10631069 (cider--update-project-dir)
10641070 (cider--update-host-port)
1071+ (cider--check-existing-session)
10651072 (cider--update-cljs-type)))
10661073 (clj-repl (cider-connect-clj params)))
10671074 (if soft-cljs-start
@@ -1208,6 +1215,30 @@ non-nil, don't start if ClojureScript requirements are not met."
12081215 cider-offer-to-open-cljs-app-in-browser)
12091216 (cider--offer-to-open-app-in-browser nrepl-server-buffer)))))))
12101217
1218+ (defun cider--check-existing-session (params )
1219+ " Ask for confirmation if a session with similar PARAMS already exists.
1220+ If no session exists or user chose to proceed, return PARAMS. If the user
1221+ canceled the action, signal quit."
1222+ (let* ((proj-dir (plist-get params :project-dir ))
1223+ (host (plist-get params :host ))
1224+ (port (plist-get params :port ))
1225+ (session (seq-find (lambda (ses )
1226+ (let ((ses-params (cider--gather-session-params ses)))
1227+ (and (equal proj-dir (plist-get ses-params :project-dir ))
1228+ (or (null port)
1229+ (equal port (plist-get ses-params :port )))
1230+ (or (null host)
1231+ (equal host (plist-get ses-params :host ))))))
1232+ (sesman-linked-sessions 'CIDER '(project)))))
1233+ (when session
1234+ (unless (y-or-n-p
1235+ (concat
1236+ " A session with the same parameters exists (" (car session) " ). "
1237+ " You can connect a sibling instead. Proceed? " ))
1238+ (let ((debug-on-quit nil ))
1239+ (signal 'quit nil )))))
1240+ params)
1241+
12111242
12121243; ;; Aliases
12131244
0 commit comments