Skip to content

Commit 8272e02

Browse files
committed
deprecate writemime to methods of show.
part of #14052
1 parent c43b5e5 commit 8272e02

29 files changed

+119
-110
lines changed

base/Enums.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,14 @@ macro enum(T,syms...)
9999
print(io, x, "::", $(esc(typename)), " = ", Int(x))
100100
end
101101
end
102-
function Base.writemime(io::IO,::MIME"text/plain",::Type{$(esc(typename))})
103-
print(io, "Enum ", $(esc(typename)), ":")
104-
for (sym, i) in $vals
105-
print(io, "\n", sym, " = ", i)
102+
function Base.show(io::IO,t::Type{$(esc(typename))})
103+
if get(io, :multiline, false)
104+
print(io, "Enum ", $(esc(typename)).name.name, ":")
105+
for (sym, i) in $vals
106+
print(io, "\n", sym, " = ", i)
107+
end
108+
else
109+
Base.show_datatype(io, t)
106110
end
107111
end
108112
end

base/REPL.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export
1515
import Base:
1616
Display,
1717
display,
18-
writemime,
18+
show,
1919
AnyDict,
2020
==
2121

@@ -111,7 +111,7 @@ end
111111
function display(d::REPLDisplay, ::MIME"text/plain", x)
112112
io = outstream(d.repl)
113113
Base.have_color && write(io, answer_color(d.repl))
114-
writemime(IOContext(io, multiline=true, limit=true), MIME("text/plain"), x)
114+
show(IOContext(io, multiline=true, limit=true), MIME("text/plain"), x)
115115
println(io)
116116
end
117117
display(d::REPLDisplay, x) = display(d, MIME("text/plain"), x)

base/Terminals.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ import Base:
3131
pipe_reader,
3232
pipe_writer,
3333
read,
34-
readuntil,
35-
writemime
34+
readuntil
3635

3736
## TextTerminal ##
3837

base/datafmt.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module DataFmt
66

7-
import Base: _default_delims, tryparse_internal, writemime
7+
import Base: _default_delims, tryparse_internal, show
88

99
export countlines, readdlm, readcsv, writedlm, writecsv
1010

@@ -623,7 +623,7 @@ end
623623
writedlm(io, a; opts...) = writedlm(io, a, '\t'; opts...)
624624
writecsv(io, a; opts...) = writedlm(io, a, ','; opts...)
625625

626-
writemime(io::IO, ::MIME"text/csv", a) = writedlm(io, a, ',')
627-
writemime(io::IO, ::MIME"text/tab-separated-values", a) = writedlm(io, a, '\t')
626+
show(io::IO, ::MIME"text/csv", a) = writedlm(io, a, ',')
627+
show(io::IO, ::MIME"text/tab-separated-values", a) = writedlm(io, a, '\t')
628628

629629
end # module DataFmt

base/deprecated.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,7 @@ end
12531253

12541254
@deprecate_binding WORD_SIZE Sys.WORD_SIZE
12551255

1256+
@deprecate writemime show
12561257

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

base/docs/helpdb/Base.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6662,28 +6662,32 @@ Return, but do not print, the time elapsed since the last [`tic`](:func:`tic`).
66626662
toq
66636663

66646664
"""
6665-
writemime(stream, mime, x)
6665+
show(stream, mime, x)
66666666
6667-
The `display` functions ultimately call `writemime` in order to write an object `x` as a
6667+
The `display` functions ultimately call `show` in order to write an object `x` as a
66686668
given `mime` type to a given I/O `stream` (usually a memory buffer), if possible. In order
66696669
to provide a rich multimedia representation of a user-defined type `T`, it is only necessary
6670-
to define a new `writemime` method for `T`, via: `writemime(stream, ::MIME"mime", x::T) = ...`,
6670+
to define a new `show` method for `T`, via: `show(stream, ::MIME"mime", x::T) = ...`,
66716671
where `mime` is a MIME-type string and the function body calls `write` (or similar) to write
66726672
that representation of `x` to `stream`. (Note that the `MIME""` notation only supports
66736673
literal strings; to construct `MIME` types in a more flexible manner use
66746674
`MIME{Symbol("")}`.)
66756675
66766676
For example, if you define a `MyImage` type and know how to write it to a PNG file, you
6677-
could define a function `writemime(stream, ::MIME"image/png", x::MyImage) = ...` to allow
6677+
could define a function `show(stream, ::MIME"image/png", x::MyImage) = ...` to allow
66786678
your images to be displayed on any PNG-capable `Display` (such as IJulia). As usual, be sure
6679-
to `import Base.writemime` in order to add new methods to the built-in Julia function
6680-
`writemime`.
6679+
to `import Base.show` in order to add new methods to the built-in Julia function
6680+
`show`.
66816681
66826682
Technically, the `MIME"mime"` macro defines a singleton type for the given `mime` string,
66836683
which allows us to exploit Julia's dispatch mechanisms in determining how to display objects
66846684
of any given type.
6685+
6686+
The default MIME type is `MIME"text/plain"`. There is a fallback definition for `text/plain`
6687+
output that calls `show` with 2 arguments. Therefore, this case should be handled by
6688+
defining a 2-argument `show` method.
66856689
"""
6686-
writemime
6690+
show(stream, mime, x)
66876691

