Skip to content

Commit

Permalink
Cleanup after name printing changes (#1613)
Browse files Browse the repository at this point in the history
* Unexport `find_name`

* Change attribute keys to reduce conflicts with `@attr` uses
  • Loading branch information
lgoettgens authored Feb 19, 2024
1 parent b4d4de5 commit 1fd3fe3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/src/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ AbstractAlgebra.@show_name
AbstractAlgebra.get_name
AbstractAlgebra.set_name!
AbstractAlgebra.extra_name
AbstractAlgebra.find_name
AbstractAlgebra.PrettyPrinting.find_name
```

### Indentation and Decapitalization
Expand Down
2 changes: 0 additions & 2 deletions src/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,6 @@ import .PrettyPrinting: Lowercase
import .PrettyPrinting: Indent
import .PrettyPrinting: Dedent

import .PrettyPrinting: find_new_name as find_name # remove once all call-sites use get_name instead

export @enable_all_show_via_expressify

###############################################################################
Expand Down
16 changes: 8 additions & 8 deletions src/PrettyPrinting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1407,22 +1407,22 @@ If `override` is `false`, the name is only set if there is no name already set.
This function errors if `obj` does not support attribute storage.
"""
function set_name!(obj, name::String; override::Bool=true)
override || isnothing(get_attribute(obj, :name)) || return
set_attribute!(obj, :name => name)
override || isnothing(get_attribute(obj, :_name)) || return
set_attribute!(obj, :_name => name)
end

"""
set_name!(obj; override::Bool=true)
Sets the name of the object `obj` to the name of a variable in global (`Main` module) namespace
with value bound to the object `obj`, if such a variable exists (see [`AbstractAlgebra.find_name`](@ref)).
with value bound to the object `obj`, if such a variable exists (see [`AbstractAlgebra.PrettyPrinting.find_name`](@ref)).
This name is used for printing using [`AbstractAlgebra.@show_name`](@ref).
If `override` is `false`, the name is only set if there is no name already set.
This function errors if `obj` does not support attribute storage.
"""
function set_name!(obj; override::Bool=true)
override || isnothing(get_attribute(obj, :name)) || return
override || isnothing(get_attribute(obj, :_name)) || return
sy = find_name(obj)
isnothing(sy) && return
set_name!(obj, string(sy); override=true)
Expand Down Expand Up @@ -1457,7 +1457,7 @@ For this to work in doctests, one should call
function find_name(obj, M=Main; all::Bool=false)
AbstractAlgebra._is_attribute_storing_type(typeof(obj)) || return find_new_name(obj, M; all)

cached_name = get_attribute(obj, :cached_name)
cached_name = get_attribute(obj, :_cached_name)
if !isnothing(cached_name)
cached_name_sy = Symbol(cached_name)
if M === Main && get_current_module() != Main
Expand All @@ -1470,7 +1470,7 @@ function find_name(obj, M=Main; all::Bool=false)
end
end
name = find_new_name(obj, M; all)
set_attribute!(obj, :cached_name => name)
set_attribute!(obj, :_cached_name => name)
return name
end

Expand Down Expand Up @@ -1501,12 +1501,12 @@ end
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:
1. The name set by [`AbstractAlgebra.set_name!`](@ref).
2. The name of a variable in global (`Main` module) namespace with value bound to the object `obj` (see [`AbstractAlgebra.find_name`](@ref)).
2. The name of a variable in global (`Main` module) namespace with value bound to the object `obj` (see [`AbstractAlgebra.PrettyPrinting.find_name`](@ref)).
3. The name returned by [`AbstractAlgebra.extra_name`](@ref).
"""
function get_name(obj)
if AbstractAlgebra._is_attribute_storing_type(typeof(obj))
name = get_attribute(obj, :name)
name = get_attribute(obj, :_name)
isnothing(name) || return name
end

Expand Down

0 comments on commit 1fd3fe3

Please sign in to comment.