aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/pprint/ColumnWriter.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/clojure/contrib/pprint/ColumnWriter.clj')
-rw-r--r--src/clojure/contrib/pprint/ColumnWriter.clj18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/clojure/contrib/pprint/ColumnWriter.clj b/src/clojure/contrib/pprint/ColumnWriter.clj
index 381c81fe..fc6ae75c 100644
--- a/src/clojure/contrib/pprint/ColumnWriter.clj
+++ b/src/clojure/contrib/pprint/ColumnWriter.clj
@@ -20,6 +20,7 @@
:constructors {[java.io.Writer Integer] [],
[java.io.Writer] []}
:methods [[getColumn [] Integer]
+ [getLine [] Integer]
[getMaxColumn [] Integer]
[setMaxColumn [Integer] Void]
[getWriter [] java.io.Writer]]
@@ -29,7 +30,7 @@
(defn- -init
([writer] (-init writer *default-page-width*))
- ([writer max-columns] [[] (ref {:max max-columns, :cur 0, :base writer})]))
+ ([writer max-columns] [[] (ref {:max max-columns, :cur 0, :line 0 :base writer})]))
(defn- get-field [#^clojure.contrib.pprint.ColumnWriter this sym]
(sym @(.state this)))
@@ -40,11 +41,15 @@
(defn- -getColumn [this]
(get-field this :cur))
+(defn- -getLine [this]
+ (get-field this :line))
+
(defn- -getMaxColumn [this]
(get-field this :max))
(defn- -setMaxColumn [this new-max]
- (dosync (set-field this :max new-max)))
+ (dosync (set-field this :max new-max))
+ nil)
(defn- -getWriter [this]
(get-field this :base))
@@ -62,7 +67,10 @@
nl (.lastIndexOf s (int \newline))]
(dosync (if (neg? nl)
(set-field this :cur (+ (get-field this :cur) (count s)))
- (set-field this :cur (- (count s) nl 1))))
+ (do
+ (set-field this :cur (- (count s) nl 1))
+ (set-field this :line (+ (get-field this :line)
+ (count (filter #(= % \newline) s)))))))
(.write #^java.io.Writer (get-field this :base) s))
Integer
@@ -70,7 +78,9 @@
(defn- write-char [#^clojure.contrib.pprint.ColumnWriter this #^Integer c]
(dosync (if (= c (int \newline))
- (set-field this :cur 0)
+ (do
+ (set-field this :cur 0)
+ (set-field this :line (inc (get-field this :line))))
(set-field this :cur (inc (get-field this :cur)))))
(.write #^java.io.Writer (get-field this :base) c))