@@ -503,7 +503,7 @@ When invoked with a prefix ARG the command doesn't prompt for confirmation."
503503(defun cider-symbol-at-point ()
504504 " Return the name of the symbol at point, otherwise nil."
505505 (let ((str (substring-no-properties (or (thing-at-point 'symbol ) " " ))))
506- (if (equal str (concat (cider-find -ns) " > " ))
506+ (if (equal str (concat (cider-current -ns) " > " ))
507507 " "
508508 str)))
509509
@@ -910,7 +910,6 @@ This is controlled via `cider-interactive-eval-output-destination'."
910910 (lambda (buffer value )
911911 (message " %s " value)
912912 (with-current-buffer buffer
913- (setq nrepl-buffer-ns (clojure-find-ns))
914913 (run-hooks 'cider-file-loaded-hook )))
915914 (lambda (_buffer value )
916915 (cider-emit-interactive-eval-output value))
@@ -1207,29 +1206,17 @@ If prefix argument KILL-BUFFER-P is non-nil, kill the buffer instead of burying
12071206 (ansi-color-apply-on-region (point-min ) (point-max )))
12081207 (goto-char (point-min ))))
12091208
1210- ; ;; Namespace handling
1211- (defun cider-find-ns ()
1212- " Return the ns of the current buffer.
1213-
1214- For Clojure buffers the ns is extracted from the ns header. If
1215- it's missing \" user\" is used as fallback."
1216- (cond
1217- ((derived-mode-p 'clojure-mode )
1218- (or (save-restriction
1219- (widen )
1220- (clojure-find-ns))
1221- " user" ))
1222- ((derived-mode-p 'cider-repl-mode )
1223- nrepl-buffer-ns)))
1224-
12251209(defun cider-current-ns ()
1226- " Return the ns in the current context.
1227- If `nrepl-buffer-ns' has a value then return that, otherwise
1228- search for and read a `ns' form."
1229- (let ((ns nrepl-buffer-ns))
1230- (or (and (string= ns " user" )
1231- (cider-find-ns))
1232- ns)))
1210+ " Return current ns.
1211+ The ns is extracted from the ns form. If missing, use current REPL's ns,
1212+ otherwise fall back to \" user\" ."
1213+ (if (derived-mode-p 'cider-repl-mode )
1214+ nrepl-buffer-ns
1215+ (or (clojure-find-ns)
1216+ (-when-let (repl-buf (cider-current-repl-buffer))
1217+ (buffer-local-value 'nrepl-buffer-ns (get-buffer repl-buf)))
1218+ nrepl-buffer-ns
1219+ " user" )))
12331220
12341221
12351222; ;; Evaluation
@@ -1256,10 +1243,7 @@ START-POS is a starting position of the form in the original context."
12561243 " "
12571244 (or (-when-let (form (cider-ns-form))
12581245 (replace-regexp-in-string " :reload\\ (-all\\ )?\\ >" " " form))
1259- (->> (get-buffer (cider-current-repl-buffer))
1260- (buffer-local-value 'nrepl-buffer-ns )
1261- (setq nrepl-buffer-ns)
1262- (format " (ns %s ) " )))))
1246+ (format " (ns %s ) " (cider-current-ns)))))
12631247 (ns-form-lines (length (split-string ns-form " \n " )))
12641248 (start-pos (or start-pos 1 ))
12651249 (start-line (line-number-at-pos start-pos))
@@ -1423,7 +1407,6 @@ See command `cider-mode'."
14231407 (interactive )
14241408 (dolist (buffer (cider-util--clojure-buffers))
14251409 (with-current-buffer buffer
1426- (setq nrepl-buffer-ns " user" )
14271410 (clojure-disable-cider))))
14281411
14291412(defun cider-possibly-disable-on-existing-clojure-buffers ()
@@ -1488,8 +1471,7 @@ The result of the completing read will be passed to COMPLETING-READ-CALLBACK."
14881471
14891472(defun cider-completing-read-sym-form (label form callback )
14901473 " Eval the FORM and pass the result to the response handler."
1491- (cider-tooling-eval form (cider-completing-read-sym-handler label callback (current-buffer ))
1492- nrepl-buffer-ns))
1474+ (cider-tooling-eval form (cider-completing-read-sym-handler label callback (current-buffer ))))
14931475
14941476(defun cider-completing-read-var (prompt ns callback )
14951477 " Perform completing read var in NS using CALLBACK."
@@ -1513,12 +1495,13 @@ The result of the completing read will be passed to COMPLETING-READ-CALLBACK."
15131495Once selected, the name of the fn will appear in the repl buffer in parens
15141496ready to call."
15151497 (interactive )
1516- (cider-completing-read-sym-form (format " Fn: %s / " nrepl-buffer-ns)
1517- (cider-fetch-fns-form (cider-current-ns))
1518- (lambda (f _targets )
1519- (with-current-buffer (cider-current-repl-buffer)
1520- (cider-repl--replace-input (format " (%s ) " f))
1521- (goto-char (- (point-max ) 1 ))))))
1498+ (let ((ns (cider-current-ns)))
1499+ (cider-completing-read-sym-form (format " Fn: %s / " ns)
1500+ (cider-fetch-fns-form ns)
1501+ (lambda (f _targets )
1502+ (with-current-buffer (cider-current-repl-buffer)
1503+ (cider-repl--replace-input (format " (%s ) " f))
1504+ (goto-char (- (point-max ) 1 )))))))
15221505
15231506(defun cider-read-symbol-name (prompt callback &optional query )
15241507 " Either read a symbol name using PROMPT or choose the one at point.
@@ -1531,7 +1514,7 @@ if there is no symbol at point, or if QUERY is non-nil."
15311514 (not symbol-name)
15321515 (equal " " symbol-name)))
15331516 (funcall callback symbol-name)
1534- (cider-completing-read-var prompt nrepl-buffer -ns callback))))
1517+ (cider-completing-read-var prompt (cider-current -ns) callback))))
15351518
15361519(defun cider-toggle-trace (query )
15371520 " Toggle tracing for the given QUERY.
@@ -1736,12 +1719,6 @@ strings, include private vars, and be case sensitive."
17361719 " (clojure.core/require 'clojure.tools.namespace.repl) (clojure.tools.namespace.repl/refresh)"
17371720 (cider-interactive-eval-handler (current-buffer ))))
17381721
1739- ; ; TODO: implement reloading ns
1740- (defun cider-eval-load-file (form )
1741- " Load FORM."
1742- (let ((buffer (current-buffer )))
1743- (cider-eval form (cider-interactive-eval-handler buffer))))
1744-
17451722(defun cider-file-string (file )
17461723 " Read the contents of a FILE and return as a string."
17471724 (with-current-buffer (find-file-noselect file)
0 commit comments