From 6bc24cdb451c304e19cc540ca63f634f94c32e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Mon, 5 Feb 2024 11:57:28 +0100 Subject: [PATCH] Use a `Ref` --- src/PrettyPrinting.jl | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/PrettyPrinting.jl b/src/PrettyPrinting.jl index 516b08bb23..23d908619a 100644 --- a/src/PrettyPrinting.jl +++ b/src/PrettyPrinting.jl @@ -1386,11 +1386,7 @@ end # ################################################################################ -@static if VERSION < v"1.8.0-DEV.1465" - ALLOW_UNICODE_OVERRIDE_VALUE = nothing -else - ALLOW_UNICODE_OVERRIDE_VALUE::Union{Bool,Nothing} = nothing -end +const ALLOW_UNICODE_OVERRIDE_VALUE = Ref{Union{Bool,Nothing}}(nothing) @doc """ allow_unicode(allowed::Bool; temporary::Bool=false) -> Bool @@ -1408,12 +1404,12 @@ function allow_unicode(allowed::Bool; temporary::Bool=false) global ALLOW_UNICODE_OVERRIDE_VALUE if temporary old_allowed = is_unicode_allowed() - ALLOW_UNICODE_OVERRIDE_VALUE = allowed + ALLOW_UNICODE_OVERRIDE_VALUE[] = allowed return old_allowed else old_allowed = is_unicode_allowed() @set_preferences!("unicode" => allowed) - ALLOW_UNICODE_OVERRIDE_VALUE = nothing + ALLOW_UNICODE_OVERRIDE_VALUE[] = nothing return old_allowed end end @@ -1425,7 +1421,7 @@ Return whether unicode characters are allowed in pretty printing. """ function is_unicode_allowed() global ALLOW_UNICODE_OVERRIDE_VALUE - override = ALLOW_UNICODE_OVERRIDE_VALUE + override = ALLOW_UNICODE_OVERRIDE_VALUE[] !isnothing(override) && return override return @load_preference("unicode", default = false)::Bool end @@ -1446,13 +1442,13 @@ end """ function with_unicode(f::Function, allowed::Bool=true) global ALLOW_UNICODE_OVERRIDE_VALUE - previous = ALLOW_UNICODE_OVERRIDE_VALUE - ALLOW_UNICODE_OVERRIDE_VALUE = allowed + previous = ALLOW_UNICODE_OVERRIDE_VALUE[] + ALLOW_UNICODE_OVERRIDE_VALUE[] = allowed try f() finally - @assert ALLOW_UNICODE_OVERRIDE_VALUE == allowed - ALLOW_UNICODE_OVERRIDE_VALUE = previous + @assert ALLOW_UNICODE_OVERRIDE_VALUE[] == allowed + ALLOW_UNICODE_OVERRIDE_VALUE[] = previous end end