Skip to content

Commit 3e3120e

Browse files
committed
Merge pull request #516 from jonpither/no-vars
Removing dynamic vars for symbol loading.
2 parents becfa17 + 9749c08 commit 3e3120e

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

cider-interaction.el

Lines changed: 36 additions & 38 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,41 +1193,46 @@ 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)
1201-
"Peform ido select using SELECTED and TARGETS."
1196+
(defun cider-ido-var-select (prompt ido-callback cider-ido-ns selected targets)
1197+
"Peform ido select using SELECTED and TARGETS.
1198+
If SELECTED is \"..\" then another selection is made for vars in the parent namespace of
1199+
CIDER-IDO-NS using PROMPT.
1200+
If SELECTED is a namespace then another selection is made against that namespace
1201+
using PROMPT.
1202+
Once a selecton is made IDO-CALLBACK is called with SELECTED."
12021203
;; TODO: immediate RET gives "" as selected for some reason
12031204
;; this is an OK workaround though
12041205
(cond ((equal "" selected)
1205-
(cider-ido-var-select (car targets) targets))
1206+
(cider-ido-var-select prompt ido-callback cider-ido-ns (car targets) targets))
12061207
((equal "/" (substring selected -1)) ; selected a namespace
1207-
(cider-ido-read-var (substring selected 0 -1) cider-ido-var-callback))
1208+
(cider-ido-read-var prompt (substring selected 0 -1) ido-callback))
12081209
((equal ".." selected)
1209-
(cider-ido-read-var (cider-ido-up-ns cider-ido-ns) cider-ido-var-callback))
1210+
(cider-ido-read-var prompt (cider-ido-up-ns cider-ido-ns) ido-callback))
12101211
;; non ido variable selection techniques don't return qualified symbols, so this shouldn't either
1211-
(t (funcall cider-ido-var-callback selected))))
1212+
(t (funcall ido-callback selected))))
12121213

12131214
(defun cider-ido-read-sym-handler (label ido-select buffer)
12141215
"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)))
1225-
1226-
(defun cider-ido-read-var (ns ido-callback)
1227-
"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))
1216+
(nrepl-make-response-handler buffer
1217+
(lambda (buffer value)
1218+
;; make sure to eval the callback in the buffer that the symbol was requested from so we get the right namespace
1219+
(with-current-buffer buffer
1220+
(let* ((targets (car (read-from-string value)))
1221+
(selected (ido-completing-read label targets nil t)))
1222+
(funcall ido-select selected targets))))
1223+
nil nil nil))
1224+
1225+
(defun cider-ido-read-sym-form (label form callback)
1226+
"Eval the FORM and pass the result to the response handler."
1227+
(cider-tooling-eval form (cider-ido-read-sym-handler label callback (current-buffer))
12331228
nrepl-buffer-ns))
12341229

1230+
(defun cider-ido-read-var (prompt ns ido-callback)
1231+
"Perform ido read var in NS using IDO-CALLBACK."
1232+
(cider-ido-read-sym-form prompt (prin1-to-string (cider-ido-form ns))
1233+
(lambda (selected targets)
1234+
(cider-ido-var-select prompt ido-callback ns selected targets))))
1235+
12351236
(defun cider-ido-fns-form (ns)
12361237
"Construct a Clojure form for reading fns using supplied NS."
12371238
(format "(let [fn-pred (fn [[k v]] (and (fn? (.get v))
@@ -1243,20 +1244,17 @@ See command `cider-mode'."
12431244
(ns-interns '%s)
12441245
(ns-refers '%s))))))" ns ns))
12451246

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-
12511247
(defun cider-load-fn-into-repl-buffer ()
12521248
"Browse functions available in current repl buffer using ido.
12531249
Once selected, the name of the fn will appear in the repl buffer in parens
12541250
ready to call."
12551251
(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))
1252+
(cider-ido-read-sym-form (format "Fn: %s/" nrepl-buffer-ns)
1253+
(cider-ido-fns-form (cider-current-ns))
1254+
(lambda (f _targets)
1255+
(with-current-buffer (cider-current-repl-buffer)
1256+
(cider-repl--replace-input (format "(%s)" f))
1257+
(goto-char (- (point-max) 1))))))
12601258

12611259
(defun cider-read-symbol-name (prompt callback &optional query)
12621260
"Either read a symbol name using PROMPT or choose the one at point.
@@ -1266,7 +1264,7 @@ if there is no symbol at point, or if QUERY is non-nil."
12661264
(let ((symbol-name (cider-symbol-at-point)))
12671265
(cond ((not (or current-prefix-arg query (not symbol-name)))
12681266
(funcall callback symbol-name))
1269-
(ido-mode (cider-ido-read-var nrepl-buffer-ns callback))
1267+
(ido-mode (cider-ido-read-var prompt nrepl-buffer-ns callback))
12701268
(t (funcall callback (read-from-minibuffer prompt symbol-name))))))
12711269

12721270
(defun cider-doc-buffer-for (symbol)

0 commit comments

Comments
 (0)