aboutsummaryrefslogtreecommitdiffstats
path: root/init.lua
blob: f4653a54ec48f5eeacfb6ea594d0de153284689d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require('vis')
par_prg = "par"

vis:operator_new("gq", function(file, range, pos)
        local cur_line = file.lines[vis.win.selection.line]
        local beg, fin = string.find(cur_line, "^%s+")
        local exec = par_prg .. " ET4w65"
        if beg ~= nil then
            local ind = fin
            if string.find(cur_line, "[-+*]", fin) then
                exec = exec .. "h"
                ind = ind + 2
            end
            exec = exec .. "p" .. ind
            vis:info("beg = " .. beg .. ", fin = " .. fin .. ", exec = " .. exec)
        end
	local status, out, err = vis:pipe(file, range, exec)
	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.")