Created
November 18, 2021 14:43
-
-
Save sritchie/f644ffea81687ec8e9a752cdfa2ce5ce to your computer and use it in GitHub Desktop.
Print writer extensions for functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn install-fn-printers! | |
"NOTE: If you are using Emacs + cider-nrepl, these two `print-method` | |
implementations will not be installed. I'm currently working on a fix to get | |
this enabled in the Emacs environment... But if you want to test this feature | |
out, simply execute these forms. | |
https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/print_method.clj#L42-L71 | |
TODO write a with-methods instead to do this..." | |
[] | |
#?(:clj | |
(do | |
(defmethod print-method AFunction [f ^java.io.Writer w] | |
(.write w (.toString ^Object (v/freeze f)))) | |
(defmethod print-method MultiFn [f ^java.io.Writer w] | |
(.write w (.toString ^Object (v/freeze f))))) | |
:cljs | |
(extend-protocol IPrintWithWriter | |
MetaFn | |
(-pr-writer [x writer _] | |
(write-all writer (.toString (v/freeze x)))) | |
MultiFn | |
(-pr-writer [x writer _] | |
(write-all writer (.toString (v/freeze x))))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment