Skip to content
Browse files

Support logical-block macro working correctly in external namespaces.

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information...
1 parent a08eac8 commit a642708b6e9a1718b74248cc28a467bd53afc81f @tomfaulhaber tomfaulhaber committed with stuarthalloway Jun 15, 2010
Showing with 38 additions and 8 deletions.
  1. +12 −7 src/clj/clojure/pprint/pprint_base.clj
  2. +26 −1 test/clojure/test_clojure/pprint/test_pretty.clj
View
19 src/clj/clojure/pprint/pprint_base.clj
@@ -311,14 +311,19 @@ and :suffix."
{:added "1.2", :arglists '[[options* body]]}
[& args]
(let [[options body] (parse-lb-options #{:prefix :per-line-prefix :suffix} args)]
- `(do (if (level-exceeded)
+ `(do (if (#'clojure.pprint/level-exceeded)
(.write ^java.io.Writer *out* "#")
- (binding [*current-level* (inc *current-level*)
- *current-length* 0]
- (start-block *out*
- ~(:prefix options) ~(:per-line-prefix options) ~(:suffix options))
- ~@body
- (end-block *out*)))
+ (do
+ (push-thread-bindings {#'clojure.pprint/*current-level*
+ (inc (var-get #'clojure.pprint/*current-level*))
+ #'clojure.pprint/*current-length* 0})
+ (try
+ (#'clojure.pprint/start-block *out*
+ ~(:prefix options) ~(:per-line-prefix options) ~(:suffix options))
+ ~@body
+ (#'clojure.pprint/end-block *out*)
+ (finally
+ (pop-thread-bindings)))))
nil)))
(defn pprint-newline
View
27 test/clojure/test_clojure/pprint/test_pretty.clj
@@ -245,6 +245,31 @@ Usage: *hello*
)
-
+;;; Some simple tests of dispatch
+
+(defmulti
+ test-dispatch
+ "A test dispatch method"
+ {:added "1.2" :arglists '[[object]]}
+ #(and (seq %) (not (string? %))))
+
+(defmethod test-dispatch true [avec]
+ (pprint-logical-block :prefix "[" :suffix "]"
+ (loop [aseq (seq avec)]
+ (when aseq
+ (write-out (first aseq))
+ (when (next aseq)
+ (.write ^java.io.Writer *out* " ")
+ (pprint-newline :linear)
+ (recur (next aseq)))))))
+
+(defmethod test-dispatch false [aval] (pr aval))
+
+(simple-tests dispatch-tests
+ (with-pprint-dispatch test-dispatch
+ (with-out-str
+ (pprint '("hello" "there"))))
+ "[\"hello\" \"there\"]\n"
+)

0 comments on commit a642708

Please sign in to comment.
Something went wrong with that request. Please try again.