CodeTracking.jl icon indicating copy to clipboard operation
CodeTracking.jl copied to clipboard

Syntax highlighted code source

Open tecosaur opened this issue 2 years ago • 2 comments

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

tecosaur avatar Aug 17 '21 13:08 tecosaur

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?

timholy avatar Aug 18 '21 10:08 timholy

https://github.com/KristofferC/OhMyREPL.jl/pull/253

Moelf avatar Dec 07 '21 19:12 Moelf

Closing this simply because of the need to keep this package very lightweight, otherwise it's quite cool.

timholy avatar Feb 04 '23 13:02 timholy

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 🙂

tecosaur avatar Feb 04 '23 14:02 tecosaur