Skip to content

Commit

Permalink
jump to numbered method in the REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed May 21, 2017
1 parent f988566 commit e51c3f5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,11 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
end
end,

# Open the editor at the location of a stackframe
# Open the editor at the location of a stackframe or method
# This is accessing a global variable that gets set in
# the show_backtrace function.
# the show_backtrace and show_method_table functions.
"^Q" => (s, o...) -> begin
linfos = Base.LAST_BACKTRACE_LINE_INFOS
linfos = Base.LAST_SHOWN_LINE_INFOS
str = String(take!(LineEdit.buffer(s)))
n = tryparse(Int, str)
isnull(n) && @goto writeback
Expand Down
6 changes: 5 additions & 1 deletion base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,15 @@ function show_method_table(io::IO, ms::MethodList, max::Int=-1, header::Bool=tru
kwtype = isdefined(mt, :kwsorter) ? Nullable{DataType}(typeof(mt.kwsorter)) : Nullable{DataType}()
n = rest = 0
local last

resize!(LAST_SHOWN_LINE_INFOS, 0)
for meth in ms
if max==-1 || n<max
n += 1
println(io)
print(io, "[$(n)] ")
show(io, meth; kwtype=kwtype)
n += 1
push!(LAST_SHOWN_LINE_INFOS, (string(meth.file), meth.line))
else
rest += 1
last = meth
Expand Down
10 changes: 5 additions & 5 deletions base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -629,20 +629,20 @@ function show_trace_entry(io, frame, n; prefix = "")
end

# Contains file name and file number. Gets set when a backtrace
# is shown. Used by the REPL to make it possible to open
# the location of a stackframe in the edítor.
global LAST_BACKTRACE_LINE_INFOS = Tuple{String, Int}[]
# or methodlist is shown. Used by the REPL to make it possible to open
# the location of a stackframe/method in the editor.
global LAST_SHOWN_LINE_INFOS = Tuple{String, Int}[]

function show_backtrace(io::IO, t::Vector)
n_frames = 0
frame_counter = 0
resize!(LAST_BACKTRACE_LINE_INFOS, 0)
resize!(LAST_SHOWN_LINE_INFOS, 0)
process_backtrace((a,b) -> n_frames += 1, t)
n_frames != 0 && print(io, "\nStacktrace:")
process_entry = (last_frame, n) -> begin
frame_counter += 1
show_trace_entry(IOContext(io, :backtrace => true), last_frame, n, prefix = string(" [", frame_counter, "] "))
push!(LAST_BACKTRACE_LINE_INFOS, (string(last_frame.file), last_frame.line))
push!(LAST_SHOWN_LINE_INFOS, (string(last_frame.file), last_frame.line))
end
process_backtrace(process_entry, t)
end
Expand Down
2 changes: 1 addition & 1 deletion doc/src/manual/interacting-with-julia.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ to do so).
| `^K` | "Kill" to end of line, placing the text in a buffer |
| `^Y` | "Yank" insert the text from the kill buffer |
| `^T` | Transpose the characters about the cursor |
| `^Q` | Write a number in REPL and press `^Q` to open editor at corresponding stackframe |
| `^Q` | Write a number in REPL and press `^Q` to open editor at corresponding stackframe or method |


### Customizing keybindings
Expand Down

0 comments on commit e51c3f5

Please sign in to comment.