Back

*print-miser-width* (clj)

(source)

variable

The column at which to enter miser style. Depending on the dispatch table, miser style add newlines in more places to try to keep lines short allowing for further levels of nesting.

Examples

clj-commons/useful
;; leave out of ns decl so we can load with classlojure.io/resource-forms
(require '[clojure.pprint :as p])
(require '[clojure.stacktrace :as s])

(letfn [(interrogate-form [list-head form]
          `(let [display# (fn [val#]
                            (let [form# (with-out-str
                                          (clojure.pprint/with-pprint-dispatch
                                            clojure.pprint/code-dispatch
                                            (clojure.pprint/pprint '~form)))
                                  val# (with-out-str (clojure.pprint/pprint val#))]
                              (~@list-head
                               (if (every? (partial > clojure.pprint/*print-miser-width*)
                                           [(count form#) (count val#)])
                                 (str (subs form# 0 (dec (count form#))) " is " val#)
                                 (str form# "--------- is ---------\n" val#)))))]
             (try (doto ~form display#)
                  (catch Throwable t#
                    (display# {:thrown t#
                               :trace (with-out-str
                                        (clojure.stacktrace/print-cause-trace t#))})
                    (throw t#)))))]
reborg/clojure-essential-reference
(require '[clojure.pprint :as pretty])

(doc pretty/write) ; <1>
;; -------------------------
;; clojure.pprint/write
;; ([object & kw-args])
;; Write an object subject to the current bindings of the printer control variables.
;; Use the kw-args argument to override individual variables for this call (and any
;; recursive calls). Returns the string result if :stream is nil or nil otherwise.
;;
;; The following keyword arguments can be passed with values:
;;   Keyword              Meaning                              Default value
;;   :stream              Writer for output or nil             *out*
;;   :base                Base to use for writing rationals    *print-base*
;;   :length              Maximum elements to show in sublists *print-length*
;;   :level               Maximum depth                        *print-level*
;;   :miser-width         Width to enter miser mode            *print-miser-width* ; <2>
;;   :dispatch            The pretty print dispatch function   *print-pprint-dispatch*
;;   :pretty              If true, do pretty printing          *print-pretty*
;;   :radix               If true, prepend a radix specifier   *print-radix*
;;   :right-margin        The column for the right margin      *print-right-margin*
;;   :suppress-namespaces If true, no namespaces in symbols    *print-suppress-namespaces*
reborg/clojure-essential-reference
(require '[clojure.pprint :as pprint])

pprint/*print-miser-width* ; <1>
;; 40