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/filter_through.lua | |
parent | 2247eeb38c71da492cb96711e133b353e7c3129d (diff) | |
download | textadept-78bcda2db6b0b8669a6fbcf63b1143602f544416.tar.gz textadept-78bcda2db6b0b8669a6fbcf63b1143602f544416.zip |
Code cleanup.
Diffstat (limited to 'modules/textadept/filter_through.lua')
-rw-r--r-- | modules/textadept/filter_through.lua | 80 |
1 files changed, 39 insertions, 41 deletions
diff --git a/modules/textadept/filter_through.lua b/modules/textadept/filter_through.lua index a3094c0c..6861166f 100644 --- a/modules/textadept/filter_through.lua +++ b/modules/textadept/filter_through.lua @@ -26,47 +26,45 @@ function filter_through() gui.command_entry.focus() end -events.connect('command_entry_keypress', - function(code) - if filter_through_active and code == 0xff1b then -- escape - filter_through_active = false - end - end, 1) -- place before command_entry.lua's handler (if necessary) +events.connect('command_entry_keypress', function(code) + if filter_through_active and code == 0xff1b then -- escape + filter_through_active = false + end +end, 1) -- place before command_entry.lua's handler (if necessary) -events.connect('command_entry_command', - function(text) -- filter through - if filter_through_active then - local buffer = buffer - local s, e = buffer.selection_start, buffer.selection_end - local input - if s ~= e then -- use selected lines as input - local i, j = buffer:line_from_position(s), buffer:line_from_position(e) - if i < j then - s = buffer:position_from_line(i) - if buffer.column[e] > 0 then e = buffer:position_from_line(j + 1) end - end - input = buffer:text_range(s, e) - else -- use whole buffer as input - input = buffer:get_text() - end - local f = io.open(tmpfile, 'wb') - f:write(input) - f:close() - local cmd = table.concat({ cat, '"'..tmpfile..'"', '|', text }, ' ') - if WIN32 then cmd = cmd:gsub('/', '\\') end - local p = io.popen(cmd) - if s ~= e then - buffer.target_start, buffer.target_end = s, e - buffer:replace_target(p:read('*all')) - buffer:set_sel(buffer.target_start, buffer.target_end) - else - buffer:set_text(p:read('*all')) - buffer:goto_pos(s) +-- Filter through. +events.connect('command_entry_command', function(text) + if filter_through_active then + local buffer = buffer + local s, e = buffer.selection_start, buffer.selection_end + local input + if s ~= e then -- use selected lines as input + local i, j = buffer:line_from_position(s), buffer:line_from_position(e) + if i < j then + s = buffer:position_from_line(i) + if buffer.column[e] > 0 then e = buffer:position_from_line(j + 1) end end - p:close() - os.remove(tmpfile) - filter_through_active = false - return true + input = buffer:text_range(s, e) + else -- use whole buffer as input + input = buffer:get_text() end - end, 1) -- place before command_entry.lua's handler (if necessary) - + local f = io.open(tmpfile, 'wb') + f:write(input) + f:close() + local cmd = table.concat({ cat, '"'..tmpfile..'"', '|', text }, ' ') + if WIN32 then cmd = cmd:gsub('/', '\\') end + local p = io.popen(cmd) + if s ~= e then + buffer.target_start, buffer.target_end = s, e + buffer:replace_target(p:read('*all')) + buffer:set_sel(buffer.target_start, buffer.target_end) + else + buffer:set_text(p:read('*all')) + buffer:goto_pos(s) + end + p:close() + os.remove(tmpfile) + filter_through_active = false + return true + end +end, 1) -- place before command_entry.lua's handler (if necessary) |