diff --git a/base/docs/Docs.jl b/base/docs/Docs.jl index 0057e094f9a6d3..cd07924e2b84d3 100644 --- a/base/docs/Docs.jl +++ b/base/docs/Docs.jl @@ -519,21 +519,30 @@ more than one expression is marked then the same docstring is applied to each ex """ :(Base.@__doc__) -function __doc__!(meta, def::Expr) +function __doc__!(meta, def::Expr, define=true) if isexpr(def, :block, 2) && isexpr(def.args[1], :meta, 1) && def.args[1].args[1] === :doc # Convert `Expr(:block, Expr(:meta, :doc), ...)` created by `@__doc__` to an `@doc`. def.head = :macrocall - def.args = [symbol("@doc"), meta, def.args[end]] - true + def.args = [symbol("@doc"), meta, def.args[end], define] + (true, def) else found = false + ret = Expr(:block) for each in def.args - found |= __doc__!(meta, each) + f, ex = __doc__!(meta, each) + if f + found = true + push!(ret.args, ex) + end + end + if length(ret.args)==1 + return (found, ret.args[1]) + else + return (found, ret) end - found end end -__doc__!(meta, def) = false +__doc__!(meta, def, define=true) = (false, def) # Predicates and helpers for `docm` expression selection: @@ -594,7 +603,7 @@ function docm(meta, ex, define = true) # Errors generated by calling `macroexpand` are passed back to the call site. isexpr(x, :error) ? esc(x) : # When documenting macro-generated code we look for embedded `@__doc__` calls. - __doc__!(meta, x) ? esc(x) : + (temp = __doc__!(meta, x, define); temp[1]) ? esc(define ? x : temp[2]) : # Any "basic" expression such as a bare function or module name or numeric literal. isbasicdoc(x) ? namedoc(meta, nothing, x) :