Skip to content

Commit 24d5ee2

Browse files
committed
Make sure there's an active connection in a few commands
1 parent eb0c18e commit 24d5ee2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cider-interaction.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,11 +1463,13 @@ of the buffer into a formatted string."
14631463
(defun cider-format-buffer ()
14641464
"Format the Clojure code in the current buffer."
14651465
(interactive)
1466+
(cider-ensure-connected)
14661467
(cider--format-buffer #'cider-sync-request:format-code))
14671468

14681469
(defun cider-format-edn-buffer ()
14691470
"Format the EDN data in the current buffer."
14701471
(interactive)
1472+
(cider-ensure-connected)
14711473
(cider--format-buffer (lambda (edn)
14721474
(cider-sync-request:format-edn edn fill-column))))
14731475

@@ -1493,6 +1495,7 @@ the string contents of the region into a formatted string."
14931495
(defun cider-format-region (start end)
14941496
"Format the Clojure code in the current region."
14951497
(interactive "r")
1498+
(cider-ensure-connected)
14961499
(cider--format-region start end #'cider-sync-request:format-code))
14971500

14981501
(defun cider-format-edn-region (start end)
@@ -1507,6 +1510,7 @@ the string contents of the region into a formatted string."
15071510
(defun cider-format-defun ()
15081511
"Format the code in the current defun."
15091512
(interactive)
1513+
(cider-ensure-connected)
15101514
(save-excursion
15111515
(mark-defun)
15121516
(cider-format-region (region-beginning) (region-end))))
@@ -1519,6 +1523,7 @@ the string contents of the region into a formatted string."
15191523
(defun cider-describe-nrepl-session ()
15201524
"Describe an nREPL session."
15211525
(interactive)
1526+
(cider-ensure-connected)
15221527
(let ((selected-session (completing-read "Describe nREPL session: " (nrepl-sessions (cider-current-connection)))))
15231528
(when (and selected-session (not (equal selected-session "")))
15241529
(let* ((session-info (nrepl-sync-request:describe (cider-current-connection) selected-session))
@@ -1539,6 +1544,7 @@ the string contents of the region into a formatted string."
15391544
(defun cider-close-nrepl-session ()
15401545
"Close an nREPL session for the current connection."
15411546
(interactive)
1547+
(cider-ensure-connected)
15421548
(let ((selected-session (completing-read "Close nREPL session: " (nrepl-sessions (cider-current-connection)))))
15431549
(when selected-session
15441550
(nrepl-sync-request:close (cider-current-connection) selected-session)
@@ -1616,6 +1622,7 @@ and all ancillary CIDER buffers."
16161622
"Restart the currently active CIDER connection.
16171623
If RESTART-ALL is t, then restarts all connections."
16181624
(interactive "P")
1625+
(cider-ensure-connected)
16191626
(if restart-all
16201627
(dolist (conn cider-connections)
16211628
(cider--restart-connection conn))
@@ -1633,6 +1640,7 @@ VAR is a fully qualified Clojure variable name as a string."
16331640
"Run -main or FUNCTION, prompting for its namespace if necessary.
16341641
With a prefix argument, prompt for function to run instead of -main."
16351642
(interactive (list (when current-prefix-arg (read-string "Function name: "))))
1643+
(cider-ensure-connected)
16361644
(let ((name (or function "-main")))
16371645
(when-let ((response (cider-nrepl-send-sync-request
16381646
(list "op" "ns-list-vars-by-name"

0 commit comments

Comments
 (0)