Skip to content

Commit

Permalink
Tweak the new pprint functions to have single-arity version
Browse files Browse the repository at this point in the history
Originally I didn't notice that other middlewares were making use
of the same functions.
  • Loading branch information
bbatsov committed Jan 2, 2019
1 parent b1a6e11 commit a14a653
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/cider/nrepl/middleware/format.clj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
(defn- format-edn
[edn pprint-fn]
(->> (read-edn edn)
(map #(with-out-str (pprint-fn %)))
(map #(pprint-fn %))
str/join
str/trim))

Expand Down
2 changes: 1 addition & 1 deletion src/cider/nrepl/middleware/stacktrace.clj
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
of pretty printed problems. The content of the returned map is modeled after
`clojure.spec/explain-printer`."
[ed pprint-fn]
(let [pp-str #(with-out-str (pprint-fn %))
(let [pp-str #(pprint-fn %)
problems (sort-by #(count (:path %))
(or (:clojure.spec/problems ed)
(:clojure.spec.alpha/problems ed)))]
Expand Down
26 changes: 17 additions & 9 deletions src/cider/nrepl/pprint.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Pretty-print related utilities.
All functions here are simple wrappers that ensure a consistent API:
* two params - object to print and a map of print options
* has one and two params signatures - object to print and a map of print options
* the keys of the print options map can be strings, as bencode clients can't send keywords
* functions return the printed object as a string"
{:added "0.20.0"}
Expand All @@ -14,25 +14,33 @@
"A simple wrapper around `clojure.pprint/write`.
It provides an API compatible with what nREPL's
pr-values middleware expects for printer functions."
[object opts]
(let [opts (assoc (walk/keywordize-keys opts) :stream nil)]
(apply pp/write object (vec (flatten (vec opts))))))
([object]
(pprint object {}))
([object opts]
(let [opts (assoc (walk/keywordize-keys opts) :stream nil)]
(apply pp/write object (vec (flatten (vec opts)))))))

(def ^:private fipp-printer
(delay
(do
(require 'fipp.edn)
(resolve 'fipp.edn/pprint))))

(defn fipp-pprint [object opts]
(with-out-str
(@fipp-printer object (walk/keywordize-keys opts))))
(defn fipp-pprint
([object]
(fipp-pprint object {}))
([object opts]
(with-out-str
(@fipp-printer object (walk/keywordize-keys opts)))))

(def ^:private puget-printer
(delay
(do
(require 'puget.printer)
(resolve 'puget.printer/pprint-str))))

(defn puget-pprint [object opts]
(@puget-printer object (walk/keywordize-keys opts)))
(defn puget-pprint
([object]
(puget-pprint object {}))
([object opts]
(@puget-printer object (walk/keywordize-keys opts))))

0 comments on commit a14a653

Please sign in to comment.