Skip to content

Commit beb552a

Browse files
committed
In interactive eval load ns-form whenever needed
1 parent 68de950 commit beb552a

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

cider-interaction.el

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,9 @@ otherwise fall back to \"user\"."
12691269
#'identity)
12701270
"Function to translate Emacs filenames to nREPL namestrings.")
12711271

1272+
(defvar-local cider--cached-ns-form nil
1273+
"Cached ns form in the current buffer.")
1274+
12721275
(defun cider-interactive-source-tracking-eval (form &optional start-pos callback)
12731276
"Evaluate FORM and dispatch the response to CALLBACK.
12741277
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'."
12981301
;; otherwise trying to eval ns form for the first time will produce an error
12991302
(let ((ns (if (cider-ns-form-p form)
13001303
"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)
13021311
(nrepl-request:eval
13031312
form
13041313
(or callback (cider-interactive-eval-handler))
@@ -1307,15 +1316,22 @@ If CALLBACK is nil use `cider-interactive-eval-handler'."
13071316
(defun cider--dummy-file-contents (form start-pos)
13081317
"Wrap FORM to make it suitable for `cider-request:load-file'.
13091318
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))))
13151330
(ns-form-lines (length (split-string ns-form "\n")))
13161331
(start-pos (or start-pos 1))
13171332
(start-line (line-number-at-pos start-pos))
13181333
(start-column (save-excursion (goto-char start-pos) (current-column))))
1334+
(setq cider--cached-ns-form cur-ns-form)
13191335
(concat
13201336
ns-form
13211337
(make-string (max 0 (- start-line ns-form-lines)) ?\n)
@@ -1700,6 +1716,7 @@ under point, prompts for a var."
17001716
(cider--clear-compilation-highlights)
17011717
(-when-let (error-win (get-buffer-window cider-error-buffer))
17021718
(quit-window nil error-win))
1719+
(setq cider--cached-ns-form (cider-ns-form))
17031720
(cider-request:load-file
17041721
(cider-file-string filename)
17051722
(funcall cider-to-nrepl-filename-function (cider--server-filename filename))

0 commit comments

Comments
 (0)