Skip to content

Commit 56f2afd

Browse files
committed
Add filtering behavior to whos()
Defaults to not displaying modules
1 parent 053780d commit 56f2afd

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

base/show.jl

+12-8
Original file line numberDiff line numberDiff line change
@@ -1118,17 +1118,21 @@ function show_nd(io::IO, a::AbstractArray, limit, print_matrix, label_slices)
11181118
cartesianmap(print_slice, tail)
11191119
end
11201120

1121-
function whos(m::Module, pattern::Regex)
1122-
for v in sort(names(m))
1123-
s = string(v)
1124-
if isdefined(m,v) && ismatch(pattern, s)
1125-
println(rpad(s, 30), summary(eval(m,v)))
1121+
function whos(m::Module, pattern::Regex; filter=[])
1122+
filtertypes = applicable(start, filter) ?
1123+
filter : [filter]
1124+
filtertest(var) = ! any(T -> typeof(var) <: T, filtertypes)
1125+
for n in sort(names(m))
1126+
s = string(n)
1127+
v = eval(m,n)
1128+
if isdefined(m,n) && ismatch(pattern, s) && filtertest(v)
1129+
println(rpad(s, 30), summary(v))
11261130
end
11271131
end
11281132
end
1129-
whos() = whos(r"")
1130-
whos(m::Module) = whos(m, r"")
1131-
whos(pat::Regex) = whos(current_module(), pat)
1133+
whos(;filter=Module) = whos(r""; filter=filter)
1134+
whos(m::Module; filter=[]) = whos(m, r""; filter=filter)
1135+
whos(pat::Regex; filter=[]) = whos(current_module(), pat; filter=filter)
11321136

11331137
# global flag for limiting output
11341138
# TODO: this should be replaced with a better mechanism. currently it is only

doc/stdlib/base.rst

+7-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ Getting Around
4141

4242
Determine whether Julia is running an interactive session.
4343

44-
.. function:: whos([Module,] [pattern::Regex])
44+
.. function:: whos([Module,] [pattern::Regex]; [filter=nothing])
4545

46-
Print information about exported global variables in a module, optionally restricted
47-
to those matching ``pattern``.
46+
Print information about exported global variables in a module (defaults to
47+
the current module), optionally restricted to those matching ``pattern``.
48+
49+
The ``filter`` keyword is either a single type or iterable object of types.
50+
Variables who are of type or subtype of an element in ``filter`` will not be
51+
displayed. If invoked without arguments, ``filter`` defaults to ``Module``.
4852

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

0 commit comments

Comments
 (0)