diff options
author | 2011-01-21 00:41:36 -0500 | |
---|---|---|
committer | 2011-01-21 00:41:36 -0500 | |
commit | 78bcda2db6b0b8669a6fbcf63b1143602f544416 (patch) | |
tree | df837e91e357573ca84be0b20155189252337cec /modules/textadept/find.lua | |
parent | 2247eeb38c71da492cb96711e133b353e7c3129d (diff) | |
download | textadept-78bcda2db6b0b8669a6fbcf63b1143602f544416.tar.gz textadept-78bcda2db6b0b8669a6fbcf63b1143602f544416.zip |
Code cleanup.
Diffstat (limited to 'modules/textadept/find.lua')
-rw-r--r-- | modules/textadept/find.lua | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index 68fcfaf7..e4b1d967 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -166,31 +166,30 @@ function find.find_incremental() gui.command_entry.focus() end -events.connect('command_entry_keypress', - function(code) - local K = _G.keys.KEYSYMS - if find.incremental then - if K[code] == 'esc' then - find.incremental = nil - elseif code < 256 or K[code] == '\b' then - local text = gui.command_entry.entry_text - if K[code] == '\b' then - find_incremental(text:sub(1, -2)) - else - find_incremental(text..string.char(code)) - end +events.connect('command_entry_keypress', function(code) + local K = _G.keys.KEYSYMS + if find.incremental then + if K[code] == 'esc' then + find.incremental = nil + elseif code < 256 or K[code] == '\b' then + local text = gui.command_entry.entry_text + if K[code] == '\b' then + find_incremental(text:sub(1, -2)) + else + find_incremental(text..string.char(code)) end end - end, 1) -- place before command_entry.lua's handler (if necessary) + end +end, 1) -- place before command_entry.lua's handler (if necessary) -events.connect('command_entry_command', - function(text) -- 'find next' for incremental search - if find.incremental then - find.incremental_start = buffer.current_pos + 1 - find_incremental(text) - return true - end - end, 1) -- place before command_entry.lua's handler (if necessary) +-- 'Find next' for incremental search. +events.connect('command_entry_command', function(text) + if find.incremental then + find.incremental_start = buffer.current_pos + 1 + find_incremental(text) + return true + end +end, 1) -- place before command_entry.lua's handler (if necessary) -- Replaces found text. -- 'find_' is called first, to select any found text. The selected text is then @@ -212,19 +211,18 @@ local function replace(rtext) rtext = rtext:gsub('%%'..i, v) end end - local ok, rtext = pcall(rtext.gsub, rtext, '%%(%b())', - function(code) - local ok, val = pcall(loadstring('return '..code)) - if not ok then - gui.dialog('ok-msgbox', - '--title', L('Error'), - '--text', L('An error occured:'), - '--informative-text', val:gsub('"', '\\"'), - '--no-cancel') - error() - end - return val - end) + local ok, rtext = pcall(rtext.gsub, rtext, '%%(%b())', function(code) + local ok, val = pcall(loadstring('return '..code)) + if not ok then + gui.dialog('ok-msgbox', + '--title', L('Error'), + '--text', L('An error occured:'), + '--informative-text', val:gsub('"', '\\"'), + '--no-cancel') + error() + end + return val + end) if ok then rtext = rtext:gsub('\\037', '%%') -- unescape '%' buffer:replace_target(rtext:gsub('\\[abfnrtv\\]', escapes)) |