diff --git a/src/args.jl b/src/args.jl index 91d4c730..c9473984 100644 --- a/src/args.jl +++ b/src/args.jl @@ -2069,7 +2069,16 @@ end #-------------------------------------------------- ## inspired by Base.@kwdef -macro add_attributes(level, expr) +""" + add_attributes(level, expr, match_table) + +Takes a `struct` definition and recurses into its fields to create keywords by chaining the field names with the structs' name with underscore. +Also creates pluralized and non-underscore aliases for these keywords. +- `level` indicates which group of `plot`, `subplot`, `series`, etc. the keywords belong to. +- `expr` is the struct definition with default values like `Base.@kwdef` +- `match_table` is an expression of the form `:match = (symbols)`, with symbols whose default value should be `:match` +""" +macro add_attributes(level, expr, match_table) expr = macroexpand(__module__, expr) # to expand @static expr isa Expr && expr.head === :struct || error("Invalid usage of @add_attributes") T = expr.args[2] @@ -2086,6 +2095,9 @@ macro add_attributes(level, expr) # e.g. _series_defualts[key] = value exp_key = Symbol(lowercase(string(T)), "_", key) pl_key = makeplural(exp_key) + if QuoteNode(exp_key) in match_table.args[2].args + value = QuoteNode(:match) + end push!( insert_block.args, Expr( diff --git a/src/components.jl b/src/components.jl index b2f3ae5f..31e5702d 100644 --- a/src/components.jl +++ b/src/components.jl @@ -775,7 +775,6 @@ end ### Legend -# TODO: what about :match for the fonts? @add_attributes subplot struct Legend background_color = :match foreground_color = :match @@ -784,4 +783,4 @@ end font::Font = font(8) title_font::Font = font(11) column = 1 -end +end :match = (:legend_font_family, :legend_font_color, :legend_title_font_family, :legend_title_font_color)