CodeTracking.jl
CodeTracking.jl copied to clipboard
Syntax highlighted code source
Hey, this seemed nifty so I made a variant macro @code_src
that prints a syntax-highlighted @code_string
using OhMyREPL.
I have no idea if optional dependencies are easy, or if this of interest, but just in case here's what I have:
using Tokenize, Crayons, InteractiveUtils
macro code_src(expr...)
codestr = InteractiveUtils.gen_call_with_extracted_types_and_kwargs(CodeTracking, :code_string, expr)
quote
tokens = collect(Tokenize.tokenize($codestr))
crayons = Vector{Crayon}(undef, length(tokens))
fill!(crayons, Crayon())
OhMyREPL.Passes.SyntaxHighlighter.SYNTAX_HIGHLIGHTER_SETTINGS(crayons, tokens, 0)
OhMyREPL.untokenize_with_ANSI(crayons, tokens)
end
end
Very cool!
It can't go in this package, though, because this needs to stay extremely lightweight. It's the foundation for JuliaInterpreter, which is then a foundation for both the debuggers and for Revise. But an add-on package would make sense, or perhaps contributing that under a @require
to OhMyREPL?
https://github.com/KristofferC/OhMyREPL.jl/pull/253
Closing this simply because of the need to keep this package very lightweight, otherwise it's quite cool.
With weak deps I feel better about turning this into a PR based on weakdeps. Let's see if I can get around to that 🙂