Repository: JuliaLang/julia
File: base/show.jl (Julia)

Code before:
# This file is a part of Julia. License is MIT: https://julialang.org/license

using .Compiler: has_typevar

function show(io::IO, ::MIME"text/plain", u::UndefInitializer)
    show(io, u)
    get(io, :compact, false)::Bool && return
    print(io, ": array initializer with undefined values")
end

# first a few multiline show functions for types defined before the MIME type:

show(io::IO, ::MIME"text/plain", r::AbstractRange) = show(io, r) # always use the compact form for printing ranges

function show(io::IO, ::MIME"text/plain", r::UnitRange)
    show(io, first(r))
    print(io, ':')
    show(io, last(r))
    if !(get(io, :compact, false)::Bool) && isempty(r)
        print(io, " (empty range)")
    end
end

function show(io::IO, ::MIME"text/plain", r::LinRange)
    isempty(r) && return show(io, r)
    # show for LinRange, e.g.
    # range(1, stop=3, length=7)
    # 7-element LinRange{Float64}:
    #   1.0,1.33333,1.66667,2.0,2.33333,2.66667,3.0
    summary(io, r)
    println(io, ":")
    print_range(io, r)
end

function show(io::IO, ::MIME"text/plain", r::LogRange)  # display LogRange like LinRange
    isempty(r) && return show(io, r)
    summary(io, r)
    println(io, ":")
    print_range(io, r, " ", ", ", "", " \u2026 ")
end

function _isself(ft::DataType)
    ftname = ft.name

Review comment (performance):
```suggestion
    show(io, r)
```
The implementation here should match the 2-arg implementation (so might as well call the 2-arg method). 

While @nsako's suggestion is reasonable, it shouldn't only be applied to the 3-arg and not the 2-arg method because that would cause inconsistencies like this:

```julia-repl
julia> io = IOContext(stdout, :typeinfo=>Bool);

julia> show(io, MIME("text/plain"), false:true)
0:1
julia> show(io, MIME("text/plain"), false:true:true)
false:true:true
```

I would recommend attempting that performance improvement in a separate pull request due to its semantic impact. Calling `show(io, r)` here means that any performance improvements to `show(io, r)` will also apply here.

Code after:
# This file is a part of Julia. License is MIT: https://julialang.org/license

using .Compiler: has_typevar

function show(io::IO, ::MIME"text/plain", u::UndefInitializer)
    show(io, u)
    get(io, :compact, false)::Bool && return
    print(io, ": array initializer with undefined values")
end

# first a few multiline show functions for types defined before the MIME type:

show(io::IO, ::MIME"text/plain", r::AbstractRange) = show(io, r) # always use the compact form for printing ranges

function show(io::IO, ::MIME"text/plain", r::UnitRange)
    show(io, r)
    if !(get(io, :compact, false)::Bool) && isempty(r)
        print(io, " (empty range)")
    end
end

function show(io::IO, ::MIME"text/plain", r::LinRange)
    isempty(r) && return show(io, r)
    # show for LinRange, e.g.
    # range(1, stop=3, length=7)
    # 7-element LinRange{Float64}:
    #   1.0,1.33333,1.66667,2.0,2.33333,2.66667,3.0
    summary(io, r)
    println(io, ":")
    print_range(io, r)
end

function show(io::IO, ::MIME"text/plain", r::LogRange)  # display LogRange like LinRange
    isempty(r) && return show(io, r)
    summary(io, r)
    println(io, ":")
    print_range(io, r, " ", ", ", "", " \u2026 ")
end

function _isself(ft::DataType)
    ftname = ft.name
    isdefined(ftname, :mt) || return false
    name = ftname.mt.name