Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made debugging available globally, without a need to require in every namespace #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ Add the dependency and the middleware, e.g. in your `:user` profile:
[com.gfredericks.debug-repl/wrap-debug-repl]}
```

Then when you're ready to set breakpoints:
Then when you're ready to set breakpoints (you may need to reload your
namespaces or do `(use 'clojure.core :reload)` first):

``` clojure
user> (require '[com.gfredericks.debug-repl :refer [break! unbreak!]])
nil
user> (let [x 41] (break!))
Hijacking repl for breakpoint: unnamed
user> (inc x)
Expand Down
8 changes: 8 additions & 0 deletions src/com/gfredericks/debug_repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
(wrap-eval)
(handler))))

(declare global-debug!)
(defn wrap-debug-repl
[handler]
;; Test for NREPL-53 at startup
Expand All @@ -220,6 +221,7 @@
(when (= ::bad-middleware-ordering (:type (ex-data e)))
(report-nrepl-53-bug))))

(global-debug!)
;; having handle-debug as a separate function makes it easier to do
;; interactive development on this middleware
(fn [msg] (handle-debug handler msg)))
Expand All @@ -237,3 +239,9 @@
after unbreaking."
[& body]
`(try ~@body (catch Throwable ~'&ex (./break!) (throw ~'&ex))))

(defn global-debug! []
(intern 'clojure.core 'break! @#'break!) (.setMacro (find-var 'clojure.core/break!))
(intern 'clojure.core 'unbreak! @#'unbreak!)
(intern 'clojure.core 'unbreak!! @#'unbreak!!)
(intern 'clojure.core 'catch-break! @#'catch-break!) (.setMacro (find-var 'clojure.core/catch-break!)))