From 59dcf82e75c4b620306f868c872bcc1e19511d35 Mon Sep 17 00:00:00 2001 From: Josh Langsfeld Date: Fri, 6 Feb 2015 15:51:08 -0500 Subject: [PATCH] Add filtering behavior to whos() Defaults to not displaying modules --- base/show.jl | 14 +++++++++----- doc/stdlib/base.rst | 9 ++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/base/show.jl b/base/show.jl index 9ef84a767182a..692cd01ac933e 100644 --- a/base/show.jl +++ b/base/show.jl @@ -1106,17 +1106,21 @@ function show_nd(io::IO, a::AbstractArray, limit, print_matrix, label_slices) cartesianmap(print_slice, tail) end -function whos(m::Module, pattern::Regex) +function whos(m::Module, pattern::Regex; filter=nothing) + filtertypes = applicable(start, filter) ? + filter : + [filter] for v in sort(names(m)) s = string(v) - if isdefined(m,v) && ismatch(pattern, s) + if ( ! (typeof(eval(m,v)) in filtertypes) && + isdefined(m,v) && ismatch(pattern, s)) println(rpad(s, 30), summary(eval(m,v))) end end end -whos() = whos(r"") -whos(m::Module) = whos(m, r"") -whos(pat::Regex) = whos(current_module(), pat) +whos(;filter=Module) = whos(r""; filter=filter) +whos(m::Module; filter=nothing) = whos(m, r""; filter=filter) +whos(pat::Regex; filter=nothing) = whos(current_module(), pat; filter=filter) # global flag for limiting output # TODO: this should be replaced with a better mechanism. currently it is only diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index aafb19d69f53b..29bf57b654870 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -36,10 +36,13 @@ Getting Around Determine whether Julia is running an interactive session. -.. function:: whos([Module,] [pattern::Regex]) +.. function:: whos([Module,] [pattern::Regex]; [filter=nothing]) - Print information about exported global variables in a module, optionally restricted - to those matching ``pattern``. + Print information about exported global variables in a module (defaults to + ``Main``), optionally restricted to those matching ``pattern``. The + ``filter`` keyword is either a single type or iterable object of types that + will not be displayed. If invoked without arguments, ``filter`` defaults to + ``Module``. .. function:: edit(file::AbstractString, [line])