Skip to content

Commit 7e98a83

Browse files
committed
Add filtering behavior to whos()
Defaults to not displaying modules
1 parent a2c3206 commit 7e98a83

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

base/show.jl

+9-5
Original file line numberDiff line numberDiff line change
@@ -1099,17 +1099,21 @@ function show_nd(io::IO, a::AbstractArray, limit, print_matrix, label_slices)
10991099
cartesianmap(print_slice, tail)
11001100
end
11011101

1102-
function whos(m::Module, pattern::Regex)
1102+
function whos(m::Module, pattern::Regex; filter=nothing)
1103+
filtertypes = applicable(start, filter) ?
1104+
filter :
1105+
[filter]
11031106
for v in sort(names(m))
11041107
s = string(v)
1105-
if isdefined(m,v) && ismatch(pattern, s)
1108+
if ( ! (typeof(eval(m,v)) in filtertypes) &&
1109+
isdefined(m,v) && ismatch(pattern, s))
11061110
println(rpad(s, 30), summary(eval(m,v)))
11071111
end
11081112
end
11091113
end
1110-
whos() = whos(r"")
1111-
whos(m::Module) = whos(m, r"")
1112-
whos(pat::Regex) = whos(current_module(), pat)
1114+
whos(;filter=Module) = whos(r""; filter=filter)
1115+
whos(m::Module; filter=nothing) = whos(m, r""; filter=filter)
1116+
whos(pat::Regex; filter=nothing) = whos(current_module(), pat; filter=filter)
11131117

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

doc/stdlib/base.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ Getting Around
3636

3737
Determine whether Julia is running an interactive session.
3838

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

41-
Print information about exported global variables in a module, optionally restricted
42-
to those matching ``pattern``.
41+
Print information about exported global variables in a module (defaults to
42+
``Main``), optionally restricted to those matching ``pattern``. The
43+
``filter`` keyword is either a single type or iterable object of types that
44+
will not be displayed. By default, nothing is filtered, unless the function
45+
is invoked as ``whos()``. Then imported modules will not be displayed.
4346

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

0 commit comments

Comments
 (0)