aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--init.lua22
1 files changed, 17 insertions, 5 deletions
diff --git a/init.lua b/init.lua
index cc83695..a32f753 100644
--- a/init.lua
+++ b/init.lua
@@ -1,3 +1,5 @@
+local internal_open = false
+
local function file_exists(path)
local f = io.open(path)
local out = f ~= nil
@@ -7,16 +9,26 @@ local function file_exists(path)
return out
end
-local function open_rej_file(file)
+local function open_other_file(file)
+ local other = ""
if file then
- local rejfile = file .. '.rej'
- if file_exists(rejfile) then
- vis:command('open ' .. rejfile)
+ 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)
- open_rej_file(file.path)
+ if not internal_open then
+ open_other_file(file.path)
+ end
end)