1module ESS
2
3# These methods have been deprecated / moved
4macro current_module()
5    return VERSION >= v"0.7-" ? :(@__MODULE__) : :(current_module())
6end
7
8parse = VERSION >= v"0.7-" ? Base.Meta.parse : Base.parse
9function_module = VERSION >= v"0.7-" ? Base.parentmodule : Base.function_module
10
11function all_help_topics()
12    ## There are not clear topics anymore. Approximate those with a very general
13    ## apropos(" ")
14    Base.Docs.apropos(" ")
15end
16
17function help(topic::AbstractString)
18    VERSION >= v"0.4-" ? Core.eval(@current_module(), parse("@doc $topic")) : Base.Help.help(topic)
19end
20
21## modified version of function show(io::IO, m::Method)
22function fun_args(m::Method)
23    tv, decls, file, line = Base.arg_decl_parts(m)
24    io = VERSION >= v"0.7-" ? Base.stdout : STDOUT::IO # STDOUT is no longer in 1.0
25    if !isempty(tv)
26        Base.show_delim_array(io, tv, '{', ',', '}', false)
27    end
28    print(io, "(")
29    join(io, [escape_string(isempty(d[2]) ? d[1] : d[1]*"::"*d[2]) for d in decls],
30         ",", ",")
31    Base.print(io, ")")
32end
33
34## modified versionof show(io::IO, mt::MethodTable)
35function fun_args(f::Function)
36    mt = Base.MethodList(methods(f).mt)
37    mod = function_module(f)   # Base.function_module deprecated in 0.7
38    if mod == Main
39        mod = "nil"
40    end
41    print("(list \"$mod\" nil '(")
42    for d in mt
43        print("\"")
44        ## method
45        fun_args(d)
46        print("\" ")
47    end
48    print("))")
49end
50
51function fun_args(s::AbstractString)
52    try
53        m = Core.eval(@current_module(), parse(s))
54        if ! isa(m, String)
55            fun_args(m)
56        end
57    catch
58        print("(list nil nil nil)")
59    end
60end
61
62function fun_args(t::DataType)
63    print("(list nil nil '(")
64    for d = fieldnames(t)
65        print("\"$d\" ")
66    end
67    print("))")
68end
69
70
71### OBJECT COMPLETION
72# Must print an output of the form:
73#
74# Cache                         Module
75# Write                         Module
76# add                           Function
77# free                          Function
78function components(m::Module)
79    for v in sort(names(m))
80        s = string(v)
81        if isdefined(m,v)
82            println(rpad(s, 30), summary(Core.eval(m,v)))
83        end
84    end
85end
86
87function components(t::DataType)
88    for v in sort(fieldnames(t))
89        println(rpad(string(v), 30), "field")
90    end
91end
92
93function components(v)
94    t = typeof(v)
95    if isa(t, DataType)
96        return components(t)
97    end
98end
99
100
101### MISC
102function main_modules(m::Module)
103    for nm in names(m)
104        if isdefined(m, nm)
105            mod = Core.eval(m, nm)
106            if isa(mod, Module)
107                print("\"$nm\" ")
108            end
109        end
110    end
111end
112
113if VERSION >= v"0.7-"
114    main_modules() = main_modules(Base.parentmodule(@current_module()))
115else
116    main_modules() = main_modules(@current_module())
117end
118
119end
120