aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept/editing.lua
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2017-06-22 23:17:22 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2017-06-22 23:17:22 -0400
commit838a4812cda87badd9b8b8425ab1cc0ac6053821 (patch)
tree40e2f2accfe76629e091b13c7fe735e625682be9 /modules/textadept/editing.lua
parent30064e7ad7411daf96770111dab21690b5fa54b2 (diff)
downloadtextadept-838a4812cda87badd9b8b8425ab1cc0ac6053821.tar.gz
textadept-838a4812cda87badd9b8b8425ab1cc0ac6053821.zip
Allow pipes in shell command for "filter through".
Diffstat (limited to 'modules/textadept/editing.lua')
-rw-r--r--modules/textadept/editing.lua18
1 files changed, 14 insertions, 4 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index ba742fad..b1f4601d 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -517,10 +517,20 @@ function M.filter_through(command)
-- Use the whole buffer as input.
buffer:target_whole_document()
end
- local p = assert(spawn(command))
- p:write(buffer.target_text)
- p:close()
- buffer:replace_target((p:read('*a') or ''):iconv('UTF-8', _CHARSET))
+ local commands = lpeg.match(lpeg.Ct(lpeg.P{
+ lpeg.C(lpeg.V('command')) * ('|' * lpeg.C(lpeg.V('command')))^0,
+ command = (1 - lpeg.S('"\'|') + lpeg.V('str'))^1,
+ str = '"' * (1 - lpeg.S('"\\') + lpeg.P('\\') * 1)^0 * lpeg.P('"')^-1 +
+ "'" * (1 - lpeg.S("'\\") + lpeg.P('\\') * 1)^0 * lpeg.P("'")^-1,
+ }), command)
+ local output = buffer.target_text
+ for i = 1, #commands do
+ local p = assert(spawn(commands[i]))
+ p:write(output)
+ p:close()
+ output = p:read('*a') or ''
+ end
+ buffer:replace_target(output:iconv('UTF-8', _CHARSET))
if s ~= e then
buffer:set_sel(buffer.target_start, buffer.target_end)
else