Skip to content

Commit

Permalink
Better support for documenting expressions with macros. Fix #11993
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Jul 4, 2015
1 parent 1368cae commit 29a8eea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
9 changes: 4 additions & 5 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,21 @@ end
fexpr(ex) = isexpr(ex, :function, :(=)) && isexpr(ex.args[1], :call)

function docm(meta, def)
isexpr(def, :macrocall) && (def = macroexpand(def))
def′ = unblock(def)
isexpr(def′, :macro) && return namedoc(meta, def, symbol("@", namify(def′)))
isexpr(def′, :type, :bitstype) && return typedoc(meta, def, namify(def′.args[2]))
isexpr(def′, :abstract) && return namedoc(meta, def, namify(def′))
isexpr(def′, :module) && return namedoc(meta, def, def′.args[2])
fexpr(def′) && return funcdoc(meta, def)
isexpr(def′, :macrocall) && (def = namify(def′))
return objdoc(meta, def)
end

function docm(ex)
isexpr(ex, :macrocall) && (ex = macroexpand(ex))
isa(ex,Symbol) && haskey(keywords, ex) && return keywords[ex]
isexpr(ex, :->) && return docm(ex.args...)
isexpr(ex, :call) && return :(doc($(esc(ex.args[1])), @which $(esc(ex))))
isexpr(ex, :macrocall) && (ex = namify(ex))
:(doc($(esc(ex))))
end

This comment has been minimized.

Copy link
@MichaelHatherly

MichaelHatherly Jul 4, 2015

Member

docm(ex) is used to retrieve docs from the docsystem – except for the -> case. Using macroexpand here will break macro lookup:

julia> "..."
       macro m(x) end

help?> @m
ERROR: wrong number of arguments

Only the docm(meta, def) needs macro expansion I think.


Expand Down Expand Up @@ -326,7 +326,7 @@ Please see docs for the `@doc` macro for more info.
"""
Docs

"""
@eval @doc """
# Documentation
Functions, methods and types can be documented by placing a string before the
Expand Down Expand Up @@ -363,8 +363,7 @@ Placing documentation before a method definition (e.g. `function foo()
documented, as opposed to the whole function. Method docs are
concatenated together in the order they were defined to provide docs
for the function.
"""
@doc
""" $(symbol("@doc"))

"`doc(obj)`: Get the doc metadata for `obj`."
doc
Expand Down
5 changes: 2 additions & 3 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ keywords[:immutable] = doc"""
See `type` and the manual for more information.
"""

"""
@eval @doc """
Executes an expression, printing the time it took to
execute and the total number of bytes its execution caused to be
allocated. Returns the value of the expression. For example:
Expand All @@ -295,8 +295,7 @@ allocated. Returns the value of the expression. For example:
sleep(1)
2+2
end
"""
@time
""" $(symbol("@time"))

doc"""
Construct a regex, such as `r"^[a-z]*$"`. The regex also accepts
Expand Down

0 comments on commit 29a8eea

Please sign in to comment.