aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2008-02-10 21:31:53 -0500
committermitchell <70453897+667e-11@users.noreply.github.com>2008-02-10 21:31:53 -0500
commit2a8b91209627608fe61c21ec96de31b7fffcea94 (patch)
tree039767373d0a3f688c86cc8c1692fc422b80696d
parent655d3222b8e242bcdb96e9458dc311aee1a658e5 (diff)
downloadtextadept-2a8b91209627608fe61c21ec96de31b7fffcea94.tar.gz
textadept-2a8b91209627608fe61c21ec96de31b7fffcea94.zip
Instead of io.popen():read(), a file descriptor is kept and close()'d afterward.
-rw-r--r--core/ext/pm/file_browser.lua8
-rw-r--r--core/file_io.lua11
-rw-r--r--modules/lua/commands.lua4
-rw-r--r--modules/textadept/editing.lua14
-rw-r--r--modules/textadept/lsnippets.lua7
-rw-r--r--modules/textadept/macros.lua12
-rw-r--r--modules/textadept/snippets.lua9
7 files changed, 46 insertions, 19 deletions
diff --git a/core/ext/pm/file_browser.lua b/core/ext/pm/file_browser.lua
index 9acf9bec..f48c1346 100644
--- a/core/ext/pm/file_browser.lua
+++ b/core/ext/pm/file_browser.lua
@@ -12,7 +12,9 @@ end
function get_contents_for(full_path)
local dirpath = table.concat(full_path, '/')
- local out = io.popen('ls -1p "'..dirpath..'"'):read('*all')
+ local p = io.popen('ls -1p "'..dirpath..'"')
+ local out = p:read('*all')
+ p:close()
if #out == 0 then
error('No such directory: '..dirpath)
return {}
@@ -49,7 +51,9 @@ function perform_menu_action(menu_item, selected_item)
textadept.pm.entry_text = filepath
textadept.pm.activate()
elseif menu_item == 'File Details' then
- local out = io.popen('ls -dhl "'..filepath..'"'):read('*all')
+ local p = io.popen('ls -dhl "'..filepath..'"')
+ local out = p:read('*all')
+ p:close()
local perms, num_dirs, owner, group, size, mod_date =
out:match('^(%S+) (%S+) (%S+) (%S+) (%S+) (%S+ %S)')
out = 'File details for:\n'..filepath..'\n'..
diff --git a/core/file_io.lua b/core/file_io.lua
index 8adf8af8..29d7d535 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -46,8 +46,9 @@ end
function open(filenames)
if not filenames then
local directory = '--filename="'..(buffer.filename or '')..'"'
- filenames = io.popen('zenity --file-selection --multiple '..
- directory):read('*all')
+ local p = io.popen('zenity --file-selection --multiple '..directory)
+ filenames = p:read('*all')
+ p:close()
end
for filename in filenames:gmatch('[^|\n]+') do open_helper(filename) end
end
@@ -100,8 +101,10 @@ function save_as(buffer, filename)
textadept.check_focused_buffer(buffer)
if not filename then
local directory = '--filename="'..(buffer.filename or '')..'"'
- filename = io.popen('zenity --file-selection --save '..
- directory..' --confirm-overwrite'):read('*all')
+ local p = io.popen('zenity --file-selection --save '..directory..
+ ' --confirm-overwrite')
+ filename = p:read('*all')
+ p:close()
end
if #filename > 0 then
buffer.filename = filename:sub(1, -2) -- chomp
diff --git a/modules/lua/commands.lua b/modules/lua/commands.lua
index b5d0c524..2130ff18 100644
--- a/modules/lua/commands.lua
+++ b/modules/lua/commands.lua
@@ -62,7 +62,9 @@ end
function run()
local buffer = buffer
local cmd = 'lua "'..buffer.filename..'" 2>&1'
- local out = io.popen(cmd):read('*all')
+ local p = io.popen(cmd)
+ local out = p:read('*all')
+ p:close()
textadept.print('> '..cmd..'\n'..out)
end
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index 4c5b1044..76a98f3b 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -219,8 +219,10 @@ end
function goto_line(line)
local buffer = buffer
if not line then
- line = io.popen('zenity --entry --title "Go To" '..
- '--text "Line Number:"'):read('*all')
+ local p = io.popen('zenity --entry --title "Go To" '..
+ '--text "Line Number:"')
+ line = p:read('*all')
+ p:close()
if line == '' then return end
line = tonumber(line)
end
@@ -542,7 +544,9 @@ end
function ruby_exec()
local buffer = buffer
local txt = get_sel_or_line()
- local out = io.popen("ruby 2>&1 <<'_EOF'\n"..txt..'\n_EOF'):read('*all')
+ local p = io.popen("ruby 2>&1 <<'_EOF'\n"..txt..'\n_EOF')
+ local out = p:read('*all')
+ p:close()
if out:sub(-1) == '\n' then out = out:sub(1, -2) end -- chomp
buffer:replace_sel(out)
end
@@ -587,7 +591,9 @@ function reformat_paragraph()
local buffer = buffer
if buffer:get_sel_text() == '' then select_paragraph() end
local txt = buffer:get_sel_text()
- local out = io.popen("fmt -c -w 80 <<'_EOF'\n"..txt..'\n_EOF'):read('*all')
+ local p = io.popen("fmt -c -w 80 <<'_EOF'\n"..txt..'\n_EOF')
+ local out = p:read('*all')
+ p:close()
if txt:sub(-1) ~= '\n' and out:sub(-1) == '\n' then out = out:sub(1, -2) end
buffer:replace_sel(out)
end
diff --git a/modules/textadept/lsnippets.lua b/modules/textadept/lsnippets.lua
index 7a8a4e13..4fa73b96 100644
--- a/modules/textadept/lsnippets.lua
+++ b/modules/textadept/lsnippets.lua
@@ -134,7 +134,12 @@ function insert(s_text)
-- Execute Lua and shell code.
s_text = s_text:gsub('%%(%b())', run_lua_code)
s_text = s_text:gsub('`([^`]+)`',
- function(code) return io.popen(code):read('*all'):sub(1, -2) end)
+ function(code)
+ local p = io.popen(code)
+ local out = p:read('*all'):sub(1, -2)
+ p:close()
+ return out
+ end)
-- Initialize the new snippet. If one is running, push it onto the stack.
if snippet.index then snippet_stack[#snippet_stack + 1] = snippet end
diff --git a/modules/textadept/macros.lua b/modules/textadept/macros.lua
index 20cf1272..1502d5d5 100644
--- a/modules/textadept/macros.lua
+++ b/modules/textadept/macros.lua
@@ -66,8 +66,10 @@ function stop_recording()
recording = false
local textadept = textadept
local bf, bp = textadept.buffer_functions, textadept.buffer_properties
- local macro_name =
- io.popen('zenity --entry --text "Macro name:"'):read('*all'):sub(1, -2)
+ local p = io.popen('zenity --entry --text "Macro name:"')
+ local macro_name = p:read('*all'):sub(1, -2)
+ p:close()
+
if #macro_name > 0 then
for _, command in ipairs(current) do
command.type = 'function'
@@ -105,8 +107,10 @@ function play(macro_name)
if not macro_name then
local macro_list = ''
for name in pairs(list) do macro_list = macro_list..name..' ' end
- macro_name = io.popen('zenity --list --text "Select a Macro" '..
- '--column Name '..macro_list):read('*all'):sub(1, -2)
+ local p = io.popen('zenity --list --text "Select a Macro" --column Name '..
+ macro_list)
+ macro_name = p:read('*all'):sub(1, -2)
+ p:close()
end
local macro = list[macro_name]
if not macro then return end
diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua
index 45b8cb39..82e41f26 100644
--- a/modules/textadept/snippets.lua
+++ b/modules/textadept/snippets.lua
@@ -110,7 +110,9 @@ function insert(snippet_arg)
-- Execute any shell code.
s_text = s_text:gsub('`(.-)`',
function(code)
- local out = io.popen(code):read('*all')
+ local p = io.popen(code)
+ local out = p:read('*all')
+ p:close()
if out:sub(-1) == '\n' then return out:sub(1, -2) end
end)
@@ -212,8 +214,9 @@ next_snippet_item = function()
script = script:gsub('replacement', replacement)
_DEBUG('script:\n'..script)
- local out = io.popen("ruby 2>&1 <<'_EOF'\n"..
- script..'\n_EOF'):read('*all')
+ local p = io.popen("ruby 2>&1 <<'_EOF'\n"..script..'\n_EOF')
+ local out = p:read('*all')
+ p:close()
_DEBUG('regex out:\n'..out)
if out:sub(-1) == '\n' then out = out:sub(1, -2) end -- chomp
return out