@@ -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))
@@ -1400,9 +1384,7 @@ Useful in hooks."
14001384
14011385(defun cider-connected-p ()
14021386 " Return t if CIDER is currently connected, nil otherwise."
1403- (condition-case nil
1404- (nrepl-current-connection-buffer)
1405- (error nil )))
1387+ (nrepl-current-connection-buffer 'no-error ))
14061388
14071389(defun cider-ensure-connected ()
14081390 " Ensure there is a cider connection present, otherwise
@@ -1425,7 +1407,6 @@ See command `cider-mode'."
14251407 (interactive )
14261408 (dolist (buffer (cider-util--clojure-buffers))
14271409 (with-current-buffer buffer
1428- (setq nrepl-buffer-ns " user" )
14291410 (clojure-disable-cider))))
14301411
14311412(defun cider-possibly-disable-on-existing-clojure-buffers ()
@@ -1490,8 +1471,7 @@ The result of the completing read will be passed to COMPLETING-READ-CALLBACK."
14901471
14911472(defun cider-completing-read-sym-form (label form callback )
14921473 " 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))
1474+ (cider-tooling-eval form (cider-completing-read-sym-handler label callback (current-buffer ))))
14951475
14961476(defun cider-completing-read-var (prompt ns callback )
14971477 " Perform completing read var in NS using CALLBACK."
@@ -1515,12 +1495,13 @@ The result of the completing read will be passed to COMPLETING-READ-CALLBACK."
15151495Once selected, the name of the fn will appear in the repl buffer in parens
15161496ready to call."
15171497 (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 ))))))
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 )))))))
15241505
15251506(defun cider-read-symbol-name (prompt callback &optional query )
15261507 " Either read a symbol name using PROMPT or choose the one at point.
@@ -1533,7 +1514,7 @@ if there is no symbol at point, or if QUERY is non-nil."
15331514 (not symbol-name)
15341515 (equal " " symbol-name)))
15351516 (funcall callback symbol-name)
1536- (cider-completing-read-var prompt nrepl-buffer -ns callback))))
1517+ (cider-completing-read-var prompt (cider-current -ns) callback))))
15371518
15381519(defun cider-toggle-trace (query )
15391520 " Toggle tracing for the given QUERY.
@@ -1738,12 +1719,6 @@ strings, include private vars, and be case sensitive."
17381719 " (clojure.core/require 'clojure.tools.namespace.repl) (clojure.tools.namespace.repl/refresh)"
17391720 (cider-interactive-eval-handler (current-buffer ))))
17401721
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-
17471722(defun cider-file-string (file )
17481723 " Read the contents of a FILE and return as a string."
17491724 (with-current-buffer (find-file-noselect file)
0 commit comments