Configuring a printing function
Pretty-printing was overhauled in CIDER 0.21 to leverage new features introduced in nREPL 0.6. Refer to nREPL's documentation for details.
You can configure the function used by CIDER for pretty-printing evaluation
results and other data using the option
cider-print-fn, which can take the
following possible values:
nilto defer to nREPL to choose the printing function. This will use the bound value of
nrepl.middleware.print/*print-fn*, which defaults to the equivalent of
prto use the equivalent of \=
pprintto use the built-in
clojure.pprint/pprint(this is the default).
fippto use the Fast Idiomatic Pretty-Printer. This is approximately 5-10x faster than
zprintto use zprint, a fast and flexible alternative to the libraries mentioned above.
cider-print-fn can be set to the namespace-qualified name of a
Clojure var whose function takes three arguments: the object to print, the
java.io.PrintWriter to print on, and a (possibly nil) map of options.
(setq cider-print-fn "user/my-pprint")
Here's one example:
(ns cider.pprint (:require [clojure.pprint :as pp])) (defn pprint "A simple wrapper around `clojure.pprint/write`. Its signature is compatible with the expectations of nREPL's wrap-print middleware." [value writer options] (apply pp/write value (mapcat identity (assoc options :stream writer))))
Limiting printed output
You can set
cider-print-quota to limit the number of bytes that will be
returned by any printing operation. This defaults to one megabyte, and can be
nil if no limit is desired. Note well that if no quota is set some
printing operations may never terminate – you can still use
Your configured printing function might also support limiting the length and
depth of printed objects – either using
clojure.core/*print-level* or in the provided options map.
You can pass an options map to the print function by setting
cider-print-options. Here's an example:
(setq cider-print-options '(dict "length" 50 "right-margin" 70))
Note that each print engine has its own configuration options, so you'll have to be sure to set
Here's a table describing the differences in the names for the most common print options supported by every print engine.
||Fipp & Puget||zprint|
Not all printing engines use (or default to) the dynamic variables in all cases, so setting them at the REPL may or may not have the intended effect. See the respective documentation of each engine:
- Fipp: https://github.com/brandonbloom/fipp/#printer-usage
- Puget: https://github.com/greglook/puget#usage
- zprint: https://github.com/kkinnear/zprint/#what-is-configurable
Width of printed output
If you're using one of the printing engines provided with CIDER, the value of
fill-column will be used for the relevant width option in the options
map. You can override this by hardcoding the relevant option in