aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2015-03-16 16:55:12 -0400
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2015-03-16 16:55:12 -0400
commit39b5f8728fdd215217d2749c20a2668ecbb5f080 (patch)
tree603e845b6683f6725593c8f12e69183156b6c5c2
parentcb3e886bba78a040d486af518d491cc191cebfd8 (diff)
Code cleanup based on the output of luacheck, a Lua linter.
-rw-r--r--core/file_io.lua18
-rw-r--r--core/init.lua2
-rw-r--r--core/lfs_ext.lua2
-rw-r--r--core/locale.lua2
-rw-r--r--core/ui.lua4
-rw-r--r--modules/ansi_c/init.lua8
-rw-r--r--modules/lua/init.lua6
-rw-r--r--modules/lua/tadoc.lua22
-rw-r--r--modules/textadept/command_entry.lua2
-rw-r--r--modules/textadept/editing.lua13
-rw-r--r--modules/textadept/file_types.lua8
-rw-r--r--modules/textadept/find.lua5
-rw-r--r--modules/textadept/keys.lua6
-rw-r--r--modules/textadept/menu.lua26
-rw-r--r--modules/textadept/run.lua25
-rw-r--r--modules/textadept/session.lua29
-rw-r--r--modules/textadept/snippets.lua10
17 files changed, 96 insertions, 92 deletions
diff --git a/core/file_io.lua b/core/file_io.lua
index bced6219..ba84b65e 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -109,8 +109,8 @@ function io.open_file(filenames)
if not filenames then return end
for i = 1, #filenames do
local filename = lfs.abspath((filenames[i]:gsub('^file://', '')))
- for i, buffer in ipairs(_BUFFERS) do
- if filename == buffer.filename then view:goto_buffer(i) goto continue end
+ for j, buffer in ipairs(_BUFFERS) do
+ if filename == buffer.filename then view:goto_buffer(j) goto continue end
end
local text = ''
@@ -133,9 +133,9 @@ function io.open_file(filenames)
end
end
if not buffer.encoding and not text:sub(1, 65536):find('\0') then
- for i = 1, #io.encodings do
- local ok, conv = pcall(string.iconv, text, 'UTF-8', io.encodings[i])
- if ok then buffer.encoding, text = io.encodings[i], conv break end
+ for j = 1, #io.encodings do
+ local ok, conv = pcall(string.iconv, text, 'UTF-8', io.encodings[j])
+ if ok then buffer.encoding, text = io.encodings[j], conv break end
end
assert(buffer.encoding, _L['Encoding conversion failed.'])
end
@@ -152,8 +152,8 @@ function io.open_file(filenames)
events.emit(events.FILE_OPENED, filename)
-- Add file to recent files list, eliminating duplicates.
- for i, file in ipairs(io.recent_files) do
- if file == filename then table.remove(io.recent_files, i) break end
+ for j, file in ipairs(io.recent_files) do
+ if file == filename then table.remove(io.recent_files, j) break end
end
table.insert(io.recent_files, 1, filename)
::continue::
@@ -303,7 +303,7 @@ events_connect(events.RESUME, update_modified_file)
-- Prompts the user to reload the current file if it has been externally
-- modified.
-events_connect(events.FILE_CHANGED, function(filename)
+events_connect(events.FILE_CHANGED, function()
local msg = ('"%s"\n%s'):format(buffer.filename:iconv('UTF-8', _CHARSET),
_L['has been modified. Reload it?'])
local button = ui.dialogs.msgbox{
@@ -315,7 +315,7 @@ events_connect(events.FILE_CHANGED, function(filename)
end)
-- Closes the initial "Untitled" buffer.
-events_connect(events.FILE_OPENED, function(filename)
+events_connect(events.FILE_OPENED, function()
local buf = _BUFFERS[1]
if #_BUFFERS == 2 and not (buf.filename or buf._type or buf.modify) then
view:goto_buffer(1)
diff --git a/core/init.lua b/core/init.lua
index 2bfb0662..591c67d1 100644
--- a/core/init.lua
+++ b/core/init.lua
@@ -18,7 +18,7 @@ _M = {} -- language modules table
if jit then module, package.searchers, bit32 = nil, package.loaders, bit end
-- pdcurses compatibility.
if CURSES and WIN32 then
- function spawn(argv, cwd, stdout_cb, stderr_cb, exit_cb)
+ function spawn(argv, cwd, stdout_cb, _, exit_cb)
local current_dir = lfs.currentdir()
if cwd then lfs.chdir(cwd) end
local p = io.popen(argv..' 2>&1')
diff --git a/core/lfs_ext.lua b/core/lfs_ext.lua
index 8b96b861..b3dda4f7 100644
--- a/core/lfs_ext.lua
+++ b/core/lfs_ext.lua
@@ -41,7 +41,7 @@ local function exclude(file, filter)
end
---
--- Iterates over all files and sub-directories (up to level number *n*) in
+-- Iterates over all files and sub-directories (up to *n* levels deep) in
-- directory *dir*, calling function *f* with each file found.
-- Files passed to *f* do not match any pattern in string or table *filter*,
-- and, unless *exclude_FILTER* is `true`, `lfs.FILTER` as well. A filter table
diff --git a/core/locale.lua b/core/locale.lua
index def44789..1dedd4a3 100644
--- a/core/locale.lua
+++ b/core/locale.lua
@@ -25,4 +25,4 @@ end
f:close()
return setmetatable(M,
- {__index = function(t, k) return 'No Localization:'..k end})
+ {__index = function(_, k) return 'No Localization:'..k end})
diff --git a/core/ui.lua b/core/ui.lua
index c6244ea2..1da1b159 100644
--- a/core/ui.lua
+++ b/core/ui.lua
@@ -43,7 +43,7 @@ local theme_props = {}
-- @see ui._print
local function _print(buffer_type, ...)
local print_buffer
- for i, buffer in ipairs(_BUFFERS) do
+ for _, buffer in ipairs(_BUFFERS) do
if buffer._type == buffer_type then print_buffer = buffer break end
end
if not print_buffer then
@@ -85,7 +85,7 @@ function ui._print(buffer_type, ...) pcall(_print, buffer_type, ...) end
function ui.print(...) ui._print(_L['[Message Buffer]'], ...) end
-- Documentation is in core/.ui.dialogs.luadoc.
-ui.dialogs = setmetatable({}, {__index = function(t, k)
+ui.dialogs = setmetatable({}, {__index = function(_, k)
-- Wrapper for `ui.dialog(k)`, transforming the given table of arguments into
-- a set of command line arguments and transforming the resulting standard
-- output into Lua objects.
diff --git a/modules/ansi_c/init.lua b/modules/ansi_c/init.lua
index 47d39022..45df001f 100644
--- a/modules/ansi_c/init.lua
+++ b/modules/ansi_c/init.lua
@@ -27,7 +27,7 @@ local xpms = setmetatable({
c = XPM.CLASS, d = XPM.SLOT, e = XPM.VARIABLE, f = XPM.METHOD,
g = XPM.TYPEDEF, m = XPM.VARIABLE, s = XPM.STRUCT, t = XPM.TYPEDEF,
v = XPM.VARIABLE
-}, {__index = function(t, k) return 0 end})
+}, {__index = function() return 0 end})
textadept.editing.autocompleters.ansi_c = function()
local list = {}
@@ -54,10 +54,10 @@ textadept.editing.autocompleters.ansi_c = function()
local sep = string.char(buffer.auto_c_type_separator)
for i = 1, #tags_files do
if lfs.attributes(tags_files[i]) then
- for line in io.lines(tags_files[i]) do
- local name = line:match('^%S+')
+ for tag_line in io.lines(tags_files[i]) do
+ local name = tag_line:match('^%S+')
if name:find(name_patt) and not name:find('^!') and not list[name] then
- local fields = line:match(';"\t(.*)$')
+ local fields = tag_line:match(';"\t(.*)$')
if (fields:match('class:(%S+)') or fields:match('enum:(%S+)') or
fields:match('struct:(%S+)') or fields:match('typedef:(%S+)') or
'') == symbol then
diff --git a/modules/lua/init.lua b/modules/lua/init.lua
index a735c544..f2ae7343 100644
--- a/modules/lua/init.lua
+++ b/modules/lua/init.lua
@@ -58,10 +58,10 @@ textadept.editing.autocompleters.lua = function()
local sep = string.char(buffer.auto_c_type_separator)
for i = 1, #M.tags do
if lfs.attributes(M.tags[i]) then
- for line in io.lines(M.tags[i]) do
- local name = line:match('^%S+')
+ for tag_line in io.lines(M.tags[i]) do
+ local name = tag_line:match('^%S+')
if name:find(name_patt) and not list[name] then
- local fields = line:match(';"\t(.*)$')
+ local fields = tag_line:match(';"\t(.*)$')
local k, class = fields:sub(1, 1), fields:match('class:(%S+)') or ''
if class == symbol and (op ~= ':' or k == 'f') then
list[#list + 1] = ("%s%s%d"):format(name, sep, xpms[k])
diff --git a/modules/lua/tadoc.lua b/modules/lua/tadoc.lua
index 3c6f381f..b097e892 100644
--- a/modules/lua/tadoc.lua
+++ b/modules/lua/tadoc.lua
@@ -176,16 +176,16 @@ function M.start(doc)
write_apidoc(apidoc, {name = '_G'}, m)
end
-- Tag and document the functions.
- for i = 1, #m.functions do
- local module_name, name = m.functions[i]:match('^(.-)[%.:]?([^.:]+)$')
+ for j = 1, #m.functions do
+ local module_name, name = m.functions[j]:match('^(.-)[%.:]?([^.:]+)$')
if module_name == '' then module_name = m.name end
write_tag(ctags, name, 'f', 'class:'..module_name)
- write_apidoc(apidoc, m, m.functions[m.functions[i]])
+ write_apidoc(apidoc, m, m.functions[m.functions[j]])
end
if m.tables then
-- Document the tables.
- for i = 1, #m.tables do
- local table_name, table = m.tables[i], m.tables[m.tables[i]]
+ for j = 1, #m.tables do
+ local table_name, table = m.tables[j], m.tables[m.tables[j]]
local module_name = m.name
if table_name:find('^_G%.') then
module_name, table_name = table_name:match('^_G%.(.-)%.?([^%.]+)$')
@@ -200,11 +200,11 @@ function M.start(doc)
if table.field then
-- Tag and document the table's fields.
table_name = module_name..'.'..table_name
- for j = 1, #table.field do
- write_tag(ctags, table.field[j], 'F', 'class:'..table_name)
+ for k = 1, #table.field do
+ write_tag(ctags, table.field[k], 'F', 'class:'..table_name)
write_apidoc(apidoc, {name = table_name}, {
- name = table.field[j],
- description = table.field[table.field[j]],
+ name = table.field[k],
+ description = table.field[table.field[k]],
class = 'table'
})
end
@@ -213,8 +213,8 @@ function M.start(doc)
end
if m.fields then
-- Tag and document the fields.
- for i = 1, #m.fields do
- local field_name, field = m.fields[i], m.fields[m.fields[i]]
+ for j = 1, #m.fields do
+ local field_name, field = m.fields[j], m.fields[m.fields[j]]
local module_name = m.name
if field_name:find('^_G%.') then
module_name, field_name = field_name:match('^_G%.(.-)%.?([^%.]+)$')
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