timholy / Rebugger.jl

An expression-level debugger for Julia with a provocative command-line (REPL) user interface
Other
171 stars 18 forks source link

Loading Rebugger only in REPL mode? #50

Closed oschulz closed 5 years ago

oschulz commented 5 years ago

The Rebugger docs currently don't mention a way to only load Rebugger if Julia is in REPL mode (analog to the atreplinit() ... in the Revise docs). I came up with this - it seems to work, but is it safe (without calling Rebugger.repl_init, which doesn't seem to work in this setting)?

"startup.jl":

atreplinit() do repl
    try
        @eval using Revise
        @async Revise.wait_steal_repl_backend()
        @info "Loaded Revise."
    catch
        @warn "Could not load Revise."
    end

    try
        @eval using Rebugger
        Rebugger.keybindings[:stepin] = "\e[17~"      # Add the keybinding F6 to step into a function.
        Rebugger.keybindings[:stacktrace] = "\e[18~"  # Add the keybinding F7 to capture a stacktrace.
        @info "Loaded Rebugger."
    catch
        @warn "Could not load Rebugger."
    end
end
timholy commented 5 years ago

Hmm, yes, I should have updated those docs. I am a little surprised it's working without Rebugger.repl_init, for reference here is my startup.jl:

atreplinit() do repl
    try
        @eval using Revise
        @async Revise.wait_steal_repl_backend()
        @async Revise.debug_logger()
    catch
    end
end

atreplinit() do repl
    try
        @eval using Rebugger
        Rebugger.repl_init()
    catch
    end
end

(I turn on the debug logger to make it easier to trap Revise mistakes, not that I've noticed one in a while.)

timholy commented 5 years ago

Oh, it looks like __init__ contains a call to REPL.setup_interface too, so I guess it's no longer necessary. Want to submit a PR? Or should I?

oschulz commented 5 years ago

Done. :-)