Skip to content

Commit 8b63165

Browse files
committed
Improve trailing context lines behaviour.
1 parent 08f6249 commit 8b63165

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

xtra/DIFF.LUA

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ local function diff_u(fn1,fn2)
3030
local function pfl(p,s)return(p..s:gsub('\n$',''):gsub('\r$',''))end
3131
local i,j,u=1,1
3232
local function flush()if #u.l>0 then
33+
if u.e==4 then table.remove(u.l)end
3334
table.insert(u.l,1,"@@ -"..u.o.s..(u.o.l==1 and""or","..u.o.l).." +"..u.n.s..(u.n.l==1 and""or","..u.n.l).. " @@")
3435
if not fh then
3536
local function fn(s)return string.match(s,"%s")and '"'..s..'"'or s end
@@ -40,7 +41,7 @@ local function diff_u(fn1,fn2)
4041
for _,p in ipairs(path)do
4142
while i<p.x do init()table.insert(u.l,pfl("-",get(fn1,f1,i)))i,u.o.l,u.e=i+1,u.o.l+1,0 end
4243
while j<p.y do init()table.insert(u.l,pfl("+",get(fn2,f2,j)))j,u.n.l,u.e=j+1,u.n.l+1,0 end
43-
if u then if u.e<3 then table.insert(u.l,pfl(" ",get(fn1,f1,i)))u.e,u.o.l,u.n.l=u.e+1,u.o.l+1,u.n.l+1 else flush()end end i,j=i+1,j+1 end
44+
if u then if u.e<4 then table.insert(u.l,pfl(" ",get(fn1,f1,i)))u.e,u.o.l,u.n.l=u.e+1,u.o.l+1,u.n.l+1 else flush()end end i,j=i+1,j+1 end
4445
local function nlc() if la then la=la:sub(-1)if la~='\n'and la~='\r'then table.insert(u.l,"\\ No newline at end of file")end end end
4546
while i<=h do init()la=get(fn1,f1,i,ps)table.insert(u.l,pfl("-",la))i,u.o.l,u.e=i+1,u.o.l+1,0 end nlc()
4647
while j<=w do init()la=get(fn2,f2,j,ps)table.insert(u.l,pfl("+",la))j,u.n.l,u.e=j+1,u.n.l+1,0 end nlc()

0 commit comments

Comments
 (0)