Skip to content

Commit b1a6e11

Browse files
committed
Add print functions compatible with nREPL 0.5
1 parent f94ca7f commit b1a6e11

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
### New features
6+
7+
* Add print functions compatible with nREPL 0.5 to `cider.nrepl.pprint` namespace.
8+
59
### Changes
610

711
* **(Breaking)** Drop support for nREPL 0.2.x (aka `tools.nrepl`). Now nREPL 0.4+ is required.

src/cider/nrepl/pprint.clj

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(ns cider.nrepl.pprint
2+
"Pretty-print related utilities.
3+
All functions here are simple wrappers that ensure a consistent API:
4+
5+
* two params - object to print and a map of print options
6+
* the keys of the print options map can be strings, as bencode clients can't send keywords
7+
* functions return the printed object as a string"
8+
{:added "0.20.0"}
9+
(:require
10+
[clojure.pprint :as pp]
11+
[clojure.walk :as walk]))
12+
13+
(defn pprint
14+
"A simple wrapper around `clojure.pprint/write`.
15+
It provides an API compatible with what nREPL's
16+
pr-values middleware expects for printer functions."
17+
[object opts]
18+
(let [opts (assoc (walk/keywordize-keys opts) :stream nil)]
19+
(apply pp/write object (vec (flatten (vec opts))))))
20+
21+
(def ^:private fipp-printer
22+
(delay
23+
(do
24+
(require 'fipp.edn)
25+
(resolve 'fipp.edn/pprint))))
26+
27+
(defn fipp-pprint [object opts]
28+
(with-out-str
29+
(@fipp-printer object (walk/keywordize-keys opts))))
30+
31+
(def ^:private puget-printer
32+
(delay
33+
(do
34+
(require 'puget.printer)
35+
(resolve 'puget.printer/pprint-str))))
36+
37+
(defn puget-pprint [object opts]
38+
(@puget-printer object (walk/keywordize-keys opts)))

0 commit comments

Comments
 (0)