@@ -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 result != [ ] do
198
+ :ok
199
+ else
200
+ :not_found
201
+ end
175
202
end
176
203
177
204
def h ( _ , _ ) do
@@ -235,7 +262,7 @@ defmodule IEx.Helpers do
235
262
end
236
263
237
264
@ doc """
238
- Prints all types for the given module or prints out a specified type's
265
+ Prints all types for the given module or prints out a specified type's
239
266
specification
240
267
241
268
## Examples
@@ -265,7 +292,7 @@ defmodule IEx.Helpers do
265
292
266
293
@ doc false
267
294
def t ( module , type ) when is_atom ( type ) do
268
- types = lc { _ , { t , _ , _args } } = typespec inlist Kernel.Typespec . beam_types ( module ) ,
295
+ types = lc { _ , { t , _ , _args } } = typespec inlist Kernel.Typespec . beam_types ( module ) ,
269
296
t == type do
270
297
print_type ( typespec )
271
298
typespec
@@ -290,7 +317,7 @@ defmodule IEx.Helpers do
290
317
291
318
@ doc false
292
319
def t ( module , type , arity ) do
293
- types = lc { _ , { t , _ , args } } = typespec inlist Kernel.Typespec . beam_types ( module ) ,
320
+ types = lc { _ , { t , _ , args } } = typespec inlist Kernel.Typespec . beam_types ( module ) ,
294
321
length ( args ) == arity and t == type , do: typespec
295
322
296
323
case types do
@@ -336,7 +363,7 @@ defmodule IEx.Helpers do
336
363
defmacro s ( { :/ , _ , [ { fun , _ , args } , arity ] } ) when args == [ ] or is_atom ( args ) do
337
364
quote do
338
365
s ( Kernel , unquote ( fun ) , unquote ( arity ) )
339
- end
366
+ end
340
367
end
341
368
342
369
defmacro s ( module ) do
@@ -461,7 +488,7 @@ defmodule IEx.Helpers do
461
488
flush
462
489
after
463
490
0 -> :ok
464
- end
491
+ end
465
492
end
466
493
467
494
defp iex_reloaded do
0 commit comments