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 6, 2015
1 parent f164ac1 commit e9d8e6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 9 additions & 5 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1108,17 +1108,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=Module)
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=Module) = whos(m, r""; filter=filter)
whos(pat::Regex; filter=Module) = 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
6 changes: 4 additions & 2 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ Getting Around

Determine whether Julia is running an interactive session.

.. function:: whos([Module,] [pattern::Regex])
.. function:: whos([Module,] [pattern::Regex]; [filter=Module])

Print information about exported global variables in a module, optionally restricted
to those matching ``pattern``.
to those matching ``pattern``. The ``filter`` keyword is either a single type or
iterable object of types that will not be displayed. By default, only imported
submodules are filtered out.

.. function:: edit(file::AbstractString, [line])

Expand Down

0 comments on commit e9d8e6b

Please sign in to comment.