@@ -1329,12 +1329,15 @@ buffer, else display in a popup buffer."
1329
1329
(cider-pprint-eval-defun-to-comment)
1330
1330
(cider--pprint-eval-form (cider-defun-at-point 'bounds ))))
1331
1331
1332
- (defun cider-eval-ns-form ()
1333
- " Evaluate the current buffer's namespace form."
1334
- (interactive )
1332
+ (defun cider-eval-ns-form (&optional undef-all )
1333
+ " Evaluate the current buffer's namespace form.
1334
+ When UNDEF-ALL is non-nil, unmap all symbols and aliases first."
1335
+ (interactive " p" )
1335
1336
(when (clojure-find-ns)
1336
1337
(save-excursion
1337
1338
(goto-char (match-beginning 0 ))
1339
+ (when undef-all
1340
+ (cider-undef-all (match-string 0 )))
1338
1341
(cider-eval-defun-at-point))))
1339
1342
1340
1343
(defun cider-read-and-eval (&optional value )
@@ -1431,13 +1434,15 @@ passing arguments."
1431
1434
(widen )
1432
1435
(substring-no-properties (buffer-string )))))
1433
1436
1434
- (defun cider-load-buffer (&optional buffer callback )
1437
+ (defun cider-load-buffer (&optional buffer callback undef-all )
1435
1438
" Load (eval) BUFFER's file in nREPL.
1436
1439
If no buffer is provided the command acts on the current buffer. If the
1437
1440
buffer is for a cljc file, and both a Clojure and ClojureScript REPL exists
1438
1441
for the project, it is evaluated in both REPLs.
1439
- Optional argument CALLBACK will override the default ‘cider-load-file-handler’."
1440
- (interactive )
1442
+ Optional argument CALLBACK will override the default ‘cider-load-file-handler’.
1443
+ When UNDEF-ALL is non-nil or called with \\ [universal-argument], removes
1444
+ all ns aliases and var mappings from the namespace before reloading it."
1445
+ (interactive (list (current-buffer ) nil (equal current-prefix-arg '(4 ))))
1441
1446
(setq buffer (or buffer (current-buffer )))
1442
1447
; ; When cider-load-buffer or cider-load-file are called in programs the
1443
1448
; ; current context might not match the buffer's context. We use the caller
@@ -1455,6 +1460,8 @@ Optional argument CALLBACK will override the default ‘cider-load-file-handler
1455
1460
(y-or-n-p (format " Save file %s ? " buffer-file-name))))
1456
1461
(save-buffer ))
1457
1462
(remove-overlays nil nil 'cider-temporary t )
1463
+ (when undef-all
1464
+ (cider-undef-all (cider-current-ns)))
1458
1465
(cider--clear-compilation-highlights)
1459
1466
(cider--quit-error-window)
1460
1467
(let ((filename (buffer-file-name buffer))
@@ -1471,25 +1478,30 @@ Optional argument CALLBACK will override the default ‘cider-load-file-handler
1471
1478
callback)))
1472
1479
(message " Loading %s ... " filename))))))
1473
1480
1474
- (defun cider-load-file (filename )
1481
+ (defun cider-load-file (filename &optional undef-all )
1475
1482
" Load (eval) the Clojure file FILENAME in nREPL.
1476
1483
If the file is a cljc file, and both a Clojure and ClojureScript REPL
1477
1484
exists for the project, it is evaluated in both REPLs. The heavy lifting
1478
- is done by `cider-load-buffer' ."
1485
+ is done by `cider-load-buffer' .
1486
+ When UNDEF-ALL is non-nil or called with \\ [universal-argument], removes
1487
+ all ns aliases and var mappings from the namespace before reloading it."
1479
1488
(interactive (list
1480
1489
(read-file-name " Load file: " nil nil nil
1481
1490
(when (buffer-file-name )
1482
1491
(file-name-nondirectory
1483
- (buffer-file-name ))))))
1492
+ (buffer-file-name ))))
1493
+ (equal current-prefix-arg '(4 ))))
1484
1494
(if-let* ((buffer (find-buffer-visiting filename)))
1485
- (cider-load-buffer buffer)
1486
- (cider-load-buffer (find-file-noselect filename))))
1495
+ (cider-load-buffer buffer nil undef-all )
1496
+ (cider-load-buffer (find-file-noselect filename) nil undef-all )))
1487
1497
1488
- (defun cider-load-all-files (directory )
1498
+ (defun cider-load-all-files (directory undef-all )
1489
1499
" Load all files in DIRECTORY (recursively).
1490
- Useful when the running nREPL on remote host."
1491
- (interactive " DLoad files beneath directory: " )
1492
- (mapcar #'cider-load-file
1500
+ Useful when the running nREPL on remote host.
1501
+ When UNDEF-ALL is non-nil or called with \\ [universal-argument], removes
1502
+ all ns aliases and var mappings from the namespaces being reloaded"
1503
+ (interactive " DLoad files beneath directory: \n P" )
1504
+ (mapcar (lambda (file ) (cider-load-file file undef-all))
1493
1505
(directory-files-recursively directory " \\ .clj[cs]?$" )))
1494
1506
1495
1507
(defalias 'cider-eval-file #'cider-load-file
0 commit comments