@@ -4,13 +4,14 @@ defmodule IEx.Server do
44 @ doc """
55 Eval loop for an IEx session. Its responsibilities include:
66
7+ * loading of .iex files
78 * reading input
89 * trapping exceptions in the code being evaluated
9- * keeping input history
10+ * keeping expression history
1011
1112 """
1213 def start ( config ) do
13- Process . put :iex_history , [ ]
14+ Process . put :iex_history , :queue . new
1415
1516 { _ , _ , scope } = :elixir . eval ( 'require IEx.Helpers' , [ ] , 0 , config . scope )
1617 config = config . scope ( scope )
@@ -135,8 +136,29 @@ defmodule IEx.Server do
135136 end
136137
137138 defp update_history ( config ) do
138- current = Process . get :iex_history
139- Process . put :iex_history , [ config | current ]
139+ limit = IEx.Options . get ( :history_size )
140+ history = Process . get ( :iex_history )
141+ len = :queue . len ( history )
142+ new_history =
143+ :queue . in ( config , history )
144+ |> limit_history ( len + 1 , limit )
145+ Process . put ( :iex_history , new_history )
146+ end
147+
148+ defp limit_history ( _ , _ , 0 ) do
149+ :queue . new
150+ end
151+
152+ defp limit_history ( queue , _ , limit ) when limit < 0 do
153+ queue
154+ end
155+
156+ defp limit_history ( queue , len , limit ) when len > limit do
157+ limit_history ( :queue . drop ( queue ) , len - 1 , limit )
158+ end
159+
160+ defp limit_history ( queue , _ , _ ) do
161+ queue
140162 end
141163
142164 defp io_get ( config ) do
0 commit comments