How to get the "automatic documentation text" when documentation has been defined?


I do like the automatically generated documentation like this:

No documentation found.

ThinkWare.idea is a Function.

# 6 methods for generic function "idea":
[1] idea(mx::Mixture) in ThinkWare at C:\Users\Rodin\ThinkWare\src\ideas.jl:66
[2] idea(su::Substance) in ThinkWare at C:\Users\Rodin\ThinkWare\src\ideas.jl:60
[3] idea(su::Substance, T) in ThinkWare at C:\Users\Rodin\ThinkWare\src\ideas.jl:60
[4] idea(su::Substance, T, p) in ThinkWare at C:\Users\Rodin\ThinkWare\src\ideas.jl:60
[5] idea(mx::Mixture, T) in ThinkWare at C:\Users\Rodin\ThinkWare\src\ideas.jl:72
[6] idea(mx::Mixture, T, p) in ThinkWare at C:\Users\Rodin\ThinkWare\src\ideas.jl:72

When I create my own documentation, using Docs.getdoc(…), how can I arrange to automatically append the automatically generated documentation ?
Is there a function returning this automatically generated documentation without caring for existing documentation?



Perhaps METHODLIST or SIGNATURES from DocStringExtensions.jl fits your needs?

However, if you want output more similar to what methods(f) give in the Julia REPL as part of your docstrings you can define your own abbreviation, for example like this:

using DocStringExtensions

struct Methods <: DocStringExtensions.Abbreviation end
const METHODS = Methods()
function DocStringExtensions.format(::Methods, buf, doc)
    binding =[:binding]
    func = Docs.resolve(binding)
    ml = methods(func)
    io = IOBuffer()
    show(io, MIME"text/plain"(), ml)
    el = eachline(seekstart(io))
    x = iterate(el)
    x === nothing && return ""
    io2 = IOBuffer()
    l1, s = x
    # First line is "# N methods for ..."
    println(io2, chop(l1, head=2, tail=0))
    x = iterate(el, s)
    while x !== nothing
        l, s = x
        m = match(r"\[\d+\] (.*)", l)
        println(io2, "  - ", m[1])
        x = iterate(el, s)
    return print(buf, strip(String(take!(io2))))


f(x) = 1
f(x::Int) = 2
f(x::Float64) = 3


Do stuff.


which gives

help?> f
search: f fd for fma fld fld1 fill fdio frexp foldr foldl flush floor float first fill!


  Do stuff

  3 methods for generic function "f":

    •  f(x::Int64) in Main at /Users/fredrik/dev/DocStringExtensions/test.jl:31

    •  f(x::Float64) in Main at /Users/fredrik/dev/DocStringExtensions/test.jl:32

    •  f(x) in Main at /Users/fredrik/dev/DocStringExtensions/test.jl:30
1 Like

Good solution to simply use methods.