1.2.0 permalink Arrow_down_16x16
  • (pretty-writer writer max-columns miser-width)

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/pprint/pretty_writer.clj:368 top

(defn pretty-writer [writer max-columns miser-width]
  (let [lb (struct logical-block nil nil (ref 0) (ref 0) (ref false) (ref false))
        fields (ref {:pretty-writer true
                     :base (column-writer writer max-columns)
                     :logical-blocks lb 
                     :sections nil
                     :mode :writing
                     :buffer []
                     :buffer-block lb
                     :buffer-level 1
                     :miser-width miser-width
                     :trailing-white-space nil
                     :pos 0})]
    (proxy [Writer IDeref] []
      (deref [] fields)

          ;;     (prlabel write x (getf :mode))
          (condp = (class x)
            (let [^String s0 (write-initial-lines this x)
                  ^String s (.replaceFirst s0 "\\s+$" "")
                  white-space (.substring s0 (count s))
                  mode (getf :mode)]
               (if (= mode :writing)
                   (write-white-space this)
                   (.write (getf :base) s)
                   (setf :trailing-white-space white-space))
                 (let [oldpos (getf :pos)
                       newpos (+ oldpos (count s0))]
                   (setf :pos newpos)
                   (add-to-buffer this (make-buffer-blob s white-space oldpos newpos))))))

            (write-char this x)
            (write-char this x))))

      (flush []
             (if (= (getf :mode) :buffering)
                (write-tokens this (getf :buffer) true)
                (setf :buffer []))
               (write-white-space this)))

      (close []
             (.flush this)))))
Vars in clojure.contrib.pprint.pretty-writer/pretty-writer: write = class condp defn deref dosync flush let proxy
Used in 0 other vars

Comments top

No comments for pretty-writer. Log in to add a comment.