summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-05-11 09:12:52 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-05-11 09:12:52 -0700
commitc1f24e122e23a0980d0fd57c282a7276dd21365d (patch)
treec79af5b579a749c99b575c811dc812235042feaf
parente676014ec852b3d327483afe9d5497de7b9e3c54 (diff)
downloaddiff2err-c1f24e122e23a0980d0fd57c282a7276dd21365d.tar.gz
diff2err-c1f24e122e23a0980d0fd57c282a7276dd21365d.tar.bz2
diff2err-c1f24e122e23a0980d0fd57c282a7276dd21365d.zip
Adding initial revision of diff2err.txr.
This is quite a few years old.
-rwxr-xr-xdiff2err.txr61
1 files changed, 61 insertions, 0 deletions
diff --git a/diff2err.txr b/diff2err.txr
new file mode 100755
index 0000000..f82ee00
--- /dev/null
+++ b/diff2err.txr
@@ -0,0 +1,61 @@
+#!/usr/bin/env txr
+@(next *stdin*)
+@(do (set *stdout* (open-file "errors.err" "w")))
+@(repeat)
+@ (some)
++++ @dir/@path
+@; Don't include deleted files: editor can't open them.
+@ (require (nequal `@dir/@path` "/dev/null"))
+@ (or)
++++ @path@\t@nil
+@ (end)
+@ (repeat)
+@@@@ -@line0,@len0 +@line1,@len1 @@@@@(skip)
+@ (bind (line start minuses pluses old) (0 nil 0 0 nil))
+@ (set line1 @(toint line1))
+@ (repeat)
+@ (cases)
+-@text
+@ (do (inc minuses)
+ (set start line)
+ (push text old))
+@ (or)
+@ (some)
+@/[^+\-]/@nil
+@ (or)
++@nil
+@; Tricky! This (do ...) is performed for every + line ...
+@ (do (if (eql 1 (inc pluses))
+ (set start line))
+ (inc line))
+@; But then due to the following @(eof) the match fails if the + is
+@; not the last line, causing the output-generating @(do) below to
+@; be skipped. The idea is to perform the below output section
+@; even for a + line, if that line is the last line of diff output,
+@; when the last hunk adds files to the end of the file.
+@ (eof)
+@ (end)
+@ (do (inc line)
+ (when start
+ (let ((wording (cond
+ ((zerop minuses) `@pluses lines added`)
+ ((zerop pluses) `@minuses lines deleted`)
+ (t `@minuses lines edited to @pluses lines`))))
+ (put-line `@path:@(+ line1 start):@wording`)
+ (put-lines (nreverse old))
+ (set minuses 0)
+ (set pluses 0)
+ (set start nil)
+ (set old nil))))
+@ (or)
++@nil
+@ (or)
+@ (accept)
+@ (end)
+@ (until)
+@/[^+\- ]/@nil
+@ (end)
+@ (until)
+--- @(skip)
+@ (end)
+@(end)