aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept
diff options
context:
space:
mode:
Diffstat (limited to 'modules/textadept')
-rw-r--r--modules/textadept/bookmarks.lua2
-rw-r--r--modules/textadept/command_entry.lua7
-rw-r--r--modules/textadept/find.lua10
-rw-r--r--modules/textadept/keys.lua2
-rw-r--r--modules/textadept/menu.lua2
-rw-r--r--modules/textadept/snippets.lua5
6 files changed, 13 insertions, 15 deletions
diff --git a/modules/textadept/bookmarks.lua b/modules/textadept/bookmarks.lua
index 0e6ab017..254b38a1 100644
--- a/modules/textadept/bookmarks.lua
+++ b/modules/textadept/bookmarks.lua
@@ -72,7 +72,7 @@ end
---
-- Goes to selected bookmark from a filtered list.
-function goto()
+function goto_bookmark()
local buffer = buffer
local markers, line = {}, buffer:marker_next(0, 2^MARK_BOOKMARK)
if line == -1 then return end
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua
index b574f9dd..3590c2cb 100644
--- a/modules/textadept/command_entry.lua
+++ b/modules/textadept/command_entry.lua
@@ -27,10 +27,10 @@ local env = setmetatable({}, {
-- Execute a Lua command.
events.connect(events.COMMAND_ENTRY_COMMAND, function(command)
- local f, err = loadstring(command)
+ local f, err = load(command, nil, 'bt', env)
if err then error(err) end
gui.command_entry.focus() -- toggle focus to hide
- setfenv(f, env)()
+ f()
events.emit(events.UPDATE_UI)
end)
@@ -41,8 +41,7 @@ events.connect(events.COMMAND_ENTRY_KEYPRESS, function(code)
elseif keys.KEYSYMS[code] == '\t' then
local substring = gui.command_entry.entry_text:match('[%w_.:]+$') or ''
local path, o, prefix = substring:match('^([%w_.:]-)([.:]?)([%w_]*)$')
- local f, err = loadstring('return ('..path..')')
- if type(f) == "function" then setfenv(f, env) end
+ local f, err = load('return ('..path..')', nil, 'bt', env)
local ok, tbl = pcall(f)
local cmpls = {}
prefix = '^'..prefix
diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua
index d1d75321..be54e3ae 100644
--- a/modules/textadept/find.lua
+++ b/modules/textadept/find.lua
@@ -42,7 +42,7 @@ function find.find_in_files(utf8_dir)
local text = find.find_entry_text
if not find.lua then text = text:gsub('([().*+?^$%%[%]-])', '%%%1') end
if not find.match_case then text = text:lower() end
- if find.whole_word then text = '[^%W_]'..text..'[^%W_]' end
+ if find.whole_word then text = '%f[%w_]'..text..'%f[^%w_]' end
local match_case, whole_word = find.match_case, find.whole_word
local matches = { 'Find: '..text }
function search_file(file)
@@ -50,7 +50,6 @@ function find.find_in_files(utf8_dir)
for line in io.lines(file) do
local optimized_line = line
if not match_case then optimized_line = line:lower() end
- if whole_word then optimized_line = ' '..line..' ' end
if optimized_line:find(text) then
file = file:iconv('UTF-8', _CHARSET)
matches[#matches + 1] = ('%s:%s:%s'):format(file, line_num, line)
@@ -127,7 +126,7 @@ local function find_(text, next, flags, nowrap, wrapped)
local results = { buffer_text:find(text, buffer.anchor + increment + 1) }
if #results > 0 then
result = results[1]
- find.captures = { unpack(results, 3) }
+ find.captures = { table.unpack(results, 3) }
buffer:set_sel(results[2], result - 1)
else
result = -1
@@ -200,14 +199,13 @@ events.connect(events.COMMAND_ENTRY_COMMAND, function(text)
end, 1) -- place before command_entry.lua's handler (if necessary)
-- Optimize for speed.
-local loadstring = loadstring
-local pcall = pcall
+local load, pcall = load, pcall
-- Runs the given code.
-- This function is passed to `string.gsub()` in the `replace()` function.
-- @param code The code to run.
local function run(code)
- local ok, val = pcall(loadstring('return '..code))
+ local ok, val = pcall(load('return '..code))
if not ok then
gui.dialog('ok-msgbox',
'--title', L('Error'),
diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua
index f10b153c..275a5616 100644
--- a/modules/textadept/keys.lua
+++ b/modules/textadept/keys.lua
@@ -225,7 +225,7 @@ keys[not OSX and 'cf2' or 'mf2'] = m_textadept.bookmarks.toggle
keys[not OSX and 'csf2' or 'msf2'] = m_textadept.bookmarks.clear
keys.f2 = m_textadept.bookmarks.goto_next
keys.sf2 = m_textadept.bookmarks.goto_prev
-keys.af2 = m_textadept.bookmarks.goto
+keys.af2 = m_textadept.bookmarks.goto_bookmark
-- Snapopen.
keys[not OSX and 'cu' or 'mu'] = { m_textadept.snapopen.open, _USERHOME }
-- TODO: { m_textadept.snapopen.open, _HOME }
diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua
index bbc632d5..0ba21390 100644
--- a/modules/textadept/menu.lua
+++ b/modules/textadept/menu.lua
@@ -131,7 +131,7 @@ menubar = {
{ L('Clear Bookmarks'), m_textadept.bookmarks.clear },
{ L('Next Bookmark'), m_textadept.bookmarks.goto_next },
{ L('Previous Bookmark'), m_textadept.bookmarks.goto_prev },
- { L('Goto Bookmark...'), m_textadept.bookmarks.goto },
+ { L('Goto Bookmark...'), m_textadept.bookmarks.goto_bookmark },
},
{ title = L('Snapopen'),
{ L('Snapopen User Home'), { m_textadept.snapopen.open, _USERHOME } },
diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua
index 3763ab7c..8e849ece 100644
--- a/modules/textadept/snippets.lua
+++ b/modules/textadept/snippets.lua
@@ -307,8 +307,9 @@ _snippet_mt = {
escaped_text = escaped_text:gsub('%%'..index..'<([^>]*)>', function(code)
local env = setmetatable({ selected_text = snippet.original_sel_text },
{ __index = _G })
- local f, result = loadstring('return '..snippet.unescape_text(code, true))
- if f then f, result = pcall(setfenv(f, env)) end
+ local f, result = load('return '..snippet.unescape_text(code, true), nil,
+ 'bt', env)
+ if f then f, result = pcall(f) end
return result or ''
end)
-- Shell code.