Permalink
Browse files

Add REBL inspect functions

  • Loading branch information...
seancorfield committed Dec 19, 2018
1 parent 42fb427 commit b5c4ec4fbe2572a97882e595f6280fec15592114
Showing with 37 additions and 0 deletions.
  1. +3 −0 src/chlorine/core.cljs
  2. +34 −0 src/chlorine/repl.cljs
@@ -43,6 +43,9 @@
(aux/command-for "run-tests-in-ns" #(repl/run-tests-in-ns!))
(aux/command-for "run-test-for-var" #(repl/run-test-at-cursor!))

(aux/command-for "inspect-block" #(repl/inspect-block!))
(aux/command-for "inspect-top-block" #(repl/inspect-top-block!))

(aux/command-for "refresh-namespaces" refresh/run-refresh!)
(aux/command-for "toggle-refresh-mode" refresh/toggle-refresh)

@@ -177,6 +177,40 @@
(. editor getSelectedBufferRange)
(.getSelectedText editor))))

(defn wrap-in-rebl-submit
"Clojure 1.10 only, require REBL on the classpath (and UI open)."
[code]
(str "(let [value " code "]"
" (when-let [d-val ((requiring-resolve 'clojure.datafy/datafy) value)]"
" ((requiring-resolve 'cognitect.rebl/submit) '" code " d-val))"
" value)"))

(defn inspect-top-block!
([] (inspect-top-block! (atom/current-editor)))
([^js editor]
(let [range (. EditorUtils
(getCursorInBlockRange editor #js {:topLevel true}))]
(some->> range
(.getTextInBufferRange editor)
(wrap-in-rebl-submit)
(eval-and-present editor
(ns-for editor)
(.getPath editor)
range)))))

(defn inspect-block!
([] (inspect-block! (atom/current-editor)))
([^js editor]
(let [range (. EditorUtils
(getCursorInBlockRange editor))]
(some->> range
(.getTextInBufferRange editor)
(wrap-in-rebl-submit)
(eval-and-present editor
(ns-for editor)
(.getPath editor)
range)))))

(defn run-tests-in-ns!
([] (run-tests-in-ns! (atom/current-editor)))
([^js editor]

0 comments on commit b5c4ec4

Please sign in to comment.