在REPL中调试或运行julia代码时,我通常会看到错误消息... at ./REPL[161]:12 [inlined]....这个数字161意味着161-thREPL中的评估,我猜.所以我的问题是我们可以在朱莉娅的提示中显示这个数字,julia [161]>而不是julia>?
Julia的优势之一是其超强的灵活性.这在Julia 0.7(夜间版本)中非常简单.
julia> repl = Base.active_repl.interface.modes[1]
"Prompt(\"julia> \",...)"
julia> repl.prompt = () -> "julia[$(length(repl.hist.history) - repl.hist.start_idx + 1)] >"
#1 (generic function with 1 method)
julia[3] >
julia[3] >2
2
julia[4] >f = () -> error("e")
#3 (generic function with 1 method)
julia[5] >f()
ERROR: e
Stacktrace:
[1] error at .\error.jl:33 [inlined]
[2] (::getfield(, Symbol("##3#4")))() at .\REPL[4]:1
[3] top-level scope
Run Code Online (Sandbox Code Playgroud)
你只需要将前两行放在你身上~/.juliarc并享受〜
由于在julia 0.7之后REPL有几处变化,因此这些代码在旧版本中不起作用.
编辑:嗯,实际上需要更多努力才能使其发挥作用.juliarc.jl.试试这段代码:
atreplinit() do repl
repl.interface = Base.REPL.setup_interface(repl)
repl = Base.active_repl.interface.modes[1]
repl.prompt = () -> "julia[$(length(repl.hist.history) - repl.hist.start_idx + 1)] >"
end
Run Code Online (Sandbox Code Playgroud)