11-- Copyright 2014-2023 Mitchell. See LICENSE.
22
3- --[[ This comment is for LuaDoc
43---
54-- A Textadept module for loading an interactive Lua REPL using the editor's Lua State, similar
65-- to Lua's interactive REPL.
1716-- to evaluate and type Enter to evaluate the entire chunk.
1817--
1918-- Lines may be optionally prefixed with '=' (similar to the Lua prompt) to print a result.
20- module('lua_repl')]]
21-
19+ -- @module lua_repl
2220local M = {}
2321
2422-- Localizations.
@@ -43,14 +41,11 @@ local env = setmetatable({
4341---
4442-- Lua command history.
4543-- It has a numeric `pos` field that indicates where in the history the user currently is.
46- -- @class table
47- -- @name history
4844M .history = {pos = 0 }
4945
5046---
5147-- Evaluates as Lua code the current line or the text on the currently selected lines.
5248-- If the current line has a syntax error, it is ignored and treated as a line continuation.
53- -- @name evaluate_repl
5449function M .evaluate_repl ()
5550 local s , e = buffer .selection_start , buffer .selection_end
5651 local code , last_line
@@ -94,9 +89,7 @@ function M.evaluate_repl()
9489 buffer :set_save_point ()
9590end
9691
97- ---
98- -- Shows a set of Lua code completions for the current position.
99- -- @name complete_lua
92+ --- Shows a set of Lua code completions for the current position.
10093function M .complete_lua ()
10194 local line , pos = buffer :get_cur_line ()
10295 local symbol , op , part = line :sub (1 , pos - 1 ):match (' ([%w_.]-)([%.:]?)([%w_]*)$' )
@@ -125,9 +118,7 @@ function M.complete_lua()
125118 buffer :auto_c_show (# part - 1 , table.concat (cmpls , string.char (buffer .auto_c_separator )))
126119end
127120
128- ---
129- -- Cycle backward through command history, taking into account commands with multiple lines.
130- -- @name cycle_history_prev
121+ --- Cycle backward through command history, taking into account commands with multiple lines.
131122function M .cycle_history_prev ()
132123 if buffer :auto_c_active () then
133124 buffer :line_up ()
@@ -143,9 +134,7 @@ function M.cycle_history_prev()
143134 buffer :add_text (M .history [M .history .pos ])
144135end
145136
146- ---
147- -- Cycle forward through command history, taking into account commands with multiple lines.
148- -- @name cycle_history_next
137+ --- Cycle forward through command history, taking into account commands with multiple lines.
149138function M .cycle_history_next ()
150139 if buffer :auto_c_active () then
151140 buffer :line_down ()
@@ -161,20 +150,16 @@ function M.cycle_history_next()
161150 buffer :add_text (M .history [M .history .pos ])
162151end
163152
164- -- LuaFormatter off
165- ---
166- -- Table of key bindings for the REPL.
167- -- @class table
168- -- @name keys
153+ --- Table of key bindings for the REPL.
154+ M .keys = {} -- empty declaration to avoid LDoc processing
169155M .keys = {
170- [' \n ' ] = M .evaluate_repl ,
171- [' ctrl+ ' ] = M .complete_lua ,
172- [' ctrl+up' ] = M .cycle_history_prev ,
173- [' ctrl+down' ] = M .cycle_history_next ,
174- [' ctrl+p' ] = M .cycle_history_prev ,
156+ [' \n ' ] = M .evaluate_repl , --
157+ [' ctrl+ ' ] = M .complete_lua , --
158+ [' ctrl+up' ] = M .cycle_history_prev , --
159+ [' ctrl+down' ] = M .cycle_history_next , --
160+ [' ctrl+p' ] = M .cycle_history_prev , --
175161 [' ctrl+n' ] = M .cycle_history_next
176162}
177- -- LuaFormatter on
178163
179164-- Cannot initially define keys in `keys.lua` because that table does not exist yet and will
180165-- be overwritten by the Lua language module. Instead, define keys here.
0 commit comments