Skip to content

Commit

Permalink
Support logical-block macro working correctly in external namespaces.
Browse files Browse the repository at this point in the history
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information
tomfaulhaber authored and stuarthalloway committed Jun 23, 2010
1 parent a08eac8 commit a642708
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/clj/clojure/pprint/pprint_base.clj
Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion test/clojure/test_clojure/pprint/test_pretty.clj
Expand Up @@ -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.