Skip to content

Commit

Permalink
remove io :multiline attribute
Browse files Browse the repository at this point in the history
this attribute doesn't nest properly,
and functions just end up branching almost the entire code based
on this parameter, so it's cleaner as a separate method

fix #17087
fix #16910
fix #17090
  • Loading branch information
vtjnash authored and JeffBezanson committed Jun 29, 2016
1 parent cfc10f0 commit f9fe68b
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 234 deletions.
23 changes: 11 additions & 12 deletions base/Enums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ macro enum(T,syms...)
let insts = ntuple(i->$(esc(typename))($values[i]), $(length(vals)))
Base.instances(::Type{$(esc(typename))}) = insts
end
function Base.print(io::IO,x::$(esc(typename)))
function Base.print(io::IO, x::$(esc(typename)))
for (sym, i) in $vals
if i == Int32(x)
print(io, sym); break
end
end
end
function Base.show(io::IO,x::$(esc(typename)))
function Base.show(io::IO, x::$(esc(typename)))
if get(io, :compact, false)
print(io, x)
else
Expand All @@ -101,16 +101,15 @@ macro enum(T,syms...)
print(io, " = ", Int(x))
end
end
function Base.show(io::IO,t::Type{$(esc(typename))})
if get(io, :multiline, false)
print(io, "Enum ")
Base.show_datatype(io, t)
print(io, ":")
for (sym, i) in $vals
print(io, "\n", sym, " = ", i)
end
else
Base.show_datatype(io, t)
function Base.show(io::IO, t::Type{$(esc(typename))})
Base.show_datatype(io, t)
end
function Base.show(io::IO, ::MIME"text/plain", t::Type{$(esc(typename))})
print(io, "Enum ")
Base.show_datatype(io, t)
print(io, ":")
for (sym, i) in $vals
print(io, "\n", sym, " = ", i)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ end

==(a::REPLDisplay, b::REPLDisplay) = a.repl === b.repl

function display(d::REPLDisplay, ::MIME"text/plain", x)
function display(d::REPLDisplay, mime::MIME"text/plain", x)
io = outstream(d.repl)
Base.have_color && write(io, answer_color(d.repl))
show(IOContext(io, multiline=true, limit=true), MIME("text/plain"), x)
show(IOContext(io, :limit => true), mime, x)
println(io)
end
display(d::REPLDisplay, x) = display(d, MIME("text/plain"), x)
Expand Down
13 changes: 13 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,19 @@ function symperm{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, pinv::Vector{Ti})
"Pkg.add(\"SuiteSparse\") to install SuiteSparse on Julia v0.5."))
end

# needs to be a macro so that we can use ::@mime(s) in type declarations
eval(Multimedia, quote
export @MIME
macro MIME(s)
Base.warn_once("@MIME(\"\") is deprecated, use MIME\"\" instead.")
if isa(s,AbstractString)
:(MIME{$(Expr(:quote, Symbol(s)))})
else
:(MIME{Symbol($s)})
end
end
end)

# During the 0.5 development cycle, do not add any deprecations below this line
# To be deprecated in 0.6

Expand Down
132 changes: 22 additions & 110 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,91 +49,34 @@ function _truncate_at_width_or_chars(str, width, chars="", truncmark="…")
end

function show{K,V}(io::IO, t::Associative{K,V})
recur_io = IOContext(io, SHOWN_SET=t, multiline=false)
recur_io = IOContext(io, :SHOWN_SET => t)
limit::Bool = get(io, :limit, false)
compact = !get(io, :multiline, false)
if !haskey(io, :compact)
recur_io = IOContext(recur_io, compact=true)
recur_io = IOContext(recur_io, :compact => true)
end
if compact
# show in a Julia-syntax-like form: Dict(k=>v, ...)
if isempty(t)
print(io, typeof(t), "()")
else
if isleaftype(K) && isleaftype(V)
print(io, typeof(t).name)
else
print(io, typeof(t))
end
print(io, '(')
if !show_circular(io, t)
first = true
n = 0
for pair in t
first || print(io, ',')
first = false
show(recur_io, pair)
n+=1
limit && n >= 10 && (print(io, ""); break)
end
end
print(io, ')')
end
return
end

# Otherwise show more descriptively, with one line per key/value pair
print(io, summary(t))
isempty(t) && return
print(io, ":\n ")
show_circular(io, t) && return
if limit
sz = displaysize(io)
rows, cols = sz[1] - 3, sz[2]
rows < 2 && (print(io, ""); return)
cols < 12 && (cols = 12) # Minimum widths of 2 for key, 4 for value
cols -= 6 # Subtract the widths of prefix " " separator " => "
rows -= 2 # Subtract the summary and final ⋮ continuation lines

# determine max key width to align the output, caching the strings
ks = Array{AbstractString}(min(rows, length(t)))
vs = Array{AbstractString}(min(rows, length(t)))
keylen = 0
vallen = 0
for (i, (k, v)) in enumerate(t)
i > rows && break
ks[i] = sprint(0, show, k, env=recur_io)
vs[i] = sprint(0, show, v, env=recur_io)
keylen = clamp(length(ks[i]), keylen, cols)
vallen = clamp(length(vs[i]), vallen, cols)
end
if keylen > max(div(cols, 2), cols - vallen)
keylen = max(cld(cols, 3), cols - vallen)
end
else
rows = cols = 0
end

first = true
for (i, (k, v)) in enumerate(t)
first || print(io, "\n ")
first = false
limit && i > rows && (print(io, rpad("", keylen), " => ⋮"); break)

