vvvvalvalval / scope-capture

Project your Clojure(Script) REPL into the same context as your code when it ran
MIT License
573 stars 14 forks source link

Shortcut to use the `last-ep-id` in `letsc` #45

Open jprudent opened 2 years ago

jprudent commented 2 years ago

Hello !

Because most of the time I'm interested in the last spy, I found that I can inject this macro in my user NS, to avoid having to find the ep-id manually (and because we can't do (sc.api/letsc (sc.api/last-ep-id) x) )

(defmacro letsc
  [& body]
  (let [ep-id (sc.api/last-ep-id)]
    `(sc.api/letsc ~ep-id ~@body)))

I use it like this

(defn foo [x] (sc.api/spy x))
SPY <-20> /tmp/form-init17184007261798462834.clj:1 
 At Code Site -20, will save scope with locals [x]
=> #'user/foo
(foo 12)
SPY [91 -20] /tmp/form-init17184007261798462834.clj:1 
  At Execution Point 91 of Code Site -20, saved scope with locals [x]
SPY [91 -20] /tmp/form-init17184007261798462834.clj:1 
x
=>
12
=> 12
(letsc x)
=> 12

It's really a nice improvement I think, so I would like to share it with you in case you also think so.

Thanks for scope capture, I love it :)