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