diff options
Diffstat (limited to 'modules/textadept')
-rw-r--r-- | modules/textadept/command_entry.lua | 2 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 13 | ||||
-rw-r--r-- | modules/textadept/file_types.lua | 8 | ||||
-rw-r--r-- | modules/textadept/find.lua | 5 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 6 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 26 | ||||
-rw-r--r-- | modules/textadept/run.lua | 25 | ||||
-rw-r--r-- | modules/textadept/session.lua | 29 | ||||
-rw-r--r-- | modules/textadept/snippets.lua | 10 |
9 files changed, 64 insertions, 60 deletions
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index 820ad751..7224b216 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -105,7 +105,7 @@ end -- @class table -- @name env local env = setmetatable({}, { - __index = function(t, k) + __index = function(_, k) local f = buffer[k] if f and type(f) == 'function' then f = function(...) return buffer[k](buffer, ...) end diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 241e3816..d19f34fc 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -70,7 +70,7 @@ events.connect(events.VIEW_NEW, function() if type(name) == 'string' then buffer:register_image(i, M.XPM_IMAGES[i]) end end end) -for i = 1, #M.XPM_IMAGES do _SCINTILLA.next_image_type() end -- sync +for _ = 1, #M.XPM_IMAGES do _SCINTILLA.next_image_type() end -- sync --- -- Map of lexer names to line comment strings for programming languages, used by @@ -444,7 +444,7 @@ function M.convert_indentation() local s = buffer:position_from_line(line) local indent = buffer.line_indentation[line] local e = buffer.line_indent_position[line] - current_indentation = buffer:text_range(s, e) + local current_indentation, new_indentation = buffer:text_range(s, e), nil if buffer.use_tabs then -- Need integer division and LuaJIT does not have // operator. new_indentation = ('\t'):rep(math.floor(indent / buffer.tab_width)) @@ -572,10 +572,11 @@ M.autocompleters.word = function() for i = 1, #_BUFFERS do if _BUFFERS[i] == buffer or M.AUTOCOMPLETE_ALL then local text = _BUFFERS[i]:get_text() - for i, word in text:gmatch(word_patt) do + for match_pos, match in text:gmatch(word_patt) do -- Frontier pattern (%f) is too slow, so check prior char after a match. - if (i == 1 or text:find(nonword_char, i - 1)) and not list[word] then - list[#list + 1], list[word] = word, true + if (match_pos == 1 or text:find(nonword_char, match_pos - 1)) and + not list[match] then + list[#list + 1], list[match] = match, true end end end @@ -588,8 +589,8 @@ local api_docs --- -- Displays a call tip with documentation for the symbol under or directly -- behind the caret. +-- Documentation is read from API files in the `api_files` table. -- If a call tip is already shown, cycles to the next one if it exists. --- Documentation is stored in API files in the `api_files` table. -- Symbols are determined by using `buffer.word_chars`. -- @name show_documentation -- @see api_files diff --git a/modules/textadept/file_types.lua b/modules/textadept/file_types.lua index 445cb37f..4f12bc35 100644 --- a/modules/textadept/file_types.lua +++ b/modules/textadept/file_types.lua @@ -19,7 +19,7 @@ events.LEXER_LOADED = 'lexer_loaded' --- -- Map of file extensions to their associated lexer names. --- If the file type is not recognized by its first-line, each file extension is +-- If the file type is not recognized by its first-line, each file extension is -- matched against the file's extension. -- @class table -- @name extensions @@ -82,7 +82,7 @@ end events.connect(events.BUFFER_NEW, function() buffer.get_lexer, buffer.set_lexer = get_lexer, set_lexer buffer.style_name = setmetatable({}, { - __index = function(t, style_num) -- LuaDoc is in core/.buffer.luadoc + __index = function(_, style_num) -- LuaDoc is in core/.buffer.luadoc assert(style_num >= 0 and style_num <= 255, '0 <= style_num < 256') return buffer:private_lexer_call(style_num) end, @@ -92,8 +92,8 @@ end, 1) -- Auto-detect lexer on file open or save as. events.connect(events.FILE_OPENED, function() buffer:set_lexer() end) -events.connect(events.FILE_AFTER_SAVE, function(filename, saved_as) - if saved_as then buffer:set_lexer() end +events.connect(events.FILE_AFTER_SAVE, function(_, saved_as) + if saved_as then buffer:set_lexer() end end) -- Restores the buffer's lexer. diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index 35ce74eb..fe75107f 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -270,7 +270,8 @@ local function replace(rtext) rtext = rtext:gsub('%%'..i, (M.captures[i]:gsub('%%', '%%%%'))) end end - local ok, rtext = pcall(string.gsub, rtext, '%%(%b())', function(code) + local ok + ok, rtext = pcall(string.gsub, rtext, '%%(%b())', function(code) code = code:gsub('[\a\b\f\n\r\t\v\\]', escapes) local result = assert(load('return '..code))() return tostring(result):gsub('\\[abfnrtv\\]', escapes) @@ -380,7 +381,7 @@ events.connect(events.KEYPRESS, function(code) return true end end) -events.connect(events.DOUBLE_CLICK, function(pos, line) +events.connect(events.DOUBLE_CLICK, function(_, line) if is_ff_buf(buffer) then M.goto_file_found(line) end end) diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index 09f9bab8..f0add5cd 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -633,17 +633,17 @@ keys.find_incremental = { end } -- Add the character for any key pressed without modifiers to incremental find. -setmetatable(keys.find_incremental, {__index = function(t, k) +setmetatable(keys.find_incremental, {__index = function(_, k) if #k > 1 and k:find('^[cams]*.+$') then return end ui.find.find_incremental(ui.command_entry:get_text()..k, true) end}) -- Show documentation for symbols in the Lua command entry. keys.lua_command[not CURSES and 'ch' or 'mh'] = function() -- Temporarily change _G.buffer since ui.command_entry is the "active" buffer. - local buffer = _G.buffer + local orig_buffer = _G.buffer _G.buffer = ui.command_entry textadept.editing.show_documentation() - _G.buffer = buffer + _G.buffer = orig_buffer end if OSX or CURSES then -- UTF-8 input. diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index ad662194..d3799bb4 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -21,7 +21,7 @@ local SEPARATOR = {''} -- The default main menubar. -- @class table -- @name menubar -local menubar = { +local default_menubar = { { title = _L['_File'], {_L['_New'], buffer.new}, {_L['_Open'], io.open_file}, @@ -210,7 +210,7 @@ local menubar = { -- The default right-click context menu. -- @class table -- @name context_menu -local context_menu = { +local default_context_menu = { {_L['_Undo'], buffer.undo}, {_L['_Redo'], buffer.redo}, SEPARATOR, @@ -226,7 +226,7 @@ local context_menu = { -- The default tabbar context menu. -- @class table -- @name tab_context_menu -local tab_context_menu = { +local default_tab_context_menu = { {_L['_Close'], io.close_buffer}, SEPARATOR, {_L['_Save'], io.save_file}, @@ -238,7 +238,7 @@ local tab_context_menu = { -- Table of proxy tables for menus. local proxies = {} -local key_shortcuts, menu_actions, contextmenu_actions, items, commands +local key_shortcuts, menu_actions, contextmenu_actions -- Returns the GDK integer keycode and modifier mask for a key sequence. -- This is used for creating menu accelerators. @@ -320,6 +320,8 @@ local function build_command_tables(menu, title, items, commands) end end +local items, commands + -- Returns a proxy table for menu table *menu* such that when a menu item is -- changed or added, *update* is called to update the menu in the UI. -- @param menu The menu or table of menus to create a proxy for. @@ -329,15 +331,15 @@ end -- calling *update* with. local function proxy_menu(menu, update, menubar) return setmetatable({}, { - __index = function(t, k) + __index = function(_, k) local v = menu[k] return type(v) == 'table' and proxy_menu(v, update, menubar or menu) or v end, - __newindex = function(t, k, v) + __newindex = function(_, k, v) menu[k] = getmetatable(v) and getmetatable(v).menu or v update(menubar or menu) end, - __len = function(t) return #menu end, + __len = function() return #menu end, menu = menu -- store existing menu for copying (e.g. m[#m + 1] = m[#m]) }) end @@ -363,7 +365,7 @@ local function set_menubar(menubar) build_command_tables(menubar, nil, items, commands) proxies.menubar = proxy_menu(menubar, set_menubar) end -set_menubar(menubar) +set_menubar(default_menubar) -- Sets `ui.context_menu` and `ui.tab_context_menu` from menu item lists -- *buffer_menu* and *tab_menu*, respectively. @@ -380,10 +382,10 @@ set_menubar(menubar) -- @see ui.menu local function set_contextmenus(buffer_menu, tab_menu) contextmenu_actions = {} - local menu = buffer_menu or context_menu + local menu = buffer_menu or default_context_menu ui.context_menu = ui.menu(read_menu_table(menu, true)) proxies.context_menu = proxy_menu(menu, set_contextmenus) - menu = tab_menu or tab_context_menu + menu = tab_menu or default_tab_context_menu ui.tab_context_menu = ui.menu(read_menu_table(menu, true)) proxies.tab_context_menu = proxy_menu(menu, function() set_contextmenus(nil, menu) @@ -413,8 +415,8 @@ events.connect(events.MENU_CLICKED, function(menu_id) end) return setmetatable(M, { - __index = function(t, k) return proxies[k] or M[k] end, - __newindex = function(t, k, v) + __index = function(_, k) return proxies[k] or M[k] end, + __newindex = function(_, k, v) if k == 'menubar' then set_menubar(v) elseif k == 'context_menu' then diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index eb588a2b..dc4a3982 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -53,13 +53,13 @@ events.BUILD_OUTPUT = 'build_output' local preferred_view --- Executes compile, run, or build shell command *command*. +-- Executes a compile, run, or build shell command from *commands*. -- Emits events named *event*. -- @param commands Either `compile_commands`, `run_commands`, or -- `build_commands`. -- @param event Event to emit upon command output. -- @see _G.events -local function command(commands, event) +local function run_command(commands, event) local command, cwd, data if commands ~= M.build_commands then if not buffer.filename then return end @@ -147,9 +147,9 @@ end -- Prints the output from a run or compile shell command. -- If the output is a recognized warning or error message, mark it. --- @param lexer The current lexer. +-- @param _ The current lexer. -- @param output The output to print. -local function print_output(lexer, output) +local function print_output(_, output) ui.print(output) local error = get_error(output) if not error then return end @@ -178,7 +178,7 @@ M.compile_commands = {actionscript='mxmlc "%f"',ada='gnatmake "%f"',ansi_c='gcc -- @see compile_commands -- @see _G.events -- @name compile -function M.compile() command(M.compile_commands, events.COMPILE_OUTPUT) end +function M.compile() run_command(M.compile_commands, events.COMPILE_OUTPUT) end events.connect(events.COMPILE_OUTPUT, print_output) --- @@ -201,7 +201,7 @@ M.run_commands = {actionscript=WIN32 and 'start "" "%e.swf"' or OSX and 'open "f -- @see run_commands -- @see _G.events -- @name run -function M.run() command(M.run_commands, events.RUN_OUTPUT) end +function M.run() run_command(M.run_commands, events.RUN_OUTPUT) end events.connect(events.RUN_OUTPUT, print_output) --- @@ -220,7 +220,7 @@ M.build_commands = {--[[Ant]]['build.xml']='ant',--[[Make]]Makefile='make',GNUma -- @see build_commands -- @see _G.events -- @name build -function M.build() command(M.build_commands, events.BUILD_OUTPUT) end +function M.build() run_command(M.build_commands, events.BUILD_OUTPUT) end events.connect(events.BUILD_OUTPUT, print_output) --- @@ -300,11 +300,12 @@ function M.goto_error(line, next) if not error then if CURSES then view:goto_buffer(cur_buf) end return end textadept.editing.select_line() ui.goto_file(M.cwd..'/'..error.filename, true, preferred_view, true) - local line, message = error.line, error.message - buffer:goto_line(line - 1) + local line_num, message = error.line, error.message + buffer:goto_line(line_num - 1) if message then - buffer.annotation_text[line - 1] = message - if not error.warning then buffer.annotation_style[line - 1] = 8 end -- error + buffer.annotation_text[line_num - 1] = message + -- Style number 8 is the error style. + if not error.warning then buffer.annotation_style[line_num - 1] = 8 end end end events.connect(events.KEYPRESS, function(code) @@ -314,7 +315,7 @@ events.connect(events.KEYPRESS, function(code) return true end end) -events.connect(events.DOUBLE_CLICK, function(pos, line) +events.connect(events.DOUBLE_CLICK, function(_, line) if is_msg_buf(buffer) and M.cwd then M.goto_error(line) end end) diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua index eabbb26d..1986e9d3 100644 --- a/modules/textadept/session.lua +++ b/modules/textadept/session.lua @@ -49,16 +49,16 @@ function M.load(filename) for line in f:lines() do if line:find('^buffer:') then local patt = '^buffer: (%d+) (%d+) (%d+) (.+)$' - local anchor, current_pos, first_visible_line, filename = line:match(patt) - if not filename:find('^%[.+%]$') then - if lfs_attributes(filename) then - io.open_file(filename) + local anchor, current_pos, first_visible_line, file = line:match(patt) + if not file:find('^%[.+%]$') then + if lfs_attributes(file) then + io.open_file(file) else - not_found[#not_found + 1] = filename + not_found[#not_found + 1] = file end else - buffer.new()._type = filename - events.emit(events.FILE_OPENED, filename) + buffer.new()._type = file + events.emit(events.FILE_OPENED, file) end -- Restore saved buffer selection and view. anchor, current_pos = tonumber(anchor) or 0, tonumber(current_pos) or 0 @@ -85,12 +85,12 @@ function M.load(filename) ui.maximized = maximized == 'true' if not ui.maximized then ui.size = {width, height} end elseif line:find('^recent:') then - local filename = line:match('^recent: (.+)$') + local file = line:match('^recent: (.+)$') local recent, exists = io.recent_files, false - for i, file in ipairs(recent) do - if filename == file then exists = true break end + for i = 1, #recent do + if file == recent[i] then exists = true break end end - if not exists then recent[#recent + 1] = filename end + if not exists then recent[#recent + 1] = file end end end f:close() @@ -131,16 +131,15 @@ function M.save(filename) local view_line = "%sview%d: %d" -- level, number, doc index -- Write out opened buffers. for _, buffer in ipairs(_BUFFERS) do - local filename = buffer.filename or buffer._type - if filename then + local file = buffer.filename or buffer._type + if file then local current = buffer == view.buffer local anchor = current and 'anchor' or '_anchor' local current_pos = current and 'current_pos' or '_current_pos' local top_line = current and 'first_visible_line' or '_first_visible_line' session[#session + 1] = buffer_line:format(buffer[anchor] or 0, buffer[current_pos] or 0, - buffer[top_line] or 0, - filename) + buffer[top_line] or 0, file) end end -- Write out split views. diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua index a264908e..60134bc9 100644 --- a/modules/textadept/snippets.lua +++ b/modules/textadept/snippets.lua @@ -258,7 +258,7 @@ M._snippet_mt = { {__index = _G}) local f, result = load('return '..snippet.unescape_text(code, true), nil, 'bt', env) - if f then f, result = pcall(f) end + if f then result = select(2, pcall(f)) end return result or '' end) -- Shell code. @@ -306,12 +306,12 @@ M._snippet_mt = { -- Add additional carets at mirrors. escaped_text = snippet:get_escaped_text()..' ' local offset = 0 - for s, e in escaped_text:gmatch('()%%'..index..'()[^(]') do - buffer:set_target_range(start + s - 1 + offset, - start + e - 1 + offset) + for s2, e2 in escaped_text:gmatch('()%%'..index..'()[^(]') do + buffer:set_target_range(start + s2 - 1 + offset, + start + e2 - 1 + offset) buffer:replace_target(placeholder) buffer:add_selection(buffer.target_start, buffer.target_end) - offset = offset + (#placeholder - (e - s)) + offset = offset + (#placeholder - (e2 - s2)) end buffer.main_selection = 0 end |