Skip to content

Commit

Permalink
Add filtering behavior to whos()
Browse files Browse the repository at this point in the history
Defaults to not displaying modules
  • Loading branch information
jdlangs committed Feb 18, 2015
1 parent 9ac4266 commit 59dcf82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 9 additions & 5 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down

0 comments on commit 59dcf82

Please sign in to comment.