Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 16995aa

Browse files
committedMay 22, 2017
jump to numbered method in the REPL
1 parent f988566 commit 16995aa

File tree

6 files changed

+38
-30
lines changed

6 files changed

+38
-30
lines changed
 

‎NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Library improvements
3131
* the functions `base` and `digits` digits now accept a negative
3232
base (like `ndigits` did) ([#21692]).
3333

34+
* Method lists are now printed as a numbered list. In addition, the source code of a
35+
method can be opened in an editor by entering the corresponding number in the REPL
36+
and pressing `^Q` ([#22007]).
37+
3438
Compiler/Runtime improvements
3539
-----------------------------
3640

‎base/REPL.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -891,11 +891,11 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
891891
end
892892
end,
893893

894-
# Open the editor at the location of a stackframe
894+
# Open the editor at the location of a stackframe or method
895895
# This is accessing a global variable that gets set in
896-
# the show_backtrace function.
896+
# the show_backtrace and show_method_table functions.
897897
"^Q" => (s, o...) -> begin
898-
linfos = Base.LAST_BACKTRACE_LINE_INFOS
898+
linfos = Base.LAST_SHOWN_LINE_INFOS
899899
str = String(take!(LineEdit.buffer(s)))
900900
n = tryparse(Int, str)
901901
isnull(n) && @goto writeback

‎base/methodshow.jl

+5-1
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,15 @@ function show_method_table(io::IO, ms::MethodList, max::Int=-1, header::Bool=tru
150150
kwtype = isdefined(mt, :kwsorter) ? Nullable{DataType}(typeof(mt.kwsorter)) : Nullable{DataType}()
151151
n = rest = 0
152152
local last
153+
154+
resize!(LAST_SHOWN_LINE_INFOS, 0)
153155
for meth in ms
154156
if max==-1 || n<max
157+
n += 1
155158
println(io)
159+
print(io, "[$(n)] ")
156160
show(io, meth; kwtype=kwtype)
157-
n += 1
161+
push!(LAST_SHOWN_LINE_INFOS, (string(meth.file), meth.line))
158162
else
159163
rest += 1
160164
last = meth

‎base/replutil.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -629,20 +629,20 @@ function show_trace_entry(io, frame, n; prefix = "")
629629
end
630630

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

636636
function show_backtrace(io::IO, t::Vector)
637637
n_frames = 0
638638
frame_counter = 0
639-
resize!(LAST_BACKTRACE_LINE_INFOS, 0)
639+
resize!(LAST_SHOWN_LINE_INFOS, 0)
640640
process_backtrace((a,b) -> n_frames += 1, t)
641641
n_frames != 0 && print(io, "\nStacktrace:")
642642
process_entry = (last_frame, n) -> begin
643643
frame_counter += 1
644644
show_trace_entry(IOContext(io, :backtrace => true), last_frame, n, prefix = string(" [", frame_counter, "] "))
645-
push!(LAST_BACKTRACE_LINE_INFOS, (string(last_frame.file), last_frame.line))
645+
push!(LAST_SHOWN_LINE_INFOS, (string(last_frame.file), last_frame.line))
646646
end
647647
process_backtrace(process_entry, t)
648648
end

‎doc/src/manual/interacting-with-julia.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ to do so).
171171
| `^K` | "Kill" to end of line, placing the text in a buffer |
172172
| `^Y` | "Yank" insert the text from the kill buffer |
173173
| `^T` | Transpose the characters about the cursor |
174-
| `^Q` | Write a number in REPL and press `^Q` to open editor at corresponding stackframe |
174+
| `^Q` | Write a number in REPL and press `^Q` to open editor at corresponding stackframe or method |
175175

176176

177177
### Customizing keybindings

‎doc/src/manual/methods.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ of those methods are, use the [`methods()`](@ref) function:
166166
```julia
167167
julia> methods(f)
168168
# 2 methods for generic function "f":
169-
f(x::Float64, y::Float64) in Main at none:1
170-
f(x::Number, y::Number) in Main at none:1
169+
[1] f(x::Float64, y::Float64) in Main at none:1
170+
[2] f(x::Number, y::Number) in Main at none:1
171171
```
172172

173173
which shows that `f` has two methods, one taking two `Float64` arguments and one taking arguments
@@ -196,25 +196,25 @@ of methods:
196196
```julia
197197
julia> methods(+)
198198
# 180 methods for generic function "+":
199-
+(x::Bool, z::Complex{Bool}) in Base at complex.jl:224
200-
+(x::Bool, y::Bool) in Base at bool.jl:89
201-
+(x::Bool) in Base at bool.jl:86
202-
+(x::Bool, y::T) where T<:AbstractFloat in Base at bool.jl:96
203-
+(x::Bool, z::Complex) in Base at complex.jl:231
204-
+(a::Float16, b::Float16) in Base at float.jl:372
205-
+(x::Float32, y::Float32) in Base at float.jl:374
206-
+(x::Float64, y::Float64) in Base at float.jl:375
207-
+(z::Complex{Bool}, x::Bool) in Base at complex.jl:225
208-
+(z::Complex{Bool}, x::Real) in Base at complex.jl:239
209-
+(x::Char, y::Integer) in Base at char.jl:40
210-
+(c::BigInt, x::BigFloat) in Base.MPFR at mpfr.jl:303
211-
+(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) in Base.GMP at gmp.jl:303
212-
+(a::BigInt, b::BigInt, c::BigInt, d::BigInt) in Base.GMP at gmp.jl:296
213-
+(a::BigInt, b::BigInt, c::BigInt) in Base.GMP at gmp.jl:290
214-
+(x::BigInt, y::BigInt) in Base.GMP at gmp.jl:258
215-
+(x::BigInt, c::Union{UInt16, UInt32, UInt64, UInt8}) in Base.GMP at gmp.jl:315
199+
[1] +(x::Bool, z::Complex{Bool}) in Base at complex.jl:227
200+
[2] +(x::Bool, y::Bool) in Base at bool.jl:89
201+
[3] +(x::Bool) in Base at bool.jl:86
202+
[4] +(x::Bool, y::T) where T<:AbstractFloat in Base at bool.jl:96
203+
[5] +(x::Bool, z::Complex) in Base at complex.jl:234
204+
[6] +(a::Float16, b::Float16) in Base at float.jl:373
205+
[7] +(x::Float32, y::Float32) in Base at float.jl:375
206+
[8] +(x::Float64, y::Float64) in Base at float.jl:376
207+
[9] +(z::Complex{Bool}, x::Bool) in Base at complex.jl:228
208+
[10] +(z::Complex{Bool}, x::Real) in Base at complex.jl:242
209+
[11] +(x::Char, y::Integer) in Base at char.jl:40
210+
[12] +(c::BigInt, x::BigFloat) in Base.MPFR at mpfr.jl:307
211+
[13] +(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) in Base.GMP at gmp.jl:392
212+
[14] +(a::BigInt, b::BigInt, c::BigInt, d::BigInt) in Base.GMP at gmp.jl:391
213+
[15] +(a::BigInt, b::BigInt, c::BigInt) in Base.GMP at gmp.jl:390
214+
[16] +(x::BigInt, y::BigInt) in Base.GMP at gmp.jl:361
215+
[17] +(x::BigInt, c::Union{UInt16, UInt32, UInt64, UInt8}) in Base.GMP at gmp.jl:398
216216
...
217-
+(a, b, c, xs...) at operators.jl:119
217+
[180] +(a, b, c, xs...) in Base at operators.jl:424
218218
```
219219

220220
Multiple dispatch together with the flexible parametric type system give Julia its ability to

0 commit comments

Comments
 (0)
Please sign in to comment.