Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.0 KiB

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