Skip to content

Commit 23807e2

Browse files
committed
Add filtering behavior to whos()
Defaults to not displaying modules
1 parent d50524a commit 23807e2

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
@@ -1104,17 +1104,21 @@ function show_nd(io::IO, a::AbstractArray, limit, print_matrix, label_slices)
11041104
cartesianmap(print_slice, tail)
11051105
end
11061106

1107-
function whos(m::Module, pattern::Regex)
1107+
function whos(m::Module, pattern::Regex; filter=nothing)
1108+
filtertypes = applicable(start, filter) ?
1109+
filter :
1110+
[filter]
11081111
for v in sort(names(m))
11091112
s = string(v)
1110-
if isdefined(m,v) && ismatch(pattern, s)
1113+
if ( ! (typeof(eval(m,v)) in filtertypes) &&
1114+
isdefined(m,v) && ismatch(pattern, s))
11111115
println(rpad(s, 30), summary(eval(m,v)))
11121116
end
11131117
end
11141118
end
1115-
whos() = whos(r"")
1116-
whos(m::Module) = whos(m, r"")
1117-
whos(pat::Regex) = whos(current_module(), pat)
1119+
whos(;filter=Module) = whos(r""; filter=filter)
1120+
whos(m::Module; filter=nothing) = whos(m, r""; filter=filter)
1121+
whos(pat::Regex; filter=nothing) = whos(current_module(), pat; filter=filter)
11181122

11191123
# global flag for limiting output
11201124
# 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)