Skip to content

Instantly share code, notes, and snippets.

@taylorSando
Created February 8, 2016 15:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taylorSando/c63b2c49bce0ff1107df to your computer and use it in GitHub Desktop.
Save taylorSando/c63b2c49bce0ff1107df to your computer and use it in GitHub Desktop.
A way to have better function output using pr-str
;; Using defonce, because in a reloaded workflow, only want this to run once
;; Changes the default printing of the javascript source code of a function to just the function name.
;; Changes instances of dollar sign to dot, and underscores to hyphens.
;; cljs$core$pr_str would be cljs.core.pr-str instead
(defonce
ugly-pr-opts-hack
(set!
cljs.core/pr-opts
(let [old-pr-opts (cljs.core/pr-opts) ]
(fn []
(assoc
old-pr-opts
:alt-impl
(fn [obj writer opts]
(if (goog/isFunction obj)
(-write writer (-> (.-name obj)
(string/replace #"[$]" ".")
(string/replace #"[_]" "-")))
(cljs.core/pr-writer-impl obj writer opts)))))
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment