summaryrefslogtreecommitdiffstats
path: root/diff2err.txr
blob: f82ee00441d3c7d74e567547303af4ed8416f1f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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)