Skip to content

Commit 2c17007

Browse files
author
José Valim
committed
Merge pull request #2749 from alco/macro-env-doc
Document how to obtain a custom instance of Macro.Env
2 parents 8c8f6d8 + 2770c32 commit 2c17007

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/elixir/lib/macro/env.ex

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@ defmodule Macro.Env do
44
55
The current environment can be accessed at any time as
66
`__ENV__`. Inside macros, the caller environment can be
7-
accessed as `__CALLER__`. It contains the following fields:
7+
accessed as `__CALLER__`.
8+
9+
An instance of `Macro.Env` must not be modified by hand. If you need to
10+
create a custom environment to pass to `Code.eval_quoted/3`, use the
11+
following trick:
12+
13+
def make_custom_env do
14+
import SomeModule, only: [some_function: 2]
15+
alias A.B.C
16+
__ENV__
17+
end
18+
19+
You may then call `make_custom_env()` to get a struct with the desired
20+
imports and aliases included.
21+
22+
It contains the following fields:
823
924
* `module` - the current module name
1025
* `file` - the current file name as a binary

0 commit comments

Comments
 (0)