@@ -49,7 +49,7 @@ local env = setmetatable({
4949
5050--- Lua command history.
5151-- It has a numeric `pos` field that indicates where in the history the user currently is.
52- M . history = {pos = 0 }
52+ local history = {pos = 0 }
5353
5454--- Evaluates as Lua code the current line or the text on the currently selected lines.
5555-- If the current line has a syntax error, it is ignored and treated as a line continuation.
@@ -91,8 +91,8 @@ function M.evaluate_repl()
9191 buffer :add_text (tostring (result ):gsub (' (\r ?\n )' , ' %1--> ' ))
9292 buffer :new_line ()
9393 end
94- M . history [# M . history + 1 ] = code
95- M . history .pos = # M . history + 1
94+ history [# history + 1 ] = code
95+ history .pos = # history + 1
9696 buffer :set_save_point ()
9797end
9898
@@ -125,29 +125,32 @@ end
125125--- Cycle backward through command history, taking into account commands with multiple lines.
126126function M .cycle_history_prev ()
127127 if buffer :auto_c_active () then return false end -- propagate
128- if M . history .pos <= 1 then return end
129- for _ in (M . history [M . history .pos ] or ' ' ):gmatch (' \n ' ) do
128+ if history .pos <= 1 then return end
129+ for _ in (history [history .pos ] or ' ' ):gmatch (' \n ' ) do
130130 buffer :line_delete ()
131131 buffer :delete_back ()
132132 end
133133 buffer :line_delete ()
134- M . history .pos = math.max (M . history .pos - 1 , 1 )
135- buffer :add_text (M . history [M . history .pos ])
134+ history .pos = math.max (history .pos - 1 , 1 )
135+ buffer :add_text (history [history .pos ])
136136end
137137
138138--- Cycle forward through command history, taking into account commands with multiple lines.
139139function M .cycle_history_next ()
140140 if buffer :auto_c_active () then return false end -- propagate
141- if M . history .pos >= # M . history then return end
142- for _ in (M . history [M . history .pos ] or ' ' ):gmatch (' \n ' ) do
141+ if history .pos >= # history then return end
142+ for _ in (history [history .pos ] or ' ' ):gmatch (' \n ' ) do
143143 buffer :line_delete ()
144144 buffer :delete_back ()
145145 end
146146 buffer :line_delete ()
147- M . history .pos = math.min (M . history .pos + 1 , # M . history )
148- buffer :add_text (M . history [M . history .pos ])
147+ history .pos = math.min (history .pos + 1 , # history )
148+ buffer :add_text (history [history .pos ])
149149end
150150
151+ --- Clears the command history.
152+ function M .clear_history () history = {pos = 0 } end
153+
151154--- Table of key bindings for the REPL.
152155-- @field keys
153156
0 commit comments