diff --git a/src/Plots.jl b/src/Plots.jl index ff85c65f..5b8383ab 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -144,8 +144,8 @@ export arcdiagram, chorddiagram, - @kw, - @recipe, + # @kw, + @plotrecipe, translate, translate!, diff --git a/src/recipes.jl b/src/recipes.jl index 6bc34b1a..609ed641 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -32,8 +32,18 @@ macro kw(k, v) esc(:(get!(d, $k, $v))) end -macro recipe(args...) - expr = args[end] +macro plotrecipe(args, expr) + if !isa(args, Expr) + error("The first argument to `@plotrecipe` should be a valid argument list for dispatch.") + end + + # wrap the args in a tuple + if args.head != :tuple + args = Expr(:tuple, args) + end + + # replace all the key => value lines with argument setting logic + # TODO: when this is moved out of Plots, also move the replacement of key aliases to just after the _apply_recipe calls for (i,e) in enumerate(expr.args) if isa(e,Expr) && e.head == :(=>) k, v = e.args[1:2] @@ -41,19 +51,19 @@ macro recipe(args...) end end - e = esc(quote - function Plots._apply_recipe(d::KW, $(args[1:end-1]...); kw...) - $expr + # now build a function definition for _apply_recipe, wrapping the return value in a tuple if needed + esc(quote + function Plots._apply_recipe(d::KW, $(args.args...); kw...) + ret = $expr + if typeof(ret) <: Tuple + ret + else + (ret,) + end end end) - # @show e - # dump(e,10) - e end -# macro force_kw(k, v) -# esc(:(d[$k] = $v)) -# end # ---------------------------------------------------------------------------