Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Co-authored-by: Max Horn <max@quendi.de>
  • Loading branch information
lgoettgens and fingolfin committed Feb 5, 2024
1 parent 8d5ec4c commit 44ed594
Showing 1 changed file with 26 additions and 31 deletions.
57 changes: 26 additions & 31 deletions src/PrettyPrinting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1429,15 +1429,15 @@ function set_name!(obj; override::Bool=true)
end

"""
extra_name(obj) = nothing
extra_name(obj) -> Union{String,Nothing}
May be overloaded to provide a fallback name for the object `obj` in [`AbstractAlgebra.get_name`](@ref).
This function is expected to return a string or `nothing`.
The default implementation returns `nothing`.
"""
extra_name(obj) = nothing

Check warning on line 1437 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1437

Added line #L1437 was not covered by tests

"""
find_name(obj, M = Main; all::Bool = false)
find_name(obj, M = Main; all::Bool = false) -> Union{String,Nothing}
Return name of a variable in `M`'s namespace with value bound to the object `obj`,
or `nothing` if no such variable exists.
Expand Down Expand Up @@ -1474,7 +1474,7 @@ function find_name(obj, M=Main; all::Bool=false)
end

"""
get_name(obj)
get_name(obj) -> Union{String,Nothing}
Returns the name of the object `obj` if it is set, or `nothing` otherwise.
This function tries to find a name in the following order:
Expand All @@ -1483,33 +1483,28 @@ This function tries to find a name in the following order:
3. The name returned by [`AbstractAlgebra.extra_name`](@ref).
"""
function get_name(obj)
name = nothing
if AbstractAlgebra._is_attribute_storing_type(typeof(obj))
name = get_attribute(obj, :name)
name = get_attribute(obj, :name)
isnothing(name) || return name

Check warning on line 1488 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1485-L1488

Added lines #L1485 - L1488 were not covered by tests
end
if isnothing(name)
sy = find_name(obj)
if !isnothing(sy)
name = string(sy)
end
end
if isnothing(name)
name_maybe = extra_name(obj)::Union{String,Nothing}
if !isnothing(name_maybe)
name = name_maybe
end
end
return name

sy = find_name(obj)
isnothing(sy) || return string(sy)

Check warning on line 1492 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1491-L1492

Added lines #L1491 - L1492 were not covered by tests

name_maybe = extra_name(obj)::Union{String,Nothing}
isnothing(name_maybe) || return name_maybe

Check warning on line 1495 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1494-L1495

Added lines #L1494 - L1495 were not covered by tests

return nothing

Check warning on line 1497 in src/PrettyPrinting.jl

View check run for this annotation

Codecov / codecov/patch

src/PrettyPrinting.jl#L1497

Added line #L1497 was not covered by tests
end

"""
@show_name(io, obj)
@show_name(io::IO, obj)
If compact or supercompact printing is enabled,
prints the name [`get_name(obj)`](@ref AbstractAlgebra.get_name) of the object `obj` to the `io` stream.
If either property `:compact` or `:supercompact` is set to `true` for `io` (see [`IOContext`](@ref)),
print the name [`get_name(obj)`](@ref AbstractAlgebra.get_name) of the object `obj` to the `io` stream.
This macro either prints the name and returns from the current scope, or does nothing.
It is expected to be used in the `show` method of a type shown in the documentation.
It is supposed to be used at the start of `show` methods as shown in the documentation.
```
"""
macro show_name(io, obj)
Expand All @@ -1532,12 +1527,12 @@ macro show_name(io, obj)
end

"""
@show_special(io, obj)
@show_special(io::IO, obj)
If the `obj` has a `show` attribute, this gets called with `io` and `obj` and
returns from the current scope. Otherwise, does nothing.
It is expected to be used in the `show` method of a type shown in the documentation.
It is supposed to be used at the start of `show` methods as shown in the documentation.
"""
macro show_special(io, obj)
return :(
Expand All @@ -1554,12 +1549,12 @@ macro show_special(io, obj)
end

"""
@show_special(io, mime, obj)
@show_special(io::IO, mime, obj)
If the `obj` has a `show` attribute, this gets called with `io`, `mime` and `obj` and
returns from the current scope. Otherwise, does nothing.
It is expected to be used in the `show` method of a type shown in the documentation.
It is supposed to be used at the start of `show` methods as shown in the documentation.
"""
macro show_special(io, mime, obj)
return :(
Expand All @@ -1577,12 +1572,12 @@ macro show_special(io, mime, obj)
end

"""
@show_special(io, obj)
@show_special_elem(io::IO, obj)
If the `parent` of `obj` has a `show_special_elem` attribute, this gets called with `io` and `obj` and
returns from the current scope. Otherwise, does nothing.
It is expected to be used in the `show` method of a type shown in the documentation.
It is supposed to be used at the start of `show` methods as shown in the documentation.
"""
macro show_special_elem(io, obj)
return :(
Expand All @@ -1600,12 +1595,12 @@ macro show_special_elem(io, obj)
end

"""
@show_special(io, mime, obj)
@show_special_elem(io::IO, mime, obj)
If the `parent` of `obj` has a `show` attribute, this gets called with `io`, `mime` and `obj` and
returns from the current scope. Otherwise, does nothing.
It is expected to be used in the `show` method of a type shown in the documentation.
It is supposed to be used at the start of `show` methods as shown in the documentation.
"""
macro show_special_elem(io, mime, obj)
return :(
Expand Down

0 comments on commit 44ed594

Please sign in to comment.