@@ -137,6 +137,7 @@ endpoint and Clojure version."
137
137
(defun cider-rotate-connection ()
138
138
" Rotate and display the current nREPL connection."
139
139
(interactive )
140
+ (cider-ensure-connected)
140
141
(setq nrepl-connection-list
141
142
(append (cdr nrepl-connection-list)
142
143
(list (car nrepl-connection-list))))
@@ -181,14 +182,13 @@ the buffer should appear.
181
182
With a prefix ARG sets the namespace in the REPL buffer to that
182
183
of the namespace in the Clojure source buffer."
183
184
(interactive " p" )
184
- (if (not (cider-connected-p))
185
- (message " No active nREPL connection. " )
186
- (let ((buffer (current-buffer )))
187
- (when (eq 4 arg)
188
- (cider-repl-set-ns (cider-current-ns)))
189
- (pop-to-buffer (cider-find-or-create-repl-buffer))
190
- (cider-remember-clojure-buffer buffer)
191
- (goto-char (point-max )))))
185
+ (cider-ensure-connected)
186
+ (let ((buffer (current-buffer )))
187
+ (when (eq 4 arg)
188
+ (cider-repl-set-ns (cider-current-ns)))
189
+ (pop-to-buffer (cider-find-or-create-repl-buffer))
190
+ (cider-remember-clojure-buffer buffer)
191
+ (goto-char (point-max ))))
192
192
193
193
(defun cider-find-connection-buffer-for-project-directory (project-directory )
194
194
" Find the relevant connection-buffer for the given PROJECT-DIRECTORY.
@@ -234,31 +234,29 @@ of the namespace in the Clojure source buffer.
234
234
With a second prefix ARG the chosen REPL buffer is based on a
235
235
supplied project directory using IDO."
236
236
(interactive " p" )
237
- (if (not (cider-connected-p))
238
- (message " No active nREPL connection. " )
239
-
240
- (let* ((project-directory
241
- (or (when (eq 16 arg) (ido-read-directory-name " Project: " ))
242
- (nrepl-project-directory-for (nrepl-current-dir))))
243
- (connection-buffer
244
- (or
245
- (and (= 1 (length nrepl-connection-list)) (car nrepl-connection-list))
246
- (and project-directory
247
- (cider-find-connection-buffer-for-project-directory project-directory)))))
248
- (when connection-buffer
249
- (setq nrepl-connection-list
250
- (cons connection-buffer (delq connection-buffer nrepl-connection-list))))
251
- (cider-switch-to-current-repl-buffer arg)
252
- (message
253
- (format (if connection-buffer
254
- " Switched to REPL: %s"
255
- " Could not determine relevant nREPL connection, using: %s" )
256
- (with-current-buffer (nrepl-current-connection-buffer)
257
- (format " %s :%s , %s :%s "
258
- (or (nrepl--project-name nrepl-project-dir) " <no project>" )
259
- nrepl-buffer-ns
260
- (car nrepl-endpoint)
261
- (cadr nrepl-endpoint))))))))
237
+ (cider-ensure-connected)
238
+ (let* ((project-directory
239
+ (or (when (eq 16 arg) (ido-read-directory-name " Project: " ))
240
+ (nrepl-project-directory-for (nrepl-current-dir))))
241
+ (connection-buffer
242
+ (or
243
+ (and (= 1 (length nrepl-connection-list)) (car nrepl-connection-list))
244
+ (and project-directory
245
+ (cider-find-connection-buffer-for-project-directory project-directory)))))
246
+ (when connection-buffer
247
+ (setq nrepl-connection-list
248
+ (cons connection-buffer (delq connection-buffer nrepl-connection-list))))
249
+ (cider-switch-to-current-repl-buffer arg)
250
+ (message
251
+ (format (if connection-buffer
252
+ " Switched to REPL: %s"
253
+ " Could not determine relevant nREPL connection, using: %s" )
254
+ (with-current-buffer (nrepl-current-connection-buffer)
255
+ (format " %s :%s , %s :%s "
256
+ (or (nrepl--project-name nrepl-project-dir) " <no project>" )
257
+ nrepl-buffer-ns
258
+ (car nrepl-endpoint)
259
+ (cadr nrepl-endpoint)))))))
262
260
263
261
(defun cider-switch-to-last-clojure-buffer ()
264
262
" Switch to the last Clojure buffer.
@@ -1116,6 +1114,12 @@ Useful in hooks."
1116
1114
(nrepl-current-connection-buffer)
1117
1115
(error nil )))
1118
1116
1117
+ (defun cider-ensure-connected ()
1118
+ " Ensure there is a cider connection present, otherwise
1119
+ an error is signalled."
1120
+ (unless (cider-connected-p)
1121
+ (error " No active nREPL connection " )))
1122
+
1119
1123
(defun cider-enable-on-existing-clojure-buffers ()
1120
1124
" Enable interaction mode on existing Clojure buffers.
1121
1125
See command `cider-mode' ."
0 commit comments