venantius / ultra

A Leiningen plugin for a superior development environment
Eclipse Public License 1.0
1.24k stars 37 forks source link

Colorized `source` #15

Closed venantius closed 9 years ago

venantius commented 9 years ago

At the moment the source function just does a general pretty-print, giving us the following:

screen shot 2015-02-04 at 4 19 05 pm

This should be patched to provide a syntax-highlighted printing of the source in question.

venantius commented 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.

screen shot 2015-02-21 at 7 16 32 pm

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?

venantius commented 9 years ago

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

venantius commented 9 years ago

Also I should use with-out-str for this s.t. we don't get the extra nil printed at the end.

venantius commented 9 years ago

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.

venantius commented 9 years ago

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).

venantius commented 9 years ago
screen shot 2015-08-01 at 12 14 02 pm

If you don't think this looks dope as hell I claim you are smoking the crack rocks.