/
pprint.clj
86 lines (75 loc) · 2.18 KB
/
pprint.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
(ns cider.nrepl.pprint
"Pretty-print related utilities.
All functions here are simple wrappers compatible with the expectations of
nrepl.middleware.print/wrap-print."
{:added "0.20"}
(:refer-clojure :exclude [pr])
(:require
[clojure.pprint :as pp]))
(def ^:private pr-options
[:print-dup
:print-readably
:print-length
:print-level
:print-meta
:print-namespace-maps])
(defn- option->var
[option]
(resolve (symbol "clojure.core" (str "*" (name option) "*"))))
(defn- pr-bindings
[options]
(->> (select-keys options pr-options)
(into {} (keep (fn [[option value]]
(when-let [var (option->var option)]
[var value]))))))
(defn pr
"Equivalent to `clojure.core/pr`. Any options corresponding to dynamic
printing configuration vars in `clojure.core` will, if provided, be bound
accordingly (e.g. `clojure.core/*print-length*` will be used if
`:print-length` is provided)."
([value writer]
(pr value writer nil))
([value writer options]
(with-bindings (pr-bindings options)
(if *print-dup*
(print-dup value writer)
(print-method value writer)))))
(defn pprint
"A simple wrapper around `clojure.pprint/write`."
([value writer]
(pprint value writer {}))
([value writer options]
(apply pp/write value (mapcat identity (assoc options :stream writer)))))
(def ^:private fipp-printer
(delay
(do
(require 'fipp.edn)
(resolve 'fipp.edn/pprint))))
(defn fipp-pprint
([value writer]
(fipp-pprint value writer {}))
([value writer options]
(binding [*out* writer]
(@fipp-printer value options))))
(def ^:private puget-printer
(delay
(do
(require 'puget.printer)
(resolve 'puget.printer/pprint))))
(defn puget-pprint
([value writer]
(puget-pprint value writer {}))
([value writer options]
(binding [*out* writer]
(@puget-printer value options))))
(def ^:private zprint-printer
(delay
(do
(require 'zprint.core)
(resolve 'zprint.core/zprint))))
(defn zprint-pprint
([value writer]
(zprint-pprint value writer {}))
([value writer options]
(binding [*out* writer]
(@zprint-printer value options))))