Enhanced printing functions for rendering Clojure values. The following options are available to control the printer:
:width
Number of characters to try to wrap pretty-printed forms at.
:print-meta
If true, metadata will be printed before values. Defaults to the value of
*print-meta*
if unset.
:sort-keys
Print maps and sets with ordered keys. Defaults to true, which will sort all collections. If a number, counted collections will be sorted up to the set size. Otherwise, collections are not sorted before printing.
:map-delimiter
The text placed between key-value pairs in a map.
:map-coll-separator
The text placed between a map key and a collection value. The keyword :line will cause line breaks if the whole map does not fit on a single line.
:seq-limit
If set to a positive number, then lists will only render at most the first n elements. This can help prevent unintentional realization of infinite lazy sequences.
:print-color
When true, ouptut colored text from print functions.
:color-markup
:ansi for ANSI color text (the default), :html-inline for inline-styled html, :html-classes to use the names of the keys in the :color-scheme map as class names for spans so styling can be specified via CSS.
:color-scheme
Map of syntax element keywords to color codes.
:print-handlers
A lookup function which will return a rendering function for a given class
type. This will be tried before the built-in type logic. See the
hara.print.pretty.dispatch
namespace for some helpful constructors. The returned
function should accept the current printer and the value to be rendered,
returning a format document.
:print-fallback
Keyword argument specifying how to format unknown values. Puget supports a few different options:
:pretty
renders values with the default colored representation.:print
defers to the standard print method by rendering unknown values
using pr-str
.:error
will throw an exception when types with no defined handler are
encountered.Enhanced printing functions for rendering Clojure values. The following options are available to control the printer: #### General Rendering `:width` Number of characters to try to wrap pretty-printed forms at. `:print-meta` If true, metadata will be printed before values. Defaults to the value of `*print-meta*` if unset. #### Collection Options `:sort-keys` Print maps and sets with ordered keys. Defaults to true, which will sort all collections. If a number, counted collections will be sorted up to the set size. Otherwise, collections are not sorted before printing. `:map-delimiter` The text placed between key-value pairs in a map. `:map-coll-separator` The text placed between a map key and a collection value. The keyword :line will cause line breaks if the whole map does not fit on a single line. `:seq-limit` If set to a positive number, then lists will only render at most the first n elements. This can help prevent unintentional realization of infinite lazy sequences. #### Color Options `:print-color` When true, ouptut colored text from print functions. `:color-markup` :ansi for ANSI color text (the default), :html-inline for inline-styled html, :html-classes to use the names of the keys in the :color-scheme map as class names for spans so styling can be specified via CSS. `:color-scheme` Map of syntax element keywords to color codes. #### Type Handling `:print-handlers` A lookup function which will return a rendering function for a given class type. This will be tried before the built-in type logic. See the `hara.print.pretty.dispatch` namespace for some helpful constructors. The returned function should accept the current printer and the value to be rendered, returning a format document. `:print-fallback` Keyword argument specifying how to format unknown values. Puget supports a few different options: - `:pretty` renders values with the default colored representation. - `:print` defers to the standard print method by rendering unknown values using `pr-str`. - `:error` will throw an exception when types with no defined handler are encountered. - A function value will be called with the current printer options and the unknown value and is expected to return a formatting document representing it.
(canonical-printer)
(canonical-printer handlers)
constructs a canonical printer
(canonical-printer {}) => hara.print.pretty.CanonicalPrinter
constructs a canonical printer (canonical-printer {}) => hara.print.pretty.CanonicalPrinter
Map of print handlers for 'primary' Clojure types. These should take
precedence over the handlers in clojure-interface-handlers
.
Map of print handlers for 'primary' Clojure types. These should take precedence over the handlers in `clojure-interface-handlers`.
Fallback print handlers for other Clojure interfaces.
Fallback print handlers for other Clojure interfaces.
Print handler dispatch combining Java and Clojure handlers with inheritance lookups. Provides a similar experience as the standard Clojure pretty-printer.
Print handler dispatch combining Java and Clojure handlers with inheritance lookups. Provides a similar experience as the standard Clojure pretty-printer.
(format-doc printer value)
provides a format given a printer and value
(format-doc (canonical-printer) :hello) => ":hello"
(format-doc (pretty-printer {}) :hello) => [:span [:pass "[34m"] ":hello" [:pass "[0m"]]
provides a format given a printer and value (format-doc (canonical-printer) :hello) => ":hello" (format-doc (pretty-printer {}) :hello) => [:span [:pass "[34m"] ":hello" [:pass "[0m"]]
(format-doc-edn printer value)
provides a meta-less print formatter
(format-doc-edn (pretty-printer {}) :hello) => [:span [:pass "[34m"] ":hello" [:pass "[0m"]]
provides a meta-less print formatter (format-doc-edn (pretty-printer {}) :hello) => [:span [:pass "[34m"] ":hello" [:pass "[0m"]]
(format-unknown printer value)
(format-unknown printer value repr)
(format-unknown printer value tag repr)
custom printer for an unknown type
(format-unknown (canonical-printer) :hello) => (contains-in [:span "#<" "clojure.lang.Keyword" "@" string? '(" " ":hello") ">"])
custom printer for an unknown type (format-unknown (canonical-printer) :hello) => (contains-in [:span "#<" "clojure.lang.Keyword" "@" string? '(" " ":hello") ">"])
Map of print handlers for Java types. This supports syntax for regular expressions, dates, UUIDs, and futures.
Map of print handlers for Java types. This supports syntax for regular expressions, dates, UUIDs, and futures.
(pprint value)
(pprint value opts)
pretty prints with options
(pprint {:a 1 :b 2 :c (range 5)} {:width 10})
pretty prints with options (pprint {:a 1 :b 2 :c (range 5)} {:width 10})
(pprint-str value)
(pprint-str value opts)
returns the string that is printed
(pprint-str {:a 1 :b 2 :c (range 5)} {:width 10})
returns the string that is printed (pprint-str {:a 1 :b 2 :c (range 5)} {:width 10})
(pr-handler printer value)
creates a print handler for printing strings
(pr-handler (canonical-printer) [1 2 3 4]) => "[1 2 3 4]"
creates a print handler for printing strings (pr-handler (canonical-printer) [1 2 3 4]) => "[1 2 3 4]"
(pretty-printer opts)
constructs a pretty printer
(pretty-printer {}) => hara.print.pretty.PrettyPrinter
constructs a pretty printer (pretty-printer {}) => hara.print.pretty.PrettyPrinter
(render-out printer value)
helper to pprint and pprint-str
(with-out-str (render-out (canonical-printer) {:a 1 :b 2 :c (range 5)})) => "{:a 1 :b 2 :c (0 1 2 3 4)}"
helper to pprint and pprint-str (with-out-str (render-out (canonical-printer) {:a 1 :b 2 :c (range 5)})) => "{:a 1 :b 2 :c (0 1 2 3 4)}"
(tagged-handler tag value-fn)
creates a custom handler for a tagged literal
((tagged-handler 'object (fn [x] (map inc x))) (canonical-printer {}) [1 2 3 4]) => [:span "#object" " " [:group "(" [:align '("2" " " "3" " " "4" " " "5")] ")"]]
creates a custom handler for a tagged literal ((tagged-handler 'object (fn [x] (map inc x))) (canonical-printer {}) [1 2 3 4]) => [:span "#object" " " [:group "(" [:align '("2" " " "3" " " "4" " " "5")] ")"]]
(unknown-handler printer value)
creates a custom handler for an unknown object
(unknown-handler (canonical-printer) (Thread/currentThread)) => throws
creates a custom handler for an unknown object (unknown-handler (canonical-printer) (Thread/currentThread)) => throws
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close