aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2022-07-04 01:48:12 +0200
committerMatěj Cepl <mcepl@cepl.eu>2022-07-04 02:02:30 +0200
commit65ba4c81ebaf419d1a514ad4446c90157a0007b4 (patch)
tree46204c5b841bc110e7e556cd8ab207bd12ed72aa
parentc8073088422aff88781c38455ae32afaced10459 (diff)
downloadvis-par-65ba4c81ebaf419d1a514ad4446c90157a0007b4.tar.gz
Finally functional version.0.2.0
-rw-r--r--init.lua63
1 files changed, 31 insertions, 32 deletions
diff --git a/init.lua b/init.lua
index 42cb0a3..3725520 100644
--- a/init.lua
+++ b/init.lua
@@ -37,13 +37,6 @@ local function dump(o, tbs, tb)
end
end
--- fp = io.popen("foo >/tmp/unique", "w")
--- fp:write(anything)
--- fp:close()
--- fp = io.open("/tmp/unique")
--- x = read("*a")
--- fp:close()
-
local supress_stdout = " >/dev/null"
local supress_stderr = " 2>/dev/null"
local supress_output = supress_stdout .. supress_stderr
@@ -54,30 +47,32 @@ local supress_output = supress_stdout .. supress_stderr
-- If a string was passed we call the spellchecker ourself and redirect its stdout
-- to a temporary file. See http://lua-users.org/lists/lua-l/2007-10/msg00189.html.
-- The returned string consists of each misspell followed by a newline.
-local function run_par(cmd, params, inp)
+local function run_shell_cmd(cmd, params, inp)
local out
print("cmd = " .. cmd .. ", params = " .. params .. ", inp = " .. inp .. ", (" .. type(inp) .. ")")
if type(inp) == "string" then
- -- local full_cmd = cmd .. " " .. params .. " > " .. tmp_name
- -- print("full_cmd = " .. full_cmd)
- -- local tmp_name = os.tmpname()
- -- local proc = assert(io.popen(full_cmd, "w"))
- -- print("proc = " .. type(proc))
- -- proc:write(inp)
- -- -- this error detection may need lua5.2
- -- proc:flush()
- -- local exit_code = proc:close()
- --
- -- local tmp_file = assert(io.open(tmp_name, "r"))
- -- out = tmp_file:read("*a")
- -- tmp_file:close()
- -- print("out = " .. out)
- -- -- os.remove(tmp_name)
- out = vis:pipe(vis.win.file, inp, cmd .. params)
-
- if exit_code then
- print(tostring(exit_code))
+ local full_cmd = cmd .. " " .. params
+ local tmp_name = os.tmpname()
+ print("tmp_name = " .. tmp_name)
+ full_cmd = full_cmd .. " > " .. tmp_name
+ print("full_cmd = " .. full_cmd)
+ local proc = assert(io.popen(full_cmd, "w"))
+ print("proc = " .. type(proc))
+ proc:write(inp)
+ -- this error detection may need lua5.2
+ proc:flush()
+ local exit_code = proc:close()
+ print("exit_code = " .. tostring(exit_code))
+
+ local tmp_file = assert(io.open(tmp_name, "r"))
+ out = tmp_file:read("*a")
+ tmp_file:close()
+ print("out = " .. out)
+ os.remove(tmp_name)
+ -- out = vis:pipe(vis.win.file, inp, cmd .. params)
+
+ if not exit_code then
print("calling " .. full_cmd .. " failed (" .. out .. ")")
return nil
end
@@ -108,14 +103,18 @@ end
getmetatable(_VERSION).__index.lines = lines
function hanging_symbol(line, nspc)
+ local beg, fin = 0, 0
-- itemized list
- if line:find("^[-+*] ", nspc) then
- return nspc + 1 -- one for space
+ beg, fin = line:find("^[-+*] ", nspc)
+ if beg then
+ print("item beg = " .. beg .. ", fin = " .. fin)
+ return fin
end
local beg, fin = line:find("^%d+%. ", nspc)
if beg then
- return fin + 1
+ print("enum beg = " .. beg .. ", fin = " .. fin)
+ return fin
end
return nspc -- no hanging idennt
@@ -144,11 +143,11 @@ vis:operator_new(
table.insert(segment, line)
else -- this is an empty line, so do whole circus FIXME
if next(segment) then
- local new_text = run_par(par_prg, ex_args .. p_arg,
+ local new_text = run_shell_cmd(par_prg, ex_args .. p_arg,
table.concat(segment, "\n"))
segment = {}
p_arg = 0
- out = out .. new_text .. "\n\n"
+ out = out .. new_text
end
end
end