Skip to content

Commit 078babf

Browse files
committed
Add filtering behavior to whos()
Defaults to not displaying modules
1 parent f164ac1 commit 078babf

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

base/show.jl

+9-5
Original file line numberDiff line numberDiff line change
@@ -1108,17 +1108,21 @@ function show_nd(io::IO, a::AbstractArray, limit, print_matrix, label_slices)
11081108
cartesianmap(print_slice, tail)
11091109
end
11101110

1111-
function whos(m::Module, pattern::Regex)
1111+
function whos(m::Module, pattern::Regex; filter=Module)
1112+
filtertypes = applicable(start, filter) ?
1113+
filter :
1114+
[filter]
11121115
for v in sort(names(m))
11131116
s = string(v)
1114-
if isdefined(m,v) && ismatch(pattern, s)
1117+
if ( ! (typeof(eval(m,v)) in filtertypes) &&
1118+
isdefined(m,v) && ismatch(pattern, s))
11151119
println(rpad(s, 30), summary(eval(m,v)))
11161120
end
11171121
end
11181122
end
1119-
whos() = whos(r"")
1120-
whos(m::Module) = whos(m, r"")
1121-
whos(pat::Regex) = whos(current_module(), pat)
1123+
whos(;filter=Module) = whos(r""; filter=filter)
1124+
whos(m::Module; filter=Module) = whos(m, r""; filter=filter)
1125+
whos(pat::Regex; filter=Module) = whos(current_module(), pat; filter=filter)
11221126

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

doc/stdlib/base.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ 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=Module])
4040

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

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

0 commit comments

Comments
 (0)