aboutsummaryrefslogtreecommitdiffstats
path: root/init.lua
blob: a32f7531f81e05ab16378c31057673c0de08ece2 (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
33
34
local internal_open = false

local function file_exists(path)
	local f = io.open(path)
	local out = f ~= nil
	if out then
		io.close(f)
	end
	return out
end

local function open_other_file(file)
	local other = ""
	if file then
		if (file:sub(-4) == ".rej") then
			-- open base file
			other = file:sub(1, -5)
		else
			-- open rejected hunks file
			other = file .. '.rej'
		end
		if file_exists(other) then
			internal_open = true
			vis:command('open ' .. other)
		end
	end
end

vis.events.subscribe(vis.events.FILE_OPEN, function (file)
	if not internal_open then
		open_other_file(file.path)
	end
end)