diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2024-02-17 22:03:55 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2024-02-17 22:03:55 +0100 |
commit | bd714ef8371c84689ea99717a04dbb1f076ed367 (patch) | |
tree | a4f70357fef6e1c9456b64f4cd975d8cf0d4d036 | |
parent | 067128b0c1e9ce6212f19b709fba68d38fcdc75b (diff) | |
download | vis-open_rej-bd714ef8371c84689ea99717a04dbb1f076ed367.tar.gz |
It is useful, when *.rej file is find by find(1) or something
similar.
-rw-r--r-- | init.lua | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -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) |