Merge pull request #435 from takase1121/replace-unpack

replace unpack() with table.unpack()
This commit is contained in:
Adam 2021-11-16 19:49:00 -05:00 committed by GitHub
commit 0525e6e96a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 12 deletions

View File

@ -37,7 +37,7 @@ local function update_preview(sel, search_fn, text)
last_view:scroll_to_line(line2, true)
found_expression = true
else
last_view.doc:set_selection(unpack(sel))
last_view.doc:set_selection(table.unpack(sel))
found_expression = false
end
end
@ -55,7 +55,7 @@ end
local function find(label, search_fn)
last_view, last_sel, last_finds = core.active_view,
{ core.active_view.doc:get_selection() }, {}
local text = last_view.doc:get_text(unpack(last_sel))
local text = last_view.doc:get_text(table.unpack(last_sel))
found_expression = false
core.command_view:set_text(text, true)
@ -69,8 +69,8 @@ local function find(label, search_fn)
last_fn, last_text = search_fn, text
else
core.error("Couldn't find %q", text)
last_view.doc:set_selection(unpack(last_sel))
last_view:scroll_to_make_visible(unpack(last_sel))
last_view.doc:set_selection(table.unpack(last_sel))
last_view:scroll_to_make_visible(table.unpack(last_sel))
end
end, function(text)
update_preview(last_sel, search_fn, text)
@ -79,8 +79,8 @@ local function find(label, search_fn)
end, function(explicit)
core.status_view:remove_tooltip()
if explicit then
last_view.doc:set_selection(unpack(last_sel))
last_view:scroll_to_make_visible(unpack(last_sel))
last_view.doc:set_selection(table.unpack(last_sel))
last_view:scroll_to_make_visible(table.unpack(last_sel))
end
end)
end

View File

@ -202,9 +202,9 @@ local function selection_iterator(invariant, idx)
local target = invariant[3] and (idx*4 - 7) or (idx*4 + 1)
if target > #invariant[1] or target <= 0 or (type(invariant[3]) == "number" and invariant[3] ~= idx - 1) then return end
if invariant[2] then
return idx+(invariant[3] and -1 or 1), sort_positions(unpack(invariant[1], target, target+4))
return idx+(invariant[3] and -1 or 1), sort_positions(table.unpack(invariant[1], target, target+4))
else
return idx+(invariant[3] and -1 or 1), unpack(invariant[1], target, target+4)
return idx+(invariant[3] and -1 or 1), table.unpack(invariant[1], target, target+4)
end
end
@ -305,7 +305,7 @@ local function pop_undo(self, undo_stack, redo_stack, modified)
local line1, col1, line2, col2 = table.unpack(cmd)
self:raw_remove(line1, col1, line2, col2, redo_stack, cmd.time)
elseif cmd.type == "selection" then
self.selections = { unpack(cmd) }
self.selections = { table.unpack(cmd) }
end
modified = modified or (cmd.type ~= "selection")
@ -348,7 +348,7 @@ function Doc:raw_insert(line, col, text, undo_stack, time)
-- push undo
local line2, col2 = self:position_offset(line, col, #text)
push_undo(undo_stack, time, "selection", unpack(self.selections))
push_undo(undo_stack, time, "selection", table.unpack(self.selections))
push_undo(undo_stack, time, "remove", line, col, line2, col2)
-- update highlighter and assure selection is in bounds
@ -360,7 +360,7 @@ end
function Doc:raw_remove(line1, col1, line2, col2, undo_stack, time)
-- push undo
local text = self:get_text(line1, col1, line2, col2)
push_undo(undo_stack, time, "selection", unpack(self.selections))
push_undo(undo_stack, time, "selection", table.unpack(self.selections))
push_undo(undo_stack, time, "insert", line1, col1, text)
-- get line content before/after removed text

View File

@ -28,3 +28,6 @@ package.searchers = { package.searchers[1], package.searchers[2], function(modna
if not path then return nil end
return system.load_native_plugin, path
end }
table.pack = table.pack or pack or function(...) return {...} end
table.unpack = table.unpack or unpack

View File

@ -155,7 +155,7 @@ function tokenizer.tokenize(incoming_syntax, text, state)
if count % 2 == 0 then break end
end
until not res[1] or not close or not target[3]
return unpack(res)
return table.unpack(res)
end
while i <= #text do