Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add leiningen.hooks.clj-stacktrace for integration with Leiningen.

  • Loading branch information...
commit 3b04762acf12148f21f4edf4b70a505cc1ab230d 1 parent bb883ac
@technomancy technomancy authored
Showing with 30 additions and 0 deletions.
  1. +7 −0 README.md
  2. +23 −0 src/leiningen/hooks/clj_stacktrace.clj
View
7 README.md
@@ -44,6 +44,13 @@ The library also offers an API for programatically 'parsing' exceptions. This AP
(catch Exception e
(parse-exception e)))
+If you use Leiningen, you can hook clj-stacktrace straight into your project. You'll need to add Robert Hooke to your :dependencies in project.clj. The {:color true} line is optional.
+
+ :dependencies [[org.clojure/clojure "1.2.0"]
+ [robert/hooke "1.1.0"]]
+ :dev-dependencies [[clj-stacktrace "0.2.1-SNAPSHOT"]]
+ :clj-stacktrace {:color true}
+
## License
Copyright 2009-2010 Mark McGranaghan and released under an MIT license.
View
23 src/leiningen/hooks/clj_stacktrace.clj
@@ -0,0 +1,23 @@
+(ns leiningen.hooks.clj-stacktrace
+ (:use [leiningen.compile :only [eval-in-project]]
+ [robert.hooke :only [add-hook]]))
+
+(defn- hook-form [form color?]
+ (let [pst (if color?
+ 'clj-stacktrace.repl/pst+
+ 'clj-stacktrace.repl/pst)]
+ `(do (if-let [add-hook# (resolve '~'robert.hooke/add-hook)]
+ (add-hook# (resolve '~'clojure.stacktrace/print-cause-trace)
+ (fn [original# & args#]
+ (apply @(resolve '~pst) args#)))
+ (println "clj-stacktrace needs robert.hooke dependency"))
+ ~form)))
+
+(defn- add-stacktrace-hook [eval-in-project project form & [h s init]]
+ (eval-in-project project (hook-form form (:color (:clj-stacktrace project)))
+ h s `(do (try (require '~'robert.hooke)
+ (require '~'clj-stacktrace.repl)
+ (catch Exception _#))
+ ~init)))
+
+(add-hook #'eval-in-project add-stacktrace-hook)
Please sign in to comment.
Something went wrong with that request. Please try again.