Skip to content

Commit

Permalink
Add pprint with-pprint-dispatch + code-dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Oct 7, 2024
1 parent 33575ca commit 8253c69
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/sci/configs/cljs/pprint.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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})

Expand Down

0 comments on commit 8253c69

Please sign in to comment.