Browse Source

[julia] Automatically load some more tooling in REPL.

master
Fredrik Ekre 3 years ago
parent
commit
6edebde547
  1. 29
      .julia/config/startup.jl

29
.julia/config/startup.jl

@ -24,8 +24,16 @@ if Base.isinteractive() &&
end) end)
# Automatically load tooling on demand: # Automatically load tooling on demand:
# - Debugger.jl when encountering @enter or @run
# - BenchmarkTools.jl when encountering @btime or @benchmark # - BenchmarkTools.jl when encountering @btime or @benchmark
# - Debugger.jl when encountering @enter or @run
# - Profile.jl when encountering @profile
# - ProfileView.jl when encountering @profview
local tooling_dict = Dict{Symbol,Vector{Symbol}}(
:BenchmarkTools => Symbol.(["@btime", "@benchmark"]),
:Debugger => Symbol.(["@enter", "@run"]),
:Profile => Symbol.(["@profile"]),
:ProfileView => Symbol.(["@profview"]),
)
pushfirst!(REPL.repl_ast_transforms, function(ast::Union{Expr,Nothing}) pushfirst!(REPL.repl_ast_transforms, function(ast::Union{Expr,Nothing})
function contains_macro(ast, m) function contains_macro(ast, m)
return ast isa Expr && ( return ast isa Expr && (
@ -33,21 +41,14 @@ if Base.isinteractive() &&
any(x -> contains_macro(x, m), ast.args) any(x -> contains_macro(x, m), ast.args)
) )
end end
if !isdefined(Main, :Debugger) && ( for (mod, macros) in tooling_dict
contains_macro(ast, Symbol("@enter")) || contains_macro(ast, Symbol("@run")) if any(contains_macro(ast, s) for s in macros) && !isdefined(Main, mod)
) @info "Loading $mod ..."
@info "Loading Debugger ..."
try try
Core.eval(Main, :(using Debugger)) Core.eval(Main, :(using $mod))
catch catch err
@info "Failed to automatically load $mod" exception=err
end end
elseif !isdefined(Main, :BenchmarkTools) && (
contains_macro(ast, Symbol("@btime")) || contains_macro(ast, Symbol("@benchmark"))
)
@info "Loading BenchmarkTools ..."
try
Core.eval(Main, :(using BenchmarkTools))
catch
end end
end end
return ast return ast

Loading…
Cancel
Save