Skip to content

Commit

Permalink
fix #5966
Browse files Browse the repository at this point in the history
showcompact() should always be compact; confine the output limit stuff to
array printing
  • Loading branch information
JeffBezanson committed Feb 26, 2014
1 parent 8854bad commit 2946305
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
6 changes: 2 additions & 4 deletions base/grisu.jl
Expand Up @@ -118,10 +118,8 @@ show(io::IO, x::Float16) = _show(io, x, PRECISION, 5, true)
print(io::IO, x::Float32) = _show(io, x, SHORTEST_SINGLE, 0, false)
print(io::IO, x::Float16) = _show(io, x, PRECISION, 5, false)

showcompact(io::IO, x::Float64) =
(Base._limit_output::Bool) ? _show(io, x, PRECISION, 6, false) : _show(io, x, SHORTEST, 0, false)
showcompact(io::IO, x::Float32) =
(Base._limit_output::Bool) ? _show(io, x, PRECISION, 6, false) : _show(io, x, SHORTEST_SINGLE, 0, false)
showcompact(io::IO, x::Float64) = _show(io, x, PRECISION, 6, false)
showcompact(io::IO, x::Float32) = _show(io, x, PRECISION, 6, false)
showcompact(io::IO, x::Float16) = _show(io, x, PRECISION, 5, false)

# normal:
Expand Down
30 changes: 17 additions & 13 deletions base/show.jl
@@ -1,3 +1,4 @@

show(x) = show(STDOUT::IO, x)

function print(io::IO, s::Symbol)
Expand Down Expand Up @@ -84,6 +85,9 @@ end
showcompact(io::IO, x) = show(io, x)
showcompact(x) = showcompact(STDOUT::IO, x)

showcompact_lim(io, x) = _limit_output ? showcompact(io, x) : show(io, x)
showcompact_lim(io, x::Number) = _limit_output ? showcompact(io, x) : print(io, x)

macro show(exs...)
blk = Expr(:block)
for ex in exs
Expand Down Expand Up @@ -133,7 +137,7 @@ function show_delim_array(io::IO, itr::AbstractArray, op, delim, cl, delim_one,
x = itr[i]
multiline = isa(x,AbstractArray) && ndims(x)>1 && length(x)>0
newline && multiline && println(io)
compact ? showcompact(io, x) : show(io, x)
compact ? showcompact_lim(io, x) : show(io, x)
end
i += 1
if i > l
Expand Down Expand Up @@ -699,22 +703,22 @@ dump(io::IO, x::DataType) = dump(io, x, 5, "")
dump(io::IO, x::TypeVar, n::Int, indent) = println(io, x.name)


alignment(x::Any) = (0, length(sprint(showcompact, x)))
alignment(x::Number) = (length(sprint(showcompact, x)), 0)
alignment(x::Integer) = (length(sprint(showcompact, x)), 0)
alignment(x::Any) = (0, length(sprint(showcompact_lim, x)))
alignment(x::Number) = (length(sprint(showcompact_lim, x)), 0)
alignment(x::Integer) = (length(sprint(showcompact_lim, x)), 0)
function alignment(x::Real)
m = match(r"^(.*?)((?:[\.eE].*)?)$", sprint(showcompact, x))
m == nothing ? (length(sprint(showcompact, x)), 0) :
m = match(r"^(.*?)((?:[\.eE].*)?)$", sprint(showcompact_lim, x))
m == nothing ? (length(sprint(showcompact_lim, x)), 0) :
(length(m.captures[1]), length(m.captures[2]))
end
function alignment(x::Complex)
m = match(r"^(.*,)(.*)$", sprint(showcompact, x))
m == nothing ? (length(sprint(showcompact, x)), 0) :
m = match(r"^(.*,)(.*)$", sprint(showcompact_lim, x))
m == nothing ? (length(sprint(showcompact_lim, x)), 0) :
(length(m.captures[1]), length(m.captures[2]))
end
function alignment(x::Rational)
m = match(r"^(.*?/)(/.*)$", sprint(showcompact, x))
m == nothing ? (length(sprint(showcompact, x)), 0) :
m = match(r"^(.*?/)(/.*)$", sprint(showcompact_lim, x))
m == nothing ? (length(sprint(showcompact_lim, x)), 0) :
(length(m.captures[1]), length(m.captures[2]))
end

Expand Down Expand Up @@ -761,7 +765,7 @@ function print_matrix_row(io::IO,
if isassigned(X,i,j)
x = X[i,j]
a = alignment(x)
sx = sprint(showcompact, x)
sx = sprint(showcompact_lim, x)
else
a = undef_ref_alignment
sx = undef_ref_str
Expand Down Expand Up @@ -948,7 +952,7 @@ function print_matrix_repr(io, X::AbstractArray)
print(io, undef_ref_str)
else
el = X[i,j]
compact ? showcompact(io, el) : show(io, el)
compact ? showcompact_lim(io, el) : show(io, el)
end
end
if i < size(X,1)
Expand All @@ -970,7 +974,7 @@ function showarray(io::IO, X::AbstractArray;
header && println(io, ":")
if ndims(X) == 0
if isassigned(X)
return showcompact(io, X[])
return showcompact_lim(io, X[])
else
return print(io, undef_ref_str)
end
Expand Down

0 comments on commit 2946305

Please sign in to comment.