1- defrecord IEx.Config , binding: nil , cache: '' , counter: 1 , scope: nil , result: nil
1+ defrecord IEx.Config , binding: nil , cache: '' , counter: 1 , scope: nil ,
2+ result: nil , dot_iex_path: nil
23
34defmodule IEx do
45 @moduledoc % B """
56 Welcome to IEx.
67
7- This module is the main entry point Interactive Elixir and
8+ This module is the main entry point for Interactive Elixir and
89 in this documentation we will talk a bit about how IEx works.
910
1011 Notice some of the functionality described here will be available
@@ -20,11 +21,11 @@ defmodule IEx do
2021
2122 ## The User Switch command
2223
23- Besides the break command, one can type Ctrl+G to get the to
24- the user switch command. When reached, you can type `h` to
24+ Besides the break command, one can type Ctrl+G to get to the
25+ user switch command menu . When reached, you can type `h` to
2526 get more information.
2627
27- In this switch , developers are able to create new shell and
28+ In this menu , developers are able to start new shells and
2829 alternate in between them. Let's give it a try:
2930
3031 User switch command
@@ -36,7 +37,7 @@ defmodule IEx do
3637
3738 hello = :world
3839
39- Now, let's rollback to the first shell:
40+ Now, let's roll back to the first shell:
4041
4142 User switch command
4243 --> c 1
@@ -46,23 +47,57 @@ defmodule IEx do
4647 hello
4748 ** (UndefinedFunctionError) undefined function: IEx.Helpers.hello/0
4849
49- The command above fails because we have changed the shells
50- and they are isolated from each other, you can access the
51- variables defined in one in the other.
50+ The command above fails because we have switched the shells.
51+ Since shells are isolated from each other, you can't access the
52+ variables defined in one shell from the other one .
5253
53- The User Switch also allow developers to connect to remote
54- shells using r . Keep in mind that you can't connect to a
54+ The user switch command menu also allows developers to connect to remote
55+ shells using the "r" command . Keep in mind that you can't connect to a
5556 remote node if you haven't given a name to the current node
5657 (i.e. Process.is_alive? must return true).
5758
59+ ## The .iex file
60+
61+ When starting IEx, it will look for a local .iex file (located in the current
62+ working directory), then a global one (located at ~/.iex) and will load the
63+ first one it finds (if any). The code in the chosen .iex file will be
64+ evaluated in the shell's context. So, for instance, any modules that are
65+ loaded or variables that are bound in the .iex file will be available in the
66+ shell after it has booted.
67+
68+ Sample contents of a local .iex file:
69+
70+ # source another .iex file
71+ import_file "~/.iex"
72+
73+ # print something before the shell starts
74+ IO.puts "hello world"
75+
76+ # bind a variable that'll be accessible in the shell
77+ value = 13
78+
79+ Running the shell in the directory where the above .iex file is located
80+ results in
81+
82+ $ iex
83+ Erlang R15B03 (erts-5.9.3.1) [...]
84+
85+ hello world
86+ Interactive Elixir (0.8.3.dev) - press Ctrl+C to exit (type h() ENTER for help)
87+ iex(1)> value
88+ 13
89+
90+ It is possible to override the default loading sequence for .iex file by
91+ supplying the --dot-iex option to iex. See `iex --help`.
92+
5893 ## Expressions in IEx
5994
6095 As an interactive shell, IEx evalutes expressions. This has some
61- interesting consequences worthy discussing.
96+ interesting consequences that are worth discussing.
6297
6398 The first one is that the code is truly evaluated and not compiled.
64- This means that, any benchmarking done in the shell is going to have
65- skewed results. So never run any profiling nor benchmark in the shell.
99+ This means that any benchmarking done in the shell is going to have
100+ skewed results. So never run any profiling nor benchmarks in the shell.
66101
67102 Second of all, IEx alows you to break an expression into many lines,
68103 since this is common in Elixir. For example:
@@ -173,7 +208,8 @@ defmodule IEx do
173208
174209 IEx.Config[
175210 binding: opts[:binding] || [],
176- scope: scope
211+ scope: scope,
212+ dot_iex_path: Keyword.get(opts, :dot_iex_path),
177213 ]
178214 end
179215
0 commit comments