@@ -1463,11 +1463,13 @@ of the buffer into a formatted string."
1463
1463
(defun cider-format-buffer ()
1464
1464
" Format the Clojure code in the current buffer."
1465
1465
(interactive )
1466
+ (cider-ensure-connected)
1466
1467
(cider--format-buffer #'cider-sync-request:format-code ))
1467
1468
1468
1469
(defun cider-format-edn-buffer ()
1469
1470
" Format the EDN data in the current buffer."
1470
1471
(interactive )
1472
+ (cider-ensure-connected)
1471
1473
(cider--format-buffer (lambda (edn )
1472
1474
(cider-sync-request:format-edn edn fill-column))))
1473
1475
@@ -1493,6 +1495,7 @@ the string contents of the region into a formatted string."
1493
1495
(defun cider-format-region (start end )
1494
1496
" Format the Clojure code in the current region."
1495
1497
(interactive " r" )
1498
+ (cider-ensure-connected)
1496
1499
(cider--format-region start end #'cider-sync-request:format-code ))
1497
1500
1498
1501
(defun cider-format-edn-region (start end )
@@ -1507,6 +1510,7 @@ the string contents of the region into a formatted string."
1507
1510
(defun cider-format-defun ()
1508
1511
" Format the code in the current defun."
1509
1512
(interactive )
1513
+ (cider-ensure-connected)
1510
1514
(save-excursion
1511
1515
(mark-defun )
1512
1516
(cider-format-region (region-beginning ) (region-end ))))
@@ -1519,6 +1523,7 @@ the string contents of the region into a formatted string."
1519
1523
(defun cider-describe-nrepl-session ()
1520
1524
" Describe an nREPL session."
1521
1525
(interactive )
1526
+ (cider-ensure-connected)
1522
1527
(let ((selected-session (completing-read " Describe nREPL session: " (nrepl-sessions (cider-current-connection)))))
1523
1528
(when (and selected-session (not (equal selected-session " " )))
1524
1529
(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."
1539
1544
(defun cider-close-nrepl-session ()
1540
1545
" Close an nREPL session for the current connection."
1541
1546
(interactive )
1547
+ (cider-ensure-connected)
1542
1548
(let ((selected-session (completing-read " Close nREPL session: " (nrepl-sessions (cider-current-connection)))))
1543
1549
(when selected-session
1544
1550
(nrepl-sync-request:close (cider-current-connection) selected-session)
@@ -1616,6 +1622,7 @@ and all ancillary CIDER buffers."
1616
1622
" Restart the currently active CIDER connection.
1617
1623
If RESTART-ALL is t, then restarts all connections."
1618
1624
(interactive " P" )
1625
+ (cider-ensure-connected)
1619
1626
(if restart-all
1620
1627
(dolist (conn cider-connections)
1621
1628
(cider--restart-connection conn))
@@ -1633,6 +1640,7 @@ VAR is a fully qualified Clojure variable name as a string."
1633
1640
" Run -main or FUNCTION, prompting for its namespace if necessary.
1634
1641
With a prefix argument, prompt for function to run instead of -main."
1635
1642
(interactive (list (when current-prefix-arg (read-string " Function name: " ))))
1643
+ (cider-ensure-connected)
1636
1644
(let ((name (or function " -main" )))
1637
1645
(when-let ((response (cider-nrepl-send-sync-request
1638
1646
(list " op" " ns-list-vars-by-name"
0 commit comments