@@ -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 header. 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))
@@ -1425,7 +1409,6 @@ See command `cider-mode'."
14251409 (interactive )
14261410 (dolist (buffer (cider-util--clojure-buffers))
14271411 (with-current-buffer buffer
1428- (setq nrepl-buffer-ns " user" )
14291412 (clojure-disable-cider))))
14301413
14311414(defun cider-possibly-disable-on-existing-clojure-buffers ()
@@ -1490,8 +1473,7 @@ The result of the completing read will be passed to COMPLETING-READ-CALLBACK."
14901473
14911474(defun cider-completing-read-sym-form (label form callback )
14921475 " Eval the FORM and pass the result to the response handler."
1493- (cider-tooling-eval form (cider-completing-read-sym-handler label callback (current-buffer ))
1494- nrepl-buffer-ns))
1476+ (cider-tooling-eval form (cider-completing-read-sym-handler label callback (current-buffer ))))
14951477
14961478(defun cider-completing-read-var (prompt ns callback )
14971479 " Perform completing read var in NS using CALLBACK."
@@ -1515,12 +1497,13 @@ The result of the completing read will be passed to COMPLETING-READ-CALLBACK."
15151497Once selected, the name of the fn will appear in the repl buffer in parens
15161498ready to call."
15171499 (interactive )
1518- (cider-completing-read-sym-form (format " Fn: %s / " nrepl-buffer-ns)
1519- (cider-fetch-fns-form (cider-current-ns))
1520- (lambda (f _targets )
1521- (with-current-buffer (cider-current-repl-buffer)
1522- (cider-repl--replace-input (format " (%s ) " f))
1523- (goto-char (- (point-max ) 1 ))))))
1500+ (let ((ns (cider-current-ns)))
1501+ (cider-completing-read-sym-form (format " Fn: %s / " ns)
1502+ (cider-fetch-fns-form ns)
1503+ (lambda (f _targets )
1504+ (with-current-buffer (cider-current-repl-buffer)
1505+ (cider-repl--replace-input (format " (%s ) " f))
1506+ (goto-char (- (point-max ) 1 )))))))
15241507
15251508(defun cider-read-symbol-name (prompt callback &optional query )
15261509 " Either read a symbol name using PROMPT or choose the one at point.
@@ -1533,7 +1516,7 @@ if there is no symbol at point, or if QUERY is non-nil."
15331516 (not symbol-name)
15341517 (equal " " symbol-name)))
15351518 (funcall callback symbol-name)
1536- (cider-completing-read-var prompt nrepl-buffer -ns callback))))
1519+ (cider-completing-read-var prompt (cider-current -ns) callback))))
15371520
15381521(defun cider-toggle-trace (query )
15391522 " Toggle tracing for the given QUERY.
@@ -1738,12 +1721,6 @@ strings, include private vars, and be case sensitive."
17381721 " (clojure.core/require 'clojure.tools.namespace.repl) (clojure.tools.namespace.repl/refresh)"
17391722 (cider-interactive-eval-handler (current-buffer ))))
17401723
1741- ; ; TODO: implement reloading ns
1742- (defun cider-eval-load-file (form )
1743- " Load FORM."
1744- (let ((buffer (current-buffer )))
1745- (cider-eval form (cider-interactive-eval-handler buffer))))
1746-
17471724(defun cider-file-string (file )
17481725 " Read the contents of a FILE and return as a string."
17491726 (with-current-buffer (find-file-noselect file)
0 commit comments