diff --git a/src/sci/configs/cljs/pprint.cljs b/src/sci/configs/cljs/pprint.cljs index d2d9b72..ab79063 100644 --- a/src/sci/configs/cljs/pprint.cljs +++ b/src/sci/configs/cljs/pprint.cljs @@ -4,9 +4,19 @@ (def pns (sci/create-ns 'cljs.pprint nil)) +(defn ^:sci/macro with-pprint-dispatch + "Execute body with the pretty print dispatch function bound to function." + [_ _ function & body] + `(cljs.core/binding [cljs.pprint/*print-pprint-dispatch* ~function] + ~@body)) + +(def print-pprint-dispatch (sci/new-dynamic-var '*print-pprint-dispatch* + cljs.pprint/*print-pprint-dispatch* {:ns pns})) + (defn pprint [& args] (binding [*print-fn* @sci/print-fn - *print-newline* @sci/print-newline] + *print-newline* @sci/print-newline + pp/*print-pprint-dispatch* @print-pprint-dispatch] (apply pp/pprint args))) (defn print-table [& args] @@ -21,8 +31,11 @@ (def cljs-pprint-namespace {'pprint (sci/copy-var pprint pns) + '*print-pprint-dispatch* print-pprint-dispatch 'print-table (sci/copy-var print-table pns) - 'cl-format (sci/copy-var cl-format pns)}) + 'cl-format (sci/copy-var cl-format pns) + 'code-dispatch (sci/copy-var pp/code-dispatch pns) + 'with-pprint-dispatch (sci/copy-var with-pprint-dispatch pns)}) (def namespaces {'cljs.pprint cljs-pprint-namespace})