Skip to content

Commit 3b9dcfe

Browse files
committed
Merge pull request #956 from vspinu/950
[Fix #950] Check for existence of ns in `cider-interactive-eval`
2 parents 5766957 + aa80e2c commit 3b9dcfe

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
@@ -1271,6 +1271,9 @@ otherwise fall back to \"user\"."
12711271
#'identity)
12721272
"Function to translate Emacs filenames to nREPL namestrings.")
12731273

1274+
(defvar-local cider--cached-ns-form nil
1275+
"Cached ns form in the current buffer.")
1276+
12741277
(defun cider-interactive-source-tracking-eval (form &optional start-pos callback)
12751278
"Evaluate FORM and dispatch the response to CALLBACK.
12761279
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'."
13001303
;; otherwise trying to eval ns form for the first time will produce an error
13011304
(let ((ns (if (cider-ns-form-p form)
13021305
"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)
13041313
(nrepl-request:eval
13051314
form
13061315
(or callback (cider-interactive-eval-handler))
@@ -1309,15 +1318,22 @@ If CALLBACK is nil use `cider-interactive-eval-handler'."
13091318
(defun cider--dummy-file-contents (form start-pos)
13101319
"Wrap FORM to make it suitable for `cider-request:load-file'.
13111320
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))))
13171332
(ns-form-lines (length (split-string ns-form "\n")))
13181333
(start-pos (or start-pos 1))
13191334
(start-line (line-number-at-pos start-pos))
13201335
(start-column (save-excursion (goto-char start-pos) (current-column))))
1336+
(setq cider--cached-ns-form cur-ns-form)
13211337
(concat
13221338
ns-form
13231339
(make-string (max 0 (- start-line ns-form-lines)) ?\n)
@@ -1702,6 +1718,7 @@ under point, prompts for a var."
17021718
(cider--clear-compilation-highlights)
17031719
(-when-let (error-win (get-buffer-window cider-error-buffer))
17041720
(quit-window nil error-win))
1721+
(setq cider--cached-ns-form (cider-ns-form))
17051722
(cider-request:load-file
17061723
(cider-file-string filename)
17071724
(funcall cider-to-nrepl-filename-function (cider--server-filename filename))

0 commit comments

Comments
 (0)