Skip to content

Commit f587820

Browse files
committed
Merge pull request #815 from vitoshka/scratch-ns
Use "(ns $repl-ns)" in dummy file when ns form not found
2 parents e3aab3b + dc5fb95 commit f587820

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

cider-interaction.el

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,15 @@ existing file ending with URL has been found."
649649
(t (-if-let (path (cider--file-path url))
650650
(find-file-noselect path)
651651
(unless (file-name-absolute-p url)
652-
(cl-loop for bf in (cider-util--clojure-buffers)
653-
for path = (with-current-buffer bf
654-
(expand-file-name url))
655-
if (and path (file-exists-p path))
656-
return (find-file-noselect path)))))))
652+
(let ((cider-buffers (cider-util--clojure-buffers)))
653+
(or (cl-loop for bf in cider-buffers
654+
for path = (with-current-buffer bf
655+
(expand-file-name url))
656+
if (and path (file-exists-p path))
657+
return (find-file-noselect path))
658+
(cl-loop for bf in cider-buffers
659+
if (string= (buffer-name bf) url)
660+
return bf))))))))
657661

658662
(defun cider-find-var-file (var)
659663
"Return the buffer visiting the file in which VAR is defined, or nil if
@@ -1235,7 +1239,8 @@ function is the main entry point in CIDER's interactive evaluation API. All
12351239
other interactive eval functions should rely on this function. If CALLBACK
12361240
is nil use `cider-interactive-eval-handler'."
12371241
(cider--clear-compilation-highlights)
1238-
(let ((filename (buffer-file-name)))
1242+
(let ((filename (or (buffer-file-name)
1243+
(buffer-name))))
12391244
(cider-request:load-file
12401245
(cider--dummy-file-contents form start-pos)
12411246
(funcall cider-to-nrepl-filename-function (cider--server-filename filename))
@@ -1247,14 +1252,19 @@ is nil use `cider-interactive-eval-handler'."
12471252
START-POS is a starting position of the form in the original context."
12481253
(let* ((ns-form (if (cider-ns-form-p form)
12491254
""
1250-
(cider-ns-form)))
1255+
(or (-when-let (form (cider-ns-form))
1256+
(replace-regexp-in-string ":reload\\(-all\\)?\\>" "" form))
1257+
(->> (get-buffer (cider-current-repl-buffer))
1258+
(buffer-local-value 'nrepl-buffer-ns)
1259+
(setq nrepl-buffer-ns)
1260+
(format "(ns %s)")))))
12511261
(ns-form-lines (length (split-string ns-form "\n")))
12521262
(start-pos (or start-pos 1))
12531263
(start-line (line-number-at-pos start-pos))
12541264
(start-column (save-excursion (goto-char start-pos) (current-column))))
12551265
(concat
12561266
ns-form
1257-
(make-string (- start-line ns-form-lines) ?\n)
1267+
(make-string (max 0 (- start-line ns-form-lines)) ?\n)
12581268
(make-string start-column ? )
12591269
form)))
12601270

cider-repl.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@ text property `cider-old-input'."
659659
660660
If invoked in a REPL buffer the command will prompt you for the name of the
661661
namespace to switch to."
662-
(interactive (list (if (derived-mode-p 'cider-repl-mode)
662+
(interactive (list (if (or (derived-mode-p 'cider-repl-mode)
663+
(null (cider-ns-form)))
663664
(completing-read "Switch to namespace: "
664665
(cider-sync-request:ns-list))
665666
(cider-current-ns))))

0 commit comments

Comments
 (0)