@@ -1269,6 +1269,9 @@ otherwise fall back to \"user\"."
1269
1269
#'identity )
1270
1270
" Function to translate Emacs filenames to nREPL namestrings." )
1271
1271
1272
+ (defvar-local cider--cached-ns-form nil
1273
+ " Cached ns form in the current buffer." )
1274
+
1272
1275
(defun cider-interactive-source-tracking-eval (form &optional start-pos callback )
1273
1276
" Evaluate FORM and dispatch the response to CALLBACK.
1274
1277
START-POS is a starting position of the form in the original context.
@@ -1298,7 +1301,13 @@ If CALLBACK is nil use `cider-interactive-eval-handler'."
1298
1301
; ; otherwise trying to eval ns form for the first time will produce an error
1299
1302
(let ((ns (if (cider-ns-form-p form)
1300
1303
" user"
1301
- (cider-current-ns))))
1304
+ (cider-current-ns)))
1305
+ (cur-ns-form (cider-ns-form)))
1306
+ (when (and cur-ns-form
1307
+ (not (string= cur-ns-form cider--cached-ns-form))
1308
+ (not (string= ns " user" )))
1309
+ (cider-eval-ns-form))
1310
+ (setq cider--cached-ns-form cur-ns-form)
1302
1311
(nrepl-request:eval
1303
1312
form
1304
1313
(or callback (cider-interactive-eval-handler))
@@ -1307,15 +1316,22 @@ If CALLBACK is nil use `cider-interactive-eval-handler'."
1307
1316
(defun cider--dummy-file-contents (form start-pos )
1308
1317
" Wrap FORM to make it suitable for `cider-request:load-file' .
1309
1318
START-POS is a starting position of the form in the original context."
1310
- (let* ((ns-form (if (cider-ns-form-p form)
1311
- " "
1312
- (or (-when-let (form (cider-ns-form))
1313
- (replace-regexp-in-string " :reload\\ (-all\\ )?\\ >" " " form))
1314
- (format " (ns %s ) " (cider-current-ns)))))
1319
+ (let* ((cur-ns-form (cider-ns-form))
1320
+ (ns-form (cond
1321
+ ((or (null cur-ns-form)
1322
+ (cider-ns-form-p form))
1323
+ " " )
1324
+ ((string= cur-ns-form cider--cached-ns-form)
1325
+ (format " (ns %s ) " (cider-current-ns)))
1326
+ ((null cider--cached-ns-form)
1327
+ cur-ns-form)
1328
+ (t
1329
+ (replace-regexp-in-string " :reload\\ (-all\\ )?\\ >" " " cur-ns-form))))
1315
1330
(ns-form-lines (length (split-string ns-form " \n " )))
1316
1331
(start-pos (or start-pos 1 ))
1317
1332
(start-line (line-number-at-pos start-pos))
1318
1333
(start-column (save-excursion (goto-char start-pos) (current-column ))))
1334
+ (setq cider--cached-ns-form cur-ns-form)
1319
1335
(concat
1320
1336
ns-form
1321
1337
(make-string (max 0 (- start-line ns-form-lines)) ?\n )
@@ -1700,6 +1716,7 @@ under point, prompts for a var."
1700
1716
(cider--clear-compilation-highlights)
1701
1717
(-when-let (error-win (get-buffer-window cider-error-buffer))
1702
1718
(quit-window nil error-win))
1719
+ (setq cider--cached-ns-form (cider-ns-form))
1703
1720
(cider-request:load-file
1704
1721
(cider-file-string filename)
1705
1722
(funcall cider-to-nrepl-filename-function (cider--server-filename filename))
0 commit comments