aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2024-02-17 22:03:55 +0100
committerMatěj Cepl <mcepl@cepl.eu>2024-02-17 22:03:55 +0100
commitbd714ef8371c84689ea99717a04dbb1f076ed367 (patch)
treea4f70357fef6e1c9456b64f4cd975d8cf0d4d036
parent067128b0c1e9ce6212f19b709fba68d38fcdc75b (diff)
downloadvis-open_rej-master.tar.gz
Open not only by the base file, but also by *.rej one.HEADmaster
It is useful, when *.rej file is find by find(1) or something similar.
-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)