Closed venantius closed 9 years ago
As a status update on this feature - as of Ultra 0.2.1
this function now exists as ultra.repl/pprint-source
.
I was initially reluctant to replace clojure.repl/source
with this, as the syntax highlighting requires the use of (read-string)
, which can be used to execute unsafe code.
However, since pprint-source
would require you to already have the given code in your classpath, I'm having second thoughts. Might have to obtain a second opinion. @keithballinger, do you have any thoughts on this?
Looks like I can get what I want here out of using clojure/tools.reader
, which has a safe read-string implementation that I can use to swap in to replace the default read-string of clojure.core
Also I should use with-out-str
for this s.t. we don't get the extra nil printed at the end.
I'm still not super happy with how this function currently handles macros. I think I've figured out a way around it but I haven't actually tested it yet.
I'm going to leave this alone for a while. I've poked at it many times now and I think that while it's okay as it currently sits, the only "true" solution takes a radically different approach and instead delivers syntax highlighting rather than pretty-printing through fipp/puget/whidbey et al. This has two advantages: first, it avoids the (potentially unsafe) use of read-string
, and second it keeps the output relatively clean (i.e., doesn't macroexpand the source in question).
If you don't think this looks dope as hell I claim you are smoking the crack rocks.
At the moment the
source
function just does a general pretty-print, giving us the following:This should be patched to provide a syntax-highlighted printing of the source in question.