Skip to content

Commit 0c3147e

Browse files
committed
use multiline=true, limit=false in reprmime and stringmime
some small tweaks to output function changes and doc updates
1 parent 5d7dd9c commit 0c3147e

File tree

8 files changed

+32
-26
lines changed

8 files changed

+32
-26
lines changed

base/docs/helpdb/Base.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,9 +2888,9 @@ Show an expression and result, returning the result.
28882888
"""
28892889
showcompact(x)
28902890
2891-
Show a more compact representation of a value. This is used for printing array elements. If
2892-
a new type has a different compact representation,
2893-
it should test `get(io, :limit, false)` in its normal `show` method.
2891+
Show a more compact representation of a value. This is used for printing array elements.
2892+
If a new type has a different compact representation,
2893+
it should test `get(io, :compact, false)` in its normal `show` method.
28942894
"""
28952895
showcompact
28962896

base/linalg/bidiag.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ svdfact(M::Bidiagonal; thin::Bool=true) = svdfact!(copy(M),thin=thin)
121121

122122
function show(io::IO, M::Bidiagonal)
123123
if get(io, :multiline, false)
124-
invoke(show, (IO, AbstractArray), io, M)
124+
Base.showarray(io, M)
125125
else
126126
println(io, summary(M), ":")
127127
print(io, " diag:")

base/multimedia.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,33 @@ mimewritable(m::AbstractString, x) = mimewritable(MIME(m), x)
5757
# format and is returned unmodified. This is useful so that raw data can be
5858
# passed to display(m::MIME, x).
5959

60+
verbose_writemime(io, m, x) = writemime(IOContext(io,multiline=true,limit=false), m, x)
61+
6062
macro textmime(mime)
6163
quote
6264
mimeT = MIME{Symbol($mime)}
6365
# avoid method ambiguities with the general definitions below:
6466
# (Q: should we treat Vector{UInt8} as a String?)
65-
Base.Multimedia.reprmime(m::mimeT, x::Vector{UInt8}) = sprint(writemime, m, x)
67+
Base.Multimedia.reprmime(m::mimeT, x::Vector{UInt8}) = sprint(verbose_writemime, m, x)
6668
Base.Multimedia.stringmime(m::mimeT, x::Vector{UInt8}) = reprmime(m, x)
6769

6870
Base.Multimedia.istextmime(::mimeT) = true
6971
if $(mime != "text/plain") # strings are shown escaped for text/plain
7072
Base.Multimedia.reprmime(m::mimeT, x::AbstractString) = x
7173
end
72-
Base.Multimedia.reprmime(m::mimeT, x) = sprint(writemime, m, x)
74+
Base.Multimedia.reprmime(m::mimeT, x) = sprint(verbose_writemime, m, x)
7375
Base.Multimedia.stringmime(m::mimeT, x) = reprmime(m, x)
7476
end
7577
end
7678

7779
istextmime(::MIME) = false
7880
function reprmime(m::MIME, x)
7981
s = IOBuffer()
80-
writemime(s, m, x)
82+
verbose_writemime(s, m, x)
8183
takebuf_array(s)
8284
end
8385
reprmime(m::MIME, x::Vector{UInt8}) = x
84-
stringmime(m::MIME, x) = base64encode(writemime, m, x)
86+
stringmime(m::MIME, x) = base64encode(verbose_writemime, m, x)
8587
stringmime(m::MIME, x::Vector{UInt8}) = base64encode(write, x)
8688

8789
# it is convenient to accept strings instead of ::MIME

base/show.jl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,11 +1445,8 @@ function print_matrix_repr(io, X::AbstractArray)
14451445
if compact && !haskey(io, :compact)
14461446
io = IOContext(io, :compact => compact)
14471447
end
1448-
prefix *= "["
1449-
ind = " "^length(prefix)
1450-
print(io, prefix)
1448+
print(io, prefix, "[")
14511449
for i=1:size(X,1)
1452-
i > 1 && print(io, ind)
14531450
for j=1:size(X,2)
14541451
j > 1 && print(io, " ")
14551452
if !isassigned(X,i,j)
@@ -1460,14 +1457,15 @@ function print_matrix_repr(io, X::AbstractArray)
14601457
end
14611458
end
14621459
if i < size(X,1)
1463-
print(io, ";")
1464-
else
1465-
print(io, "]")
1460+
print(io, "; ")
14661461
end
14671462
end
1463+
print(io, "]")
14681464
end
14691465

