1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
require('vis')
par_prg = "fmt -c -w 65"
vis:operator_new("gq", function(file, range, pos)
vis:info("par_prg = " .. par_prg)
local status, out, err = vis:pipe(file, range, par_prg)
-- local status, out, err = vis:pipe(file, range, "par -w 65")
if not status then
vis:info(err)
else
file:delete(range)
file:insert(range.start, out)
end
return range.start -- new cursor location
end, "Formating operator, filter range through formatting filter")
vis:option_register("autoformat", "bool", function(value, toogle)
if not vis.win then return false end
vis.win.autoformat = toogle and not vis.win.autoformat or value
vis:info("Option autoformat = " .. tostring(vis.win.autoformat))
return true
end, "Automatically format current paragraph.")
|