File tree Expand file tree Collapse file tree 4 files changed +31
-12
lines changed Expand file tree Collapse file tree 4 files changed +31
-12
lines changed Original file line number Diff line number Diff line change @@ -357,7 +357,7 @@ defmodule IEx do
357
357
13
358
358
359
359
It is possible to load another file by configuring the `iex` application's `dot_iex`
360
- value (`config :iex, dot_iex: "PATH"` or `IEx.Config. configure(dot_iex: "PATH")`)
360
+ value (`config :iex, dot_iex: "PATH"` or `IEx.configure(dot_iex: "PATH")`)
361
361
or supplying the `--dot-iex` option to IEx. See `iex --help`.
362
362
363
363
In case of remote nodes, the location of the `.iex.exs` files are taken
@@ -488,6 +488,9 @@ defmodule IEx do
488
488
* `:alive_continuation_prompt` - used when `Node.alive?/0` returns
489
489
`true` and more input is expected
490
490
491
+ * `:auto_reload` - when set to `true`, automatically purges in-memory
492
+ modules when they get invalidated by a concurrent compilation
493
+
491
494
The following values in the prompt string will be replaced appropriately:
492
495
493
496
* `%counter` - the index of the history
Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ defmodule IEx.Config do
14
14
:alive_continuation_prompt ,
15
15
:width ,
16
16
:parser ,
17
- :dot_iex
17
+ :dot_iex ,
18
+ :auto_reload
18
19
]
19
20
20
21
# Read API
@@ -93,6 +94,10 @@ defmodule IEx.Config do
93
94
Application . get_env ( :iex , :dot_iex )
94
95
end
95
96
97
+ def auto_reload? ( ) do
98
+ Application . fetch_env! ( :iex , :auto_reload )
99
+ end
100
+
96
101
# Used by default on evaluation cycle
97
102
defp default_color ( :eval_interrupt ) , do: [ :yellow ]
98
103
defp default_color ( :eval_result ) , do: [ :yellow ]
@@ -199,6 +204,7 @@ defmodule IEx.Config do
199
204
defp validate_option ( { :width , new } ) when is_integer ( new ) , do: :ok
200
205
defp validate_option ( { :parser , tuple } ) when tuple_size ( tuple ) == 3 , do: :ok
201
206
defp validate_option ( { :dot_iex , path } ) when is_binary ( path ) , do: :ok
207
+ defp validate_option ( { :auto_reload , enabled } ) when is_boolean ( enabled ) , do: :ok
202
208
203
209
defp validate_option ( option ) do
204
210
raise ArgumentError , "invalid configuration #{ inspect ( option ) } "
Original file line number Diff line number Diff line change @@ -25,13 +25,8 @@ defmodule IEx.MixListener do
25
25
26
26
@ impl true
27
27
def handle_call ( :purge , _from , state ) do
28
- for module <- state . to_purge do
29
- :code . purge ( module )
30
- :code . delete ( module )
31
- end
32
-
28
+ purge_modules ( state . to_purge )
33
29
status = if Enum . empty? ( state . to_purge ) , do: :noop , else: :ok
34
-
35
30
{ :reply , status , % { state | to_purge: MapSet . new ( ) } }
36
31
end
37
32
@@ -43,13 +38,27 @@ defmodule IEx.MixListener do
43
38
{ :noreply , state }
44
39
else
45
40
% { changed: changed , removed: removed } = info . modules_diff
46
- state = update_in ( state . to_purge , & Enum . into ( changed , & 1 ) )
47
- state = update_in ( state . to_purge , & Enum . into ( removed , & 1 ) )
48
- { :noreply , state }
41
+
42
+ if IEx.Config . auto_reload? ( ) do
43
+ purge_modules ( changed )
44
+ purge_modules ( removed )
45
+ { :noreply , state }
46
+ else
47
+ state = update_in ( state . to_purge , & Enum . into ( changed , & 1 ) )
48
+ state = update_in ( state . to_purge , & Enum . into ( removed , & 1 ) )
49
+ { :noreply , state }
50
+ end
49
51
end
50
52
end
51
53
52
54
def handle_info ( _message , state ) do
53
55
{ :noreply , state }
54
56
end
57
+
58
+ defp purge_modules ( modules ) do
59
+ for module <- modules do
60
+ :code . purge ( module )
61
+ :code . delete ( module )
62
+ end
63
+ end
55
64
end
Original file line number Diff line number Diff line change @@ -18,7 +18,8 @@ defmodule IEx.MixProject do
18
18
inspect: [ pretty: true ] ,
19
19
history_size: 20 ,
20
20
default_prompt: "%prefix(%counter)>" ,
21
- alive_prompt: "%prefix(%node)%counter>"
21
+ alive_prompt: "%prefix(%node)%counter>" ,
22
+ auto_reload: false
22
23
]
23
24
]
24
25
end
You can’t perform that action at this time.
0 commit comments