Back

*print-right-margin* (clj)

(source)

variable

Pretty printing will try to avoid anything going beyond this column. Set it to nil to have pprint let the line be arbitrarily long. This will ignore all non-mandatory newlines.

Examples

clojure
  "(ns autodoc.build-html
  \"This is the namespace that builds the HTML pages themselves.
It is implemented with a number of custom enlive templates.\"
  {:skip-wiki true, :author \"Tom Faulhaber\"}
  (:refer-clojure :exclude [empty complement])
  (:import [java.util.jar JarFile]
           [java.io File FileWriter BufferedWriter StringReader
                    BufferedInputStream BufferedOutputStream
                    ByteArrayOutputStream FileReader FileInputStream]
           [java.util.regex Pattern])
  (:require [clojure.string :as str])
  (:use [net.cgrand.enlive-html :exclude (deftemplate)]
        [clojure.java.io :only (as-file file writer)]
        [clojure.java.shell :only (sh)]
        [clojure.pprint :only (pprint cl-format pprint-ident
                               pprint-logical-block set-pprint-dispatch
                               get-pretty-writer fresh-line)]
        [clojure.data.json :only (pprint-json)]
        [autodoc.collect-info :only (contrib-info)]
        [autodoc.params :only (params expand-classpath)])
  (:use clojure.set clojure.java.io clojure.data clojure.java.browse
        clojure.inspector clojure.zip clojure.stacktrace))")

(defn tst-pprint
  "A helper function to pprint to a string with a restricted right margin"
  [right-margin obj]
  (binding [*print-right-margin* right-margin
            *print-pretty* true]
    (write obj :stream nil)))
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])

(binding [pprint/*print-pprint-dispatch* pprint/code-dispatch ; <3>
          pprint/*print-right-margin* 30]
     (pprint/pprint nested-statement))