Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created November 18, 2021 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sritchie/f644ffea81687ec8e9a752cdfa2ce5ce to your computer and use it in GitHub Desktop.
Save sritchie/f644ffea81687ec8e9a752cdfa2ce5ce to your computer and use it in GitHub Desktop.
Print writer extensions for functions.
(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