66886692
"""
66896693
mean!(r, v)
@@ -7303,7 +7307,7 @@ Write an informative text representation of a value to the current output stream
73037307
should overload `show(io, x)` where the first argument is a stream. The representation used
73047308
by `show` generally includes Julia-specific formatting and type information.
73057309
"""
7306-
show
7310+
show(x)
73077311

73087312
"""
73097313
@allocated
@@ -7981,8 +7985,8 @@ rethrow
79817985
reprmime(mime, x)
79827986
79837987
Returns an `AbstractString` or `Vector{UInt8}` containing the representation of `x` in the
7984-
requested `mime` type, as written by `writemime` (throwing a `MethodError` if no appropriate
7985-
`writemime` is available). An `AbstractString` is returned for MIME types with textual
7988+
requested `mime` type, as written by `show` (throwing a `MethodError` if no appropriate
7989+
`show` is available). An `AbstractString` is returned for MIME types with textual
79867990
representations (such as `"text/html"` or `"application/postscript"`), whereas binary data
79877991
is returned as `Vector{UInt8}`. (The function `istextmime(mime)` returns whether or not Julia
79887992
treats a given `mime` type as text.)
@@ -8375,7 +8379,7 @@ showall
83758379
83768380
Returns a boolean value indicating whether or not the object `x` can be written as the given
83778381
`mime` type. (By default, this is determined automatically by the existence of the
8378-
corresponding `writemime` function for `typeof(x)`.)
8382+
corresponding `show` function for `typeof(x)`.)
83798383
"""
83808384
mimewritable
83818385

base/docs/utils.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Text / HTML objects
44

5-
import Base: print, writemime
5+
import Base: print, show
66

77
export HTML, @html_str
88

@@ -26,13 +26,13 @@ end
2626
function HTML(xs...)
2727
HTML() do io
2828
for x in xs
29-
writemime(io, MIME"text/html"(), x)
29+
show(io, MIME"text/html"(), x)
3030
end
3131
end
3232
end
3333

34-
writemime(io::IO, ::MIME"text/html", h::HTML) = print(io, h.content)
35-
writemime{F <: Function}(io::IO, ::MIME"text/html", h::HTML{F}) = h.content(io)
34+
show(io::IO, ::MIME"text/html", h::HTML) = print(io, h.content)
35+
show{F <: Function}(io::IO, ::MIME"text/html", h::HTML{F}) = h.content(io)
3636

3737
"""
3838
@html_str -> Docs.HTML
@@ -46,7 +46,7 @@ end
4646
function catdoc(xs::HTML...)
4747
HTML() do io
4848
for x in xs
49-
writemime(io, MIME"text/html"(), x)
49+
show(io, MIME"text/html"(), x)
5050
end
5151
end
5252
end
@@ -70,7 +70,7 @@ end
7070

7171
print(io::IO, t::Text) = print(io, t.content)
7272
print{F <: Function}(io::IO, t::Text{F}) = t.content(io)
73-
writemime(io::IO, ::MIME"text/plain", t::Text) = print(io, t)
73+
show(io::IO, t::Text) = print(io, t)
7474

7575
"""
7676
@text_str -> Docs.Text
@@ -84,7 +84,7 @@ end
8484
function catdoc(xs::Text...)
8585
Text() do io
8686
for x in xs
87-
writemime(io, MIME"text/plain"(), x)
87+
show(io, MIME"text/plain"(), x)
8888
end
8989
end
9090
end

base/exports.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,6 @@ export
12331233
@MIME_str,
12341234
reprmime,
12351235
stringmime,
1236-
writemime,
12371236
mimewritable,
12381237
popdisplay,
12391238
pushdisplay,

base/markdown/IPython/IPython.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function blocktex(stream::IO, md::MD)
2222
end
2323
end
2424

25-
writemime(io::IO, ::MIME"text/plain", tex::LaTeX) =
25+
show(io::IO, tex::LaTeX) =
2626
print(io, '$', tex.formula, '$')
2727

2828
latex(io::IO, tex::LaTeX) =

base/markdown/Markdown.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Markdown
44

5-
import Base: writemime, ==
5+
import Base: show, ==
66
import Core: @doc_str
77

88
include("parse/config.jl")

0 commit comments

Comments
 (0)