aboutsummaryrefslogtreecommitdiffstats
path: root/init.lua
blob: e2599c7b9adc25dcecacffc8e5755a70eeced28a (plain) (blame)
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 = nil

vis:operator_new("gq", function(file, range, pos)
	local prg = (par_prg ~= nil) and par_prg or "fmt -c -w 65"
	local status, out, err = vis:pipe(file, range, 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 fmt(1)")

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.")