From 8253c69a537bcc82e8ff122e5f905fe9d1e303f0 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Mon, 7 Oct 2024 14:28:16 +0200 Subject: [PATCH] Add pprint with-pprint-dispatch + code-dispatch --- src/sci/configs/cljs/pprint.cljs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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})