diff --git a/base/methodshow.jl b/base/methodshow.jl index 611686c067db6..154a79d849924 100644 --- a/base/methodshow.jl +++ b/base/methodshow.jl @@ -32,6 +32,7 @@ function arg_decl_parts(m::Method) end function show(io::IO, m::Method) + print(io, m.func.code.name) tv, decls, file, line = arg_decl_parts(m) if !isempty(tv) show_delim_array(io, tv, '{', ',', '}', false) @@ -57,7 +58,6 @@ function show_method_table(io::IO, mt::MethodTable, max::Int=-1, header::Bool=tr while !is(d,()) if max==-1 || n") @@ -130,9 +131,27 @@ function writemime(io::IO, mime::MIME"text/html", mt::MethodTable) print(io, "$n $meths for generic function $name:") end + +# pretty-printing of Vector{Method} for output of methodswith: + +function writemime(io::IO, mime::MIME"text/html", mt::AbstractVector{Method}) + print(io, summary(mt)) + if !isempty(mt) + print(io, ":") + end +end + +# override usual show method for Vector{Method}: don't abbreviate long lists +writemime(io::IO, mime::MIME"text/plain", mt::AbstractVector{Method}) = + showarray(io, mt, limit=false) diff --git a/base/util.jl b/base/util.jl index 1f49fc7c530d3..0b2bc78aa4a29 100644 --- a/base/util.jl +++ b/base/util.jl @@ -94,8 +94,7 @@ function whicht(f, types) d = f.env.defs while !is(d,()) if is(d.func.code, lsd) - print(STDOUT, f.env.name) - show(STDOUT, d); println(STDOUT) + display(d) return end d = d.next @@ -412,38 +411,36 @@ versioninfo(verbose::Bool) = versioninfo(STDOUT,verbose) # `methodswith` -- shows a list of methods using the type given -function methodswith(io::IO, t::Type, m::Module, showparents::Bool) +function methodswith(t::Type, m::Module, showparents::Bool=false) + meths = Method[] for nm in names(m) try mt = eval(m, nm) d = mt.env.defs while !is(d,()) if any(map(x -> x == t || (showparents && t <: x && x != Any && x != ANY && !isa(x, TypeVar)), d.sig)) - print(io, nm) - show(io, d) - println(io) + push!(meths, d) end d = d.next end end end + return meths end -methodswith(t::Type, m::Module, showparents::Bool) = methodswith(STDOUT, t, m, showparents) -methodswith(t::Type, showparents::Bool) = methodswith(STDOUT, t, showparents) -methodswith(t::Type, m::Module) = methodswith(STDOUT, t, m, false) -methodswith(t::Type) = methodswith(STDOUT, t, false) -function methodswith(io::IO, t::Type, showparents::Bool) +function methodswith(t::Type, showparents::Bool=false) + meths = Method[] mainmod = current_module() # find modules in Main for nm in names(mainmod) if isdefined(mainmod,nm) mod = eval(mainmod, nm) if isa(mod, Module) - methodswith(io, t, mod, showparents) + meths = [meths, methodswith(t, mod, showparents)] end end end + return meths end ## printing with color ## diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index aed578f7e08af..1cdbaf14a8c30 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -98,8 +98,8 @@ Getting Around .. function:: methodswith(typ[, showparents]) - Show all methods with an argument of type ``typ``. If optional - ``showparents`` is ``true``, also show arguments with a parent type + Return an array of methods with an argument of type ``typ``. If optional + ``showparents`` is ``true``, also return arguments with a parent type of ``typ``, excluding type ``Any``. .. function:: @show