Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Feb 5, 2024
1 parent 8d5ec4c commit 5b3d6a3
Showing 1 changed file with 31 additions and 36 deletions.
67 changes: 31 additions & 36 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

"""
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,36 +1483,31 @@ 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
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)

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

return nothing
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)
macro show_name(io::IO, obj)
return :(
begin
local i = $(esc(io))
Expand All @@ -1532,14 +1527,14 @@ 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)
macro show_special(io::IO, obj)
return :(
begin
local i = $(esc(io))
Expand All @@ -1554,14 +1549,14 @@ 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)
macro show_special(io::IO, mime, obj)
return :(
begin
local i = $(esc(io))
Expand All @@ -1577,14 +1572,14 @@ 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)
macro show_special_elem(io::IO, obj)
return :(
begin
local i = $(esc(io))
Expand All @@ -1600,14 +1595,14 @@ 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)
macro show_special_elem(io::IO, mime, obj)
return :(
begin
local i = $(esc(io))
Expand Down

0 comments on commit 5b3d6a3

Please sign in to comment.