Permalink
Browse files

Add fipp.repl/pst

  • Loading branch information...
brandonbloom committed Jan 11, 2017
1 parent 5af77ab commit 08ea347176e0ab79d36e8ef02edbf80e0085b2d5
Showing with 32 additions and 2 deletions.
  1. +1 −1 README.md
  2. +1 −1 project.clj
  3. +30 −0 src/fipp/repl.clj
@@ -23,7 +23,7 @@ Fipp artifacts are [published on Clojars](https://clojars.org/fipp).
To depend on this version with Lein, add the following to your `project.clj`:
```clojure
[fipp "0.6.7"]
[fipp "0.6.8"]
```
This version of Fipp works with Clojure 1.7 or newer.
@@ -1,4 +1,4 @@
(defproject fipp "0.6.7"
(defproject fipp "0.6.8"
:description "Fast Idiomatic Pretty Printer for Clojure"
:url "https://github.com/brandonbloom/fipp"
:license {:name "Eclipse Public License"
@@ -0,0 +1,30 @@
(ns fipp.repl
(:require [clojure.repl :as clj]
[fipp.edn :refer [pprint]]))
(defn pst
"Like clojure.repl/pst, but with ex-info fipp pretty-printing."
([] (pst 12))
([e-or-depth]
(if (instance? Throwable e-or-depth)
(pst e-or-depth 12)
(when-let [e *e]
(pst (clj/root-cause e) e-or-depth))))
([^Throwable e depth]
(binding [*out* *err*]
(println (str (-> e class .getSimpleName) " " (.getMessage e)))
(when-let [info (ex-data e)]
(pprint info))
(let [st (.getStackTrace e)
cause (.getCause e)]
(doseq [el (take depth
(remove #(#{"clojure.lang.RestFn"
"clojure.lang.AFn"}
(.getClassName %))
st))]
(println (str \tab (clj/stack-element-str el))))
(when cause
(println "Caused by:")
(pst cause (min depth
(+ 2 (- (count (.getStackTrace cause))
(count st))))))))))

0 comments on commit 08ea347

Please sign in to comment.