1470-
function show(io::IO, X::AbstractArray)
1466+
show(io::IO, X::AbstractArray) = showarray(io, X)
1467+
1468+
function showarray(io::IO, X::AbstractArray)
14711469
repr = !get(io, :multiline, false)
14721470
if repr && ndims(X) == 1
14731471
return show_vector(io, X, "[", "]")
@@ -1502,8 +1500,8 @@ function show(io::IO, X::AbstractArray)
15021500
print_matrix(io, X, punct...)
15031501
else
15041502
show_nd(io, X,
1505-
(io, slice) -> print_matrix(io, slice, punct...),
1506-
!repr)
1503+
(io, slice) -> print_matrix(io, slice, punct...),
1504+
!repr)
15071505
end
15081506
end
15091507
end

doc/stdlib/io-network.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ Text I/O
434434

435435
.. Docstring generated from Julia source
436436
437-
Show a more compact representation of a value. This is used for printing array elements. If a new type has a different compact representation, it should test ``Base.limit_output(io)`` in its normal ``show`` method.
437+
Show a more compact representation of a value. This is used for printing array elements. If a new type has a different compact representation, it should test ``get(io, :compact, false)`` in its normal ``show`` method.
438438

439439
.. function:: showall(x)
440440

test/nullable.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,13 @@ for (i, T) in enumerate(types)
9292
@test takebuf_string(io1) == @sprintf("Nullable{%s}(%s)", T, takebuf_string(io2))
9393

9494
a1 = [x2]
95+
show(IOContext(io1, compact=false), a1)
96+
show(IOContext(io2, compact=false), x2)
97+
@test takebuf_string(io1) ==
98+
@sprintf("Nullable{%s}[%s]", string(T), takebuf_string(io2))
99+
95100
show(io1, a1)
96-
show(io2, x2)
101+
show(IOContext(io2, compact=true), x2)
97102
@test takebuf_string(io1) ==
98103
@sprintf("Nullable{%s}[%s]", string(T), takebuf_string(io2))
99104
end

test/ranges.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,9 @@ end
571571
# to test print_range in range.jl
572572
replstrmime(x) = sprint((io,x) -> writemime(IOContext(io, multiline=true, limit=true), MIME("text/plain"), x), x)
573573
@test replstrmime(1:4) == "1:4"
574-
@test replstrmime(linspace(1,5,7)) == "7-element LinSpace{Float64}:\n 1.0,1.66667,2.33333,3.0,3.66667,4.33333,5.0"
574+
@test stringmime("text/plain", 1:4) == "1:4"
575+
@test stringmime("text/plain", linspace(1,5,7)) == "7-element LinSpace{Float64}:\n 1.0,1.66667,2.33333,3.0,3.66667,4.33333,5.0"
576+
@test repr(linspace(1,5,7)) == "linspace(1.0,5.0,7)"
575577
@test replstrmime(0:100.) == "0.0:1.0:100.0"
576578
# next is to test a very large range, which should be fast because print_range
577579
# only examines spacing of the left and right edges of the range, sufficient

test/replutil.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,8 @@ let err_str,
262262
err_str = @except_str randn(1)() MethodError
263263
@test contains(err_str, "MethodError: objects of type Array{Float64,1} are not callable")
264264
end
265-
strmime(x) = sprint((io,x)->writemime(IOContext(io,multiline=true), MIME("text/plain"), x), x)
266-
@test strmime(FunctionLike()) == "(::FunctionLike) (generic function with 0 methods)"
267-
@test ismatch(r"^@doc \(macro with \d+ method[s]?\)$", strmime(getfield(Base, Symbol("@doc"))))
265+
@test stringmime("text/plain", FunctionLike()) == "(::FunctionLike) (generic function with 0 methods)"
266+
@test ismatch(r"^@doc \(macro with \d+ method[s]?\)$", stringmime("text/plain", getfield(Base, Symbol("@doc"))))
268267

269268
method_defs_lineno = @__LINE__
270269
Base.Symbol() = throw(ErrorException("1"))
@@ -292,8 +291,8 @@ let err_str,
292291
@test sprint(show, which(reinterpret(EightBitTypeT{Int32}, 0x54), Tuple{})) == "(::EightBitTypeT)() at $sp:$(method_defs_lineno + 6)"
293292
@test startswith(sprint(show, which(getfield(Base, Symbol("@doc")), Tuple{Vararg{Any}})), "@doc(x...) at boot.jl:")
294293
@test startswith(sprint(show, which(FunctionLike(), Tuple{})), "(::FunctionLike)() at $sp:$(method_defs_lineno + 7)")
295-
@test strmime(FunctionLike()) == "(::FunctionLike) (generic function with 1 method)"
296-
@test strmime(Core.arraysize) == "arraysize (built-in function)"
294+
@test stringmime("text/plain", FunctionLike()) == "(::FunctionLike) (generic function with 1 method)"
295+
@test stringmime("text/plain", Core.arraysize) == "arraysize (built-in function)"
297296

298297
err_str = @except_stackframe Symbol() ErrorException
299298
@test err_str == " in Symbol() at $sn:$(method_defs_lineno + 0)"

0 commit comments

Comments
 (0)