if limit
key = rpad(_truncate_at_width_or_chars(ks[i], keylen, "\r\n"), keylen)
# show in a Julia-syntax-like form: Dict(k=>v, ...)
if isempty(t)
print(io, typeof(t), "()")
else
if isleaftype(K) && isleaftype(V)
print(io, typeof(t).name)
else
key = sprint(0, show, k, env=recur_io)
print(io, typeof(t))
end
print(recur_io, key)
print(io, " => ")

if limit
val = _truncate_at_width_or_chars(vs[i], cols - keylen, "\r\n")
print(io, val)
else
show(recur_io, v)
print(io, '(')
if !show_circular(io, t)
first = true
n = 0
for pair in t
first || print(io, ',')
first = false
show(recur_io, pair)
n+=1
limit && n >= 10 && (print(io, ""); break)
end
end
print(io, ')')
end
end

Expand All @@ -147,38 +90,7 @@ end
summary{T<:Union{KeyIterator,ValueIterator}}(iter::T) =
string(T.name, " for a ", summary(iter.dict))

function show(io::IO, iter::Union{KeyIterator,ValueIterator})
if !get(io, :multiline, false)
return show(io, collect(iter))
end
print(io, summary(iter))
isempty(iter) && return
print(io, ". ", isa(iter,KeyIterator) ? "Keys" : "Values", ":")
limit::Bool = get(io, :limit, false)
if limit
sz = displaysize(io)
rows, cols = sz[1] - 3, sz[2]
rows < 2 && (print(io, ""); return)
cols < 4 && (cols = 4)
cols -= 2 # For prefix " "
rows -= 2 # For summary and final ⋮ continuation lines
else
rows = cols = 0
end

for (i, v) in enumerate(iter)
print(io, "\n ")
limit && i >= rows && (print(io, ""); break)

if limit
str = sprint(0, show, v, env=io)
str = _truncate_at_width_or_chars(str, cols, "\r\n")
print(io, str)
else
show(io, v)
end
end
end
show(io::IO, iter::Union{KeyIterator,ValueIterator}) = show(io, collect(iter))

length(v::Union{KeyIterator,ValueIterator}) = length(v.dict)
isempty(v::Union{KeyIterator,ValueIterator}) = isempty(v.dict)
Expand Down
15 changes: 6 additions & 9 deletions base/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,12 @@ svdfact(M::Bidiagonal; thin::Bool=true) = svdfact!(copy(M),thin=thin)
####################

function show(io::IO, M::Bidiagonal)
if get(io, :multiline, false)
Base.showarray(io, M)
else
println(io, summary(M), ":")
print(io, " diag:")
print_matrix(io, (M.dv)')
print(io, M.isupper?"\n super:":"\n sub:")
print_matrix(io, (M.ev)')
end
# TODO: make this readable and one-line
println(io, summary(M), ":")
print(io, " diag:")
print_matrix(io, (M.dv)')
print(io, M.isupper?"\n super:":"\n sub:")
print_matrix(io, (M.ev)')
end

size(M::Bidiagonal) = (length(M.dv), length(M.dv))
Expand Down
12 changes: 1 addition & 11 deletions base/multimedia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Multimedia

export Display, display, pushdisplay, popdisplay, displayable, redisplay,
MIME, @MIME, @MIME_str, reprmime, stringmime, istextmime,
MIME, @MIME_str, reprmime, stringmime, istextmime,
mimewritable, TextDisplay

###########################################################################
Expand All @@ -18,16 +18,6 @@ MIME(s) = MIME{Symbol(s)}()
show{mime}(io::IO, ::MIME{mime}) = print(io, "MIME type ", string(mime))
print{mime}(io::IO, ::MIME{mime}) = print(io, mime)

# needs to be a macro so that we can use ::@mime(s) in type declarations
macro MIME(s)
Base.warn_once("@MIME(\"\") is deprecated, use MIME\"\" instead.")
if isa(s,AbstractString)
:(MIME{$(Expr(:quote, Symbol(s)))})
else
:(MIME{Symbol($s)})
end
end

macro MIME_str(s)
:(MIME{$(Expr(:quote, Symbol(s)))})
end
Expand Down
30 changes: 8 additions & 22 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,25 +236,13 @@ linspace(start::Real, stop::Real, len::Real=50) =
linspace(promote(AbstractFloat(start), AbstractFloat(stop))..., len)

function show(io::IO, r::LinSpace)
if get(io, :multiline, false)
# show for linspace, e.g.
# linspace(1,3,7)
# 7-element LinSpace{Float64}:
# 1.0,1.33333,1.66667,2.0,2.33333,2.66667,3.0
print(io, summary(r))
if !isempty(r)
println(io, ":")
print_range(io, r)
end
else
print(io, "linspace(")
show(io, first(r))
print(io, ',')
show(io, last(r))
print(io, ',')
show(io, length(r))
print(io, ')')
end
print(io, "linspace(")
show(io, first(r))
print(io, ',')
show(io, last(r))
print(io, ',')
show(io, length(r))
print(io, ')')
end

"""
Expand Down Expand Up @@ -497,9 +485,7 @@ function getindex{T}(r::LinSpace{T}, s::OrdinalRange)
return linspace(vfirst, vlast, sl)
end

function show(io::IO, r::Range)
print(io, repr(first(r)), ':', repr(step(r)), ':', repr(last(r)))
end
show(io::IO, r::Range) = print(io, repr(first(r)), ':', repr(step(r)), ':', repr(last(r)))
show(io::IO, r::UnitRange) = print(io, repr(first(r)), ':', repr(last(r)))

=={T<:Range}(r::T, s::T) = (first(r) == first(s)) & (step(r) == step(s)) & (last(r) == last(s))
Expand Down
Loading

0 comments on commit f9fe68b

Please sign in to comment.