From 9d470191d5eda30f45f5ae6b072549acbc8f499d Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 22 Jan 2016 14:06:09 -0500 Subject: [PATCH] doc system fix: when using `__doc__` and define==false, extract just the `__doc__` pieces to avoid repeating the rest of the surrounding code (which might include method definitions). --- base/docs/Docs.jl | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/base/docs/Docs.jl b/base/docs/Docs.jl index 0a3cd316177841..04012ac617cc3e 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) && def.args[1] == symbol("#doc#") # Convert `Expr(:block, :#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) :