Skip to content

Commit d822737

Browse files
committed
Removing dynamic vars for symbol loading
1 parent becfa17 commit d822737

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

cider-interaction.el

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,10 +1173,6 @@ See command `cider-mode'."
11731173
(unless (cider-connected-p)
11741174
(cider-disable-on-existing-clojure-buffers)))
11751175

1176-
;; this is horrible, but with async callbacks we can't rely on dynamic scope
1177-
(defvar cider-ido-ns nil)
1178-
(defvar cider-ido-var-callback nil)
1179-
11801176
(defun cider-ido-form (ns)
11811177
"Construct a Clojure form for ido read using NS."
11821178
`(concat (if (find-ns (symbol ,ns))
@@ -1197,40 +1193,40 @@ See command `cider-mode'."
11971193
"Perform up using NS."
11981194
(mapconcat 'identity (butlast (split-string ns "\\.")) "."))
11991195

1200-
(defun cider-ido-var-select (selected targets)
1196+
(defun cider-ido-var-select (ido-callback cider-ido-ns selected targets)
12011197
"Peform ido select using SELECTED and TARGETS."
12021198
;; TODO: immediate RET gives "" as selected for some reason
12031199
;; this is an OK workaround though
12041200
(cond ((equal "" selected)
1205-
(cider-ido-var-select (car targets) targets))
1201+
(cider-ido-var-select ido-callback cider-ido-ns (car targets) targets))
12061202
((equal "/" (substring selected -1)) ; selected a namespace
1207-
(cider-ido-read-var (substring selected 0 -1) cider-ido-var-callback))
1203+
(cider-ido-read-var (substring selected 0 -1) ido-callback))
12081204
((equal ".." selected)
1209-
(cider-ido-read-var (cider-ido-up-ns cider-ido-ns) cider-ido-var-callback))
1205+
(cider-ido-read-var (cider-ido-up-ns cider-ido-ns) ido-callback))
12101206
;; non ido variable selection techniques don't return qualified symbols, so this shouldn't either
1211-
(t (funcall cider-ido-var-callback selected))))
1207+
(t (funcall ido-callback selected))))
12121208

12131209
(defun cider-ido-read-sym-handler (label ido-select buffer)
12141210
"Create an ido read var handler with IDO-SELECT for BUFFER."
1215-
(let ((ido-select ido-select)
1216-
(label label))
1217-
(nrepl-make-response-handler buffer
1218-
(lambda (buffer value)
1219-
;; make sure to eval the callback in the buffer that the symbol was requested from so we get the right namespace
1220-
(with-current-buffer buffer
1221-
(let* ((targets (car (read-from-string value)))
1222-
(selected (ido-completing-read label targets nil t)))
1223-
(funcall ido-select selected targets))))
1224-
nil nil nil)))
1211+
(nrepl-make-response-handler buffer
1212+
(lambda (buffer value)
1213+
;; make sure to eval the callback in the buffer that the symbol was requested from so we get the right namespace
1214+
(with-current-buffer buffer
1215+
(let* ((targets (car (read-from-string value)))
1216+
(selected (ido-completing-read label targets nil t)))
1217+
(funcall ido-select selected targets))))
1218+
nil nil nil))
1219+
1220+
(defun cider-ido-read-sym-form (label form callback)
1221+
"Eval the FORM and pass the result to the response handler."
1222+
(cider-tooling-eval form (cider-ido-read-sym-handler label callback (current-buffer))
1223+
nrepl-buffer-ns))
12251224

12261225
(defun cider-ido-read-var (ns ido-callback)
12271226
"Perform ido read var in NS using IDO-CALLBACK."
1228-
;; Have to be stateful =(
1229-
(setq cider-ido-ns ns)
1230-
(setq cider-ido-var-callback ido-callback)
1231-
(cider-tooling-eval (prin1-to-string (cider-ido-form cider-ido-ns))
1232-
(cider-ido-read-sym-handler "Var: " 'cider-ido-var-select (current-buffer))
1233-
nrepl-buffer-ns))
1227+
(cider-ido-read-sym-form "Var: " (prin1-to-string (cider-ido-form ns))
1228+
(lambda (selected targets)
1229+
(cider-ido-var-select ido-callback ns selected targets))))
12341230

12351231
(defun cider-ido-fns-form (ns)
12361232
"Construct a Clojure form for reading fns using supplied NS."
@@ -1243,20 +1239,17 @@ See command `cider-mode'."
12431239
(ns-interns '%s)
12441240
(ns-refers '%s))))))" ns ns))
12451241

1246-
(defun cider-ido-fn-callback (f targets)
1247-
(with-current-buffer (cider-current-repl-buffer)
1248-
(cider-repl--replace-input (format "(%s)" f))
1249-
(goto-char (- (point-max) 1))))
1250-
12511242
(defun cider-load-fn-into-repl-buffer ()
12521243
"Browse functions available in current repl buffer using ido.
12531244
Once selected, the name of the fn will appear in the repl buffer in parens
12541245
ready to call."
12551246
(interactive)
1256-
(cider-tooling-eval (cider-ido-fns-form (cider-current-ns))
1257-
(cider-ido-read-sym-handler (format "Fn: %s/" nrepl-buffer-ns)
1258-
'cider-ido-fn-callback (current-buffer))
1259-
nrepl-buffer-ns))
1247+
(cider-ido-read-sym-form (format "Fn: %s/" nrepl-buffer-ns)
1248+
(cider-ido-fns-form (cider-current-ns))
1249+
(lambda (f _targets)
1250+
(with-current-buffer (cider-current-repl-buffer)
1251+
(cider-repl--replace-input (format "(%s)" f))
1252+
(goto-char (- (point-max) 1))))))
12601253

12611254
(defun cider-read-symbol-name (prompt callback &optional query)
12621255
"Either read a symbol name using PROMPT or choose the one at point.

0 commit comments

Comments
 (0)