gorilla-repl
gorilla-repl copied to clipboard
Pretty print syntax highlighting and indentation
Currently you can have nice colourful EDN rendered, or you can have nicely indented EDN rendered in monochrome with pprint
.
It would be nice to have plain Clojure code syntax highlighted and indented, or at least have an option for the latter.
Yes, this would be great, and I was keen on adding it in the first release. The reason it's not already in there is because I have no idea really how to do it! I guess the right thing to do would be to follow the pprint
code. I did look at that before, and it seemed to be really complicated, based on an academic paper of all things.
So yes, I'm positive about the idea, but not desperately confident about actually being able to write it :-)
Blimey, would it be straight-forward to do the physical layout in the DOM with your current client-side?
Looking at pretty_writer.clj, maybe we could do something crazy by sub-classing java.io.Writer
and translating the emitted layout characters to equivalent HTML span elements or whatever. I might have a go at this if worthwhile.
Yes, I wonder ... all of the structural information about what the expression represents is there already in the renderer's DOM output (vectors have class 'clj-vector' etc etc). So I wonder if it could be done just with CSS?! That would be very neat if possible, just toggling one class on the renderer output to switch between pretty and plain. It probably wouldn't be perfect, especially when the indentation got to be deep, but it might not be bad. Would certainly be the easiest thing to try.
This looks like it might be useful: https://github.com/brandonbloom/fipp in terms of providing a pluggable pretty printer. Again... maybe I'll actually try and do it!
@JonyEpsilon Any thoughts on this in the last year? I'm hoping to use gorilla-repl to give a demo which includes displaying a number of nested data structures. I might be available to work on this myself this week, so I'd love to hear whatever thoughts you might have.
In case I can't make any progress on this issue soon, have you got any recommendations for a work-around? Syntax-highlighting + pretty layout would be ideal, but I'd take just the layout if I can't get both to work. I was able to just call (clojure.pprint/pprint ...)
and it printed correctly as separate console output. If I could just suppress the nil result box, that would be a fine work-around for now. Any way to do that?
No new thoughts really. It's something I'd like to see, but I also think it is pretty difficult to do, so haven't attempted it.
There isn't a way to suppress the nil box at the moment.
I hacked in pretty printing + highlighting using org.clojure/clojure.pprint
and venantius/glow
and it works great. Would a dep on glow be acceptable?
@solussd Feel free to push up that code so I can take a look if you want.