@@ -123,8 +123,17 @@ defmodule IEx.Helpers do
123
123
124
124
defmacro h ( { name , _ , args } ) when args == [ ] or is_atom ( args ) do
125
125
quote do
126
- h ( unquote ( __MODULE__ ) , unquote ( name ) )
127
- h ( Kernel , unquote ( name ) )
126
+ candidates = [ unquote ( __MODULE__ ) , Kernel , Kernel.SpecialForms ]
127
+
128
+ # If we got at least one :ok, final result will be :ok
129
+ Enum . reduce candidates , :not_found , fn ( mod , flag ) ->
130
+ ret = h ( mod , unquote ( name ) )
131
+ if flag == :ok do
132
+ :ok
133
+ else
134
+ ret
135
+ end
136
+ end
128
137
end
129
138
end
130
139
@@ -134,17 +143,31 @@ defmodule IEx.Helpers do
134
143
end
135
144
end
136
145
146
+ defmacrop mfa_exported? ( module , function , arity ) do
147
+ quote do
148
+ function_exported? ( unquote ( module ) , unquote ( function ) , unquote ( arity ) ) or
149
+ macro_exported? ( unquote ( module ) , unquote ( function ) , unquote ( arity ) )
150
+ end
151
+ end
152
+
153
+ defp h_kernel ( function , arity ) do
154
+ if mfa_exported? ( Kernel , function , arity ) do
155
+ h ( Kernel , function , arity )
156
+ else
157
+ h ( Kernel.SpecialForms , function , arity )
158
+ end
159
+ end
160
+
137
161
@ doc false
138
162
def h ( :h , 1 ) do
139
163
h ( __MODULE__ , :h , 1 )
140
164
end
141
165
142
166
def h ( function , arity ) when is_atom ( function ) and is_integer ( arity ) do
143
- if function_exported? ( __MODULE__ , function , arity ) or
144
- macro_exported? ( __MODULE__ , function , arity ) do
167
+ if mfa_exported? ( __MODULE__ , function , arity ) do
145
168
h ( __MODULE__ , function , arity )
146
169
else
147
- h ( Kernel , function , arity )
170
+ h_kernel ( function , arity )
148
171
end
149
172
end
150
173
@@ -166,12 +189,16 @@ defmodule IEx.Helpers do
166
189
end
167
190
168
191
def h ( module , function ) when is_atom ( module ) and is_atom ( function ) do
169
- lc { { f , arity } , _line , _type , _args , doc } in list module . __info__ ( :docs ) ,
192
+ result = lc { { f , arity } , _line , _type , _args , doc } in list module . __info__ ( :docs ) ,
170
193
f == function and doc != false do
171
194
h ( module , function , arity )
172
195
IO . puts ""
173
196
end
174
- :ok
197
+ if length ( result ) > 0 do
198
+ :ok
199
+ else
200
+ :not_found
201
+ end
175
202
end
176
203
177
204
def h ( _ , _ ) do
0 commit comments