Source

aurum / plugin / aurum / log.vim

   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
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
"▶1
scriptencoding utf-8
if !exists('s:_pluginloaded')
    execute frawor#Setup('0.2', {'@/table': '0.1',
                \        '@aurum/cmdutils': '0.0',
                \         '@aurum/bufvars': '0.0',
                \            '@aurum/edit': '1.0',
                \                  '@/fwc': '0.3',
                \            '@aurum/repo': '2.2',
                \             '@/commands': '0.0',
                \            '@/functions': '0.0',
                \              '@/options': '0.0',}, 0)
    call FraworLoad('@/commands')
    call FraworLoad('@/functions')
    let s:logcomp=[]
    let s:logfunc={}
    call s:_f.command.add('AuLog', s:logfunc, {'nargs': '*',
                \                           'complete': s:logcomp})
    finish
elseif s:_pluginloaded
    finish
endif
let s:F.glog={}
let s:F.graph={}
let s:F.temp={}
let s:_options={
            \'ignorefiles': {'default': [],
            \                'checker': 'list in [patch renames copies files]'},
            \'closewindow': {'default': 1, 'filter': 'bool'},
            \'procinput':   {'default': 1, 'checker': 'range 0 2'},
        \}
let s:_messages={
            \'2multl': 'Two multiline statements on one line',
            \'argmis': 'Missing argument #%u for keyword %s',
            \  'ebuf': 'Switched to another buffer: exiting',
        \}
" iterfuncs :: {fname: { "start": startfunc, "next": nextfunc }}
" startfunc (always) :: repo, opts, * → d
let s:iterfuncs={}
"▶1 graph
"▶2 graph.update_state :: graph, gstate → + graph
function s:F.graph.update_state(s)
    let self.prev_state=self.state
    let self.state=a:s
endfunction
"▶2 graph.ensure_capacity :: graph, num_columns → + graph
function s:F.graph.ensure_capacity(num_columns)
    let mdiff=(a:num_columns*2)-len(self.mapping)
    if mdiff>0
        let plist=repeat([-1], mdiff)
        let self.mapping+=plist
        let self.new_mapping+=plist
    endif
endfunction
"▶2 graph.insert_into_new_columns :: graph, hex, mapindex → mapindex + graph
function s:F.graph.insert_into_new_columns(hex, mapindex)
    let i=0
    for hex in self.new_columns
        if hex is# a:hex
            let self.mapping[a:mapindex]=i
            return a:mapindex+2
        endif
        let i+=1
    endfor
    let self.mapping[a:mapindex]=len(self.new_columns)
    call add(self.new_columns, a:hex)
    return a:mapindex+2
endfunction
"▶2 graph.update_columns :: graph → + graph
function s:F.graph.update_columns()
    let self.columns=self.new_columns
    let self.new_columns=[]
    let max_new_columns=len(self.columns)+self.num_parents
    call self.ensure_capacity(max_new_columns)
    let self.mapping_size=2*max_new_columns
    if !empty(self.mapping)
        call remove(self.mapping, 0, self.mapping_size-1)
    endif
    call extend(self.mapping, repeat([-1], self.mapping_size), 0)
    let seen=0
    let midx=0
    let is_cs_in_columns=1
    let num_columns=len(self.columns)
    for i in range(num_columns+1)
        if i==num_columns
            if seen
                break
            endif
            let is_cs_in_columns=0
            let ccshex=self.cs.hex
        else
            let ccshex=self.columns[i]
        endif
        if ccshex is# self.cs.hex
            let oldmidx=midx
            let seen=1
            let self.commit_index=i
            for parent in self.interesting_parents
                let midx=self.insert_into_new_columns(parent, midx)
            endfor
            if midx==oldmidx
                let midx+=2
            endif
        else
            let midx=self.insert_into_new_columns(ccshex, midx)
        endif
    endfor
    while self.mapping_size>1 && self.mapping[self.mapping_size-1]==-1
        let self.mapping_size-=1
    endwhile
    let self.width=(len(self.columns)+self.num_parents+(self.num_parents<1)
                \  -(is_cs_in_columns))*2
endfunction
"▶2 graph.update :: graph, cs → + graph
function s:F.graph.update(cs)
    let self.cs=a:cs
    let self.interesting_parents=filter(copy(a:cs.parents),
                \                       '!has_key(self.skipchangesets, v:val)')
    let self.num_parents=len(self.interesting_parents)
    let self.prev_commit_index=self.commit_index
    call self.update_columns()
    let self.expansion_row=0
    if self.state isnot# 'padding'
        let self.state='skip'
    elseif self.num_parents>2 &&
                \self.commit_index<(len(self.columns)-1)
        let self.state='precommit'
    else
        let self.state='commit'
    endif
endfunction
"▶2 graph.is_mapping_correct :: graph → Bool
function s:F.graph.is_mapping_correct()
    return empty(filter(self.mapping[:(self.mapping_size-1)],
                \       '!(v:val==-1 || v:val==v:key/2)'))
endfunction
"▶2 graph.pad_horizontally :: graph, chars_written → String
" XXX Replace somehow?
function s:F.graph.pad_horizontally(chars_written)
    if a:chars_written>=self.width
        return ''
    endif
    return repeat(' ', self.width-a:chars_written)
endfunction
"▶2 graph.output_padding_line :: graph → String
function s:F.graph.output_padding_line()
    let lnc=len(self.new_columns)
    return repeat('| ', lnc).self.pad_horizontally(lnc*2)
endfunction
"▶2 graph.output_skip_line :: graph → String
function s:F.graph.output_skip_line()
    call self.update_state(((self.num_parents>2 &&
                \            self.commit_index<(len(self.columns)-1))?
                \               ('precommit'):
                \               ('commit')))
    return '...'.self.pad_horizontally(3)
endfunction
"▶2 graph.output_pre_commit_line :: graph → String
function s:F.graph.output_pre_commit_line()
    let num_expansion_rows=(self.num_parents-2)*2
    let seen=0
    let r=''
    let i=-1
    for hex in self.columns
        let i+=1
        if hex is# self.cs.hex
            let seen=1
            let r.='|'.repeat(' ', self.expansion_row)
        elseif seen && self.expansion_row==0
            let r.='|\'[self.prev_state is# 'postmerge' &&
                        \self.prev_commit_index<i]
        elseif seen && self.expansion_row>0
            let r.='\'
        else
            let r.='|'
        endif
        let r.=' '
    endfor
    let r.=self.pad_horizontally(len(r))
    let self.expansion_row+=1
    if self.expansion_row>num_expansion_rows
        call self.update_state('commit')
    endif
    return r
endfunction
"▶2 graph.output_commit_char :: graph → String
function s:F.graph.output_commit_char()
    return '@o'[index(self.workcss, self.cs.hex)==-1]
endfunction
"▶2 graph.draw_octopus_merge :: graph → String
function s:F.graph.draw_octopus_merge()
    let r=''
    for i in range(((self.num_parents-2)*2)-1)
        let r.='-'
    endfor
    let r.='.'
    return r
endfunction
"▶2 graph.output_commit_line :: graph → String
function s:F.graph.output_commit_line()
    let seen=0
    let r=''
    let lcolumns=len(self.columns)
    for i in range(lcolumns+1)
        if i==lcolumns
            if seen
                break
            endif
            let ccshex=self.cs.hex
        else
            let ccshex=self.columns[i]
        endif
        if ccshex is# self.cs.hex
            let seen=1
            let r.=self.output_commit_char()
            if self.num_parents>2
                let r.=self.draw_octopus_merge()
            endif
        elseif seen && self.num_parents>2
            let r.='\'
        elseif seen && self.num_parents==2
            let r.='|\'[self.prev_state is# 'postmerge' &&
                        \self.prev_commit_index<i]
        else
            let r.='|'
        endif
        let r.=' '
    endfor
    let r.=self.pad_horizontally(len(r))
    call self.update_state(((self.num_parents>1)?
                \             ('postmerge'):
                \          ((self.is_mapping_correct())?
                \             ('padding')
                \          :
                \             ('collapsing'))))
    return r
endfunction
"▶2 graph.output_post_merge_line :: graph → String
function s:F.graph.output_post_merge_line()
    let seen=0
    let r=''
    let lcolumns=len(self.columns)
    for i in range(lcolumns+1)
        if i==lcolumns
            if seen
                break
            endif
            let ccshex=self.cs.hex
        else
            let ccshex=self.columns[i]
        endif
        if ccshex is# self.cs.hex
            let seen=1
            let r.='|'.repeat('\ ', self.num_parents-1)
        else
            let r.='|\'[seen].' '
        endif
    endfor
    let r.=self.pad_horizontally(len(r))
    call self.update_state(((self.is_mapping_correct())?
                \               ('padding'):
                \               ('collapsing')))
    return r
endfunction
"▶2 graph.output_collapsing_line :: graph → String
function s:F.graph.output_collapsing_line()
    let used_horizontal=0
    let horizontal_edge=-1
    let horizontal_edge_target=-1
    let self.new_mapping=repeat([-1], self.mapping_size)
    for [i, target] in map(self.mapping[:(self.mapping_size-1)],
                \          '[v:key, v:val]')
        if target==-1
            continue
        elseif i==target*2
            let self.new_mapping[i]=target
        elseif self.new_mapping[i-1]==-1
            let self.new_mapping[i-1]=target
            if horizontal_edge==-1
                let horizontal_edge=i
                let horizontal_edge_target=target
                let j=(target*2)+3
                while j<i-2
                    let self.new_mapping[j]=target
                    let j+=2
                endwhile
            endif
        elseif self.new_mapping[i-1]==target
        else
            let self.new_mapping[i-2]=target
            if horizontal_edge==-1
                let horizontal_edge=1
            endif
        endif
    endfor
    if self.mapping[self.mapping_size-1]==-1
        let self.mapping_size-=1
    endif
    let r=''
    for [i, target] in map(self.new_mapping[:(self.mapping_size-1)],
                \          '[v:key, v:val]')
        if target==-1
            let r.=' '
        elseif target*2==i
            let r.='|'
        elseif target==horizontal_edge_target && i!=horizontal_edge-1
            if i!=(target*2)+3
                let self.new_mapping[i]=-1
            endif
            let used_horizontal=1
            let r.='_'
        else
            if used_horizontal && i<horizontal_edge
                let self.new_mapping[i]=-1
            endif
            let r.='/'
        endif
    endfor
    let r.=self.pad_horizontally(len(r))
    let [self.mapping, self.new_mapping]=
                \[self.new_mapping, self.mapping]
    if self.is_mapping_correct()
        call self.update_state('padding')
    endif
    return r
endfunction
"▶2 graph.next_line :: graph → String
let s:gstatesfmap={
            \'padding':    s:F.graph.output_padding_line,
            \'skip':       s:F.graph.output_skip_line,
            \'precommit':  s:F.graph.output_pre_commit_line,
            \'commit':     s:F.graph.output_commit_line,
            \'postmerge':  s:F.graph.output_post_merge_line,
            \'collapsing': s:F.graph.output_collapsing_line,
        \}
function s:F.graph.next_line()
    return call(s:gstatesfmap[self.state], [], self)
endfunction
"▶2 graph.padding_line :: graph → String
function s:F.graph.padding_line()
    if self.state isnot# 'commit'
        return self.next_line()
    endif
    if self.num_parents<3
        let r.=repeat('| ', len(self.columns))
    else
        let r.=join(map(copy(self.columns),
                    \   '"|".((v:val is# "'.self.cs.hex.'")?'.
                    \           'repeat(" ", (self.num_parents-2)*2):'.
                    \           '" ")'), '')
    endif
    let r.=self.pad_horizontally(len(r))
    let self.prev_state='padding'
    return r
endfunction
"▶2 graph.show_commit :: graph → [String]
function s:F.graph.show_commit()
    let r=[]
    while 1
        try
            if self.state is# 'commit'
                break
            endif
        finally
            " XXX We need at least one iteration. :finally makes sure it will be 
            " done
            let r+=[self.next_line()]
        endtry
    endwhile
    return r
endfunction
"▶2 graph.show_remainder :: graph → [String]
function s:F.graph.show_remainder()
    let r=[]
    while self.state isnot# 'padding'
        let r+=[self.next_line()]
    endwhile
    return r
endfunction
"▶1 glog
"▶2 glog.utfedges
function s:F.glog.utfedges(seen, hex, parents)
    let nodeidx=index(a:seen, a:hex)
    if nodeidx==-1
        let nodeidx=len(a:seen)
        call add(a:seen, a:hex)
    endif
    let knownparents=[]
    let newparents=[]
    for parenthex in a:parents
        call add(((index(a:seen, parenthex)==-1)?
                    \   (newparents):
                    \   (knownparents)),
                    \parenthex)
    endfor
    let ncols=len(a:seen)
    call remove(a:seen, nodeidx)
    call extend(a:seen, newparents, nodeidx)
    let edges=map(knownparents, '['.nodeidx.', index(a:seen, v:val)]')
    if !empty(newparents)
        call add(edges, [nodeidx, nodeidx])
        if len(newparents)>1
            call add(edges, [nodeidx, nodeidx+1])
        endif
    endif
    let nmorecols=len(a:seen)-ncols
    return [nodeidx, edges, ncols, nmorecols]
endfunction
"▶2 glog.fix_long_right_edges
function s:F.glog.fix_long_right_edges(edges)
    call map(a:edges, '((v:val[1]>v:val[0])?([v:val[0], v:val[1]+1]):(v:val))')
endfunction
"▶2 glog.get_nodeline_edges_tail
function s:F.glog.get_nodeline_edges_tail(node_index, p_node_index, n_columns,
            \                             n_columns_diff, p_diff, fix_tail)
    if a:fix_tail && a:n_columns_diff==a:p_diff && a:n_columns_diff!=0
        if a:n_columns_diff==-1
            let start=max([a:node_index+1, a:p_node_index])
            return repeat(['|', ' '], (start-a:node_index-1))+
                        \repeat(['/', ' '], (a:n_columns-start))
        else
            return repeat(['\', ' '], (a:n_columns-a:node_index-1))
        endif
    else
        return repeat(['|', ' '], (a:n_columns-a:node_index-1))
    endif
endfunction
"▶2 glog.draw_edges
function s:F.glog.draw_edges(edges, nodeline, interline)
    for [start, end] in a:edges
        if start==end+1
            let a:interline[2*end   + 1]='/'
        elseif start==end-1
            let a:interline[2*start + 1]='\'
        elseif start==end
            let a:interline[2*start    ]='|'
        else
            let a:nodeline[2*end]='+'
            if start>end
                let [start, end]=[end, start]
            endif
            for i in range(2*start+1, 2*end-1)
                if a:nodeline[i] isnot# '+'
                    let a:nodeline[i]='-'
                endif
            endfor
        endif
    endfor
endfunction
"▶2 glog.get_padding_line
function s:F.glog.get_padding_line(ni, n_columns, edges)
    let c=' '
    if index(a:edges, [a:ni, a:ni-1])!=-1 || index(a:edges, [a:ni, a:ni])!=-1
        let c='|'
    endif
    return repeat(['|', ' '], a:ni)+
                \[c, ' ']+
                \repeat(['|', " "], (a:n_columns-a:ni-1))
endfunction
"▶2 glog.addlines
function s:F.glog.addlines(special, lnum)
    let mapexpr='[v:val[0]+'.a:lnum.']+v:val[1:]'
    call map(a:special, 'v:key[-2:] is? "_r"?'.
                \             'map(v:val, '.string(mapexpr).'):'.
                \             mapexpr)
    return a:special
endfunction
"▶2 glog.addcols
function s:F.glog.addcols(special, cnum)
    let mapexpr='[v:val[0], v:val[1]+'.a:cnum.']+v:val[2:]'
    call map(a:special, 'v:key[-2:] is? "_r"?'.
                \             'map(v:val, '.string(mapexpr).'):'.
                \             mapexpr)
    return a:special
endfunction
"▶2 glog.utf
function s:F.glog.utf(state, type, char, text, coldata)
    let [idx, edges, ncols, coldiff]=a:coldata
    let add_padding_line=0
    let lnum = (has_key(a:text, 'text') ? len(a:text.text) : 0)
    if coldiff==-1
        call s:F.glog.fix_long_right_edges(edges)
        if lnum>2
            let add_padding_line=!empty(map(filter(copy(edges),
                        \                          '(v:val[0]+1)<v:val[1]'),
                        \                   'v:val[0]'))
        endif
    endif
    let fix_nodeline_tail = (lnum<=2 && add_padding_line)
    let shift_interline=repeat(['|', ' '], idx)
    let nodeline=copy(shift_interline)+
                \[a:char, ' ']+
                \s:F.glog.get_nodeline_edges_tail(idx,     a:state[1], ncols,
                \                                 coldiff, a:state[0],
                \                                 fix_nodeline_tail)
    if coldiff==-1
        let n_spaces=1
        let edge_ch='/'
    elseif coldiff==0
        let n_spaces=2
        let edge_ch='|'
    else
        let n_spaces=3
        let edge_ch='\'
    endif
    let shift_interline+=repeat([' '], n_spaces)+
                \        repeat([edge_ch, ' '], (ncols-idx-1))
    call s:F.glog.draw_edges(edges, nodeline, shift_interline)
    let lines=[nodeline]
    if add_padding_line
        call add(lines, s:F.glog.get_padding_line(idx, ncols, edges))
    endif
    if has_key(a:text, 'skip')
        let joined_sil=join(shift_interline, '')
        let joined_nl=substitute(join(nodeline, ''), '\V'.a:char, '|', '')
        let a:text.text=[]
        if joined_nl!~#'\v^[o| ]+$'
            let a:text.text+=[substitute(joined_nl,'\v\-@<=\||\|\-@=','+','')]
        endif
        if joined_sil!~#'\v^[| ]+$' && joined_sil isnot# joined_nl
            let a:text.text+=[joined_sil]
        endif
        return a:text
    else
        call add(lines, shift_interline)
    endif
    let ltdiff=lnum-len(lines)
    if ltdiff>0
        let extra_interline=repeat(['|', ' '], ncols+coldiff)
        call extend(lines, repeat([extra_interline], ltdiff))
    else
        call extend(a:text.text, repeat([''], -ltdiff))
    endif
    let indentation_level=2*max([ncols, ncols+coldiff])
    let a:state[0]=coldiff
    let a:state[1]=idx
    call map(lines, 'printf("%-*s ", indentation_level, join(v:val, ""))')
    let curspecial=a:text.special
    let shiftlen=len(lines[0])
    call s:F.glog.addcols(a:text.special, shiftlen)
    let a:text.block_r=[[0, shiftlen],
                \       [len(a:text.text)-1,
                \        max(map(copy(lines), 'len(v:val)'))]]
    let curspecial.bullet=[0, stridx(lines[0], a:char), a:char]
    call map(a:text.text, 'lines[v:key].v:val')
    return a:text
endfunction
"▶2 glog.graph_init :: repo, [cs] → graph
let s:defgraph={
            \'cs':                0,
            \'num_parents':       0,
            \'expansion_row':     0,
            \'state':             'padding',
            \'prev_state':        'padding',
            \'commit_index':      0,
            \'prev_commit_index': 0,
            \'columns':           [],
            \'new_columns':       [],
            \'mapping':           [],
            \'new_mapping':       [],
            \'mapping_size':      0,
            \'skipchangesets':    {},
        \}
function s:F.glog.graph_init(showparents, opts)
    let graph=deepcopy(s:defgraph)
    let graph.repo=a:opts.repo
    let graph.workcss=a:showparents
    let graph.skipchangesets=a:opts.skipchangesets
    call extend(graph, s:F.graph)
    return graph
endfunction
"▶2 glog.show_log :: graph, cs, Text → Text
function s:F.glog.show_log(graph, cs, text)
    let lines=((a:graph.cs is 0)?([]):(a:graph.show_remainder()))
    call a:graph.update(a:cs)
    let lines+=a:graph.show_commit()
    let collen=len(lines[-1])
    let a:text.block_r[0][1]+=collen
    let a:text.block_r[1][1]+=collen
    call s:F.glog.addcols(a:text.special, collen)
    let lines[-1]=lines[-1][:-2].' '.get(a:text.text, 0, '')
    let cchar=a:graph.output_commit_char()
    let bidx=stridx(lines[-1], cchar)
    if bidx!=-1
        let a:text.special.bullet=[0, bidx, cchar]
    endif
    for line in a:text.text[1:]
        let lines+=[a:graph.next_line()[:-2].' '.line]
    endfor
    let a:text.text=lines
    return a:text
endfunction
"▶2 s:DateCmp :: cs, cs → -1|0|1
function s:DateCmp(a, b)
    let a=a:a.time
    let b=a:b.time
    return ((a==b)?(0):((a>b)?(-1):(1)))
endfunction
let s:_functions+=['s:DateCmp']
"▶2 glog.graphlog
function s:F.glog.graphlog(repo, opts, csiterfuncs, bvar, read)
    "▶3 Get grapher
    if get(a:repo, 'has_octopus_merges', 1)
        let literfuncs=s:iterfuncs.git
    else
        let literfuncs=s:iterfuncs.hg
    endif
    "▶3 Initialize variables
    let haslimit=(has_key(a:opts, 'limit') && a:opts.limit)
    if haslimit
        let limit=a:opts.limit
    endif
    let foundfirst=0
    let csbuf=[]
    let reqprops=keys(a:opts.reqs)
    call filter(reqprops, 'index(a:repo.initprops, v:val)==-1')
    let a:opts.skipchangesets={}
    "▶3 Initialize variables not required for reading
    if !a:read
        let specials={}
        let rectangles=[]
        let csstarts={}
        let r=[]
        let a:bvar.rectangles=rectangles
        let a:bvar.specials=specials
        let a:bvar.csstarts=csstarts
        let didredraw=0
        let procinput=a:bvar.procinput
        let lastw0line=-1
        let buf=bufnr('%')
        let firstcs=1
        let lastline=0
    endif
    "▶3 Initialize iterator functions
    let ld=literfuncs.start(a:repo,a:opts,[a:repo.functions.getworkhex(a:repo)])
    let csd=a:csiterfuncs.start(a:repo, a:opts)
    let checkd=s:iterfuncs.check.start(a:repo, a:opts)
    "▲3
    while 1 && (!haslimit || limit)
        let cs=a:csiterfuncs.next(csd)
        if cs is 0 "▶3
            return r
        endif "▲3
        let skip=!s:iterfuncs.check.check(checkd, cs)
        "▶3 Add cs to skipchangesets or get its properties
        if skip
            let a:opts.skipchangesets[cs.hex]=cs
        else
            call map(copy(reqprops),
                        \'a:repo.functions.getcsprop(a:repo, cs, v:val)')
            let foundfirst=1
            if haslimit
                let limit-=1
            endif
        endif
        "▲3
        if foundfirst
            let csbuf+=[cs]
            if !skip
                for cs in csbuf
                    let [lines, rectangle, special]=literfuncs.proccs(ld, cs)
                    "▶3 Add various information to bvar
                    if !a:read && rectangle isnot 0
                        let rectangle[0][0]=lastline
                        let lastline+=len(lines)
                        let rectangle[1][0]=lastline-1
                        let rectangle+=[cs.hex]
                        call add(rectangles, rectangle)
                        let csstarts[cs.hex]=rectangle[0][0]
                        if special isnot 0
                            let specials[cs.hex]=special
                        endif
                    endif
                    "▲3
                    "▶3 Add lines to returned list if reading
                    if a:read
                        let r+=lines
                    "▶3 Add lines to buffer if not, process user input
                    else
                        "▶4 Add lines to buffer
                        if firstcs
                            call setline(1, lines)
                            let firstcs=0
                        else
                            call append('$', lines)
                        endif
                        "▶4 Process user input
                        if didredraw
                            if procinput && getchar(1)
                                let input=''
                                while getchar(1)
                                    let char=getchar()
                                    if type(char)==type(0)
                                        let input.=nr2char(char)
                                    else
                                        let input.=char
                                    endif
                                endwhile
                                execute 'normal' input
                                if bufnr('%')!=buf
                                    if bufexists(buf)
                                        execute 'silent bwipeout!' buf
                                    endif
                                    call s:_f.warn('ebuf')
                                    return []
                                endif
                                let lw0=line('w0')
                                if lw0!=lastw0line
                                    redraw
                                    let didredraw=(line('$')>=lw0+winheight(0))
                                    let lastw0line=lw0
                                endif
                            endif
                        "▶4 Redraw if necessary
                        elseif line('$')>=line('w0')+winheight(0)
                            redraw
                            let didredraw=1
                            let lastw0line=line('w0')
                        endif
                        "▲4
                    endif
                    "▲3
                    unlet rectangle special
                endfor
                call remove(csbuf, 0, -1)
            endif
        endif
        unlet cs
    endwhile
    return r
endfunction
"▶1 iterfuncs: loggers
"▶2 iterfuncs.git
" TODO Fix skipping changesets if possible
let s:iterfuncs.git={}
function s:iterfuncs.git.start(repo, opts, ...)
    let graph=s:F.glog.graph_init(get(a:000, 0, []), a:opts)
    return {'graph': graph, 'opts': a:opts}
endfunction
function s:iterfuncs.git.proccs(d, cs)
    if has_key(a:d.opts.skipchangesets, a:cs.hex)
        return [[], 0, 0]
    endif
    let text=a:d.opts.templatefunc(a:cs, a:d.opts)
    let text.block_r=[[0, 0],
                \     [len(text.text)-1,
                \      max(map(copy(text.text), 'len(v:val)'))]]
    let text=s:F.glog.show_log(a:d.graph, a:cs, text)
    return [text.text, text.block_r, text.special]
endfunction
"▶2 iterfuncs.hg
let s:iterfuncs.hg={}
function s:iterfuncs.hg.start(repo, opts, ...)
    return {'seen': [], 'state': [0, 0], 'opts': a:opts,
                \'showparents': get(a:000, 0, [])}
endfunction
function s:iterfuncs.hg.proccs(d, cs)
    let char=((index(a:d.showparents, a:cs.hex)==-1)?('o'):('@'))
    if has_key(a:d.opts.skipchangesets, a:cs.hex)
        let text={'skip': 1}
        let skip=1
    else
        let text=a:d.opts.templatefunc(a:cs, a:d.opts)
        let skip=0
    endif
    call s:F.glog.utf(a:d.state, 'C', char, text,
                \     s:F.glog.utfedges(a:d.seen, a:cs.hex, a:cs.parents))
    if !has_key(text, 'text') || empty(text.text)
        return [[], 0, 0]
    endif
    if !skip
        return [text.text, text.block_r, text.special]
    else
        return [text.text, 0, 0]
    endif
endfunction
"▶1 temp
"▶2 s:templates
let s:templates={
            \'default': "Changeset $rev#suf:\:#$hex$branch#hide,pref: (branch ,suf:)#\n".
            \           "Commited $time by $user\n".
            \           "Tags: $tags\n".
            \           "Bookmarks: $bookmarks\n".
            \           "Files: $changes\n".
            \           "Renamed $renames\n".
            \           "Copied $copies\n".
            \           "$hide#@# $description\n".
            \           "$hide#$#$stat\n".
            \           "$hide#:#$patch\n".
            \           "$empty",
            \'hgdef':   "changeset:   $rev#suf:\:#$hex\n".
            \           "branch:      $branch\n".
            \           "tags:        $tags\n".
            \           "bookmarks:   $bookmarks\n".
            \           "user:        $user\n".
            \           "date:        $time#%a %b %d %H:%M:%S %Y#\n".
            \           "files:       $changes# #\n".
            \           "summary:     $summary\n".
            \           "$hide#$#$stat\n".
            \           "$hide#:#$patch\n".
            \           "$empty",
            \'hgdescr': "changeset:   $rev#suf:\:#$hex\n".
            \           "branch:      $branch\n".
            \           "tags:        $tags\n".
            \           "bookmarks:   $bookmarks\n".
            \           "user:        $user\n".
            \           "date:        $time#%a %b %d %H:%M:%S %Y#\n".
            \           "files:       $changes# #\n".
            \           "description:\n".
            \           "$description\n".
            \           "$hide#$#$stat\n".
            \           "$hide#:#$patch\n".
            \           "$empty",
            \'compact': "$rev$tags#pref:[,suf:]#   $hex $time#%Y-%m-%d %H:%M# $user\n".
            \           "  $summary\n".
            \           "$hide#$# $stat\n".
            \           "$hide#:#$patch\n".
            \           "$empty",
            \'cdescr':  "$rev$tags#pref:[,suf:]#   $hex $time#%Y-%m-%d %H:%M# $user\n".
            \           "  $description\n".
            \           "$hide#$# $stat\n".
            \           "$hide#:#$patch\n".
            \           "$empty",
            \'git':     "commit $hex\n".
            \           "Author: $user\n".
            \           "Date:   $time#%a %b %d %T %Y#\n".
            \           "$empty\n".
            \           "    $description\n".
            \           "$empty\n".
            \           "$hide#$# $stat\n".
            \           "$hide#:#$patch",
            \'gitoneline': "$hex $summary\n".
            \              "$hide#$# $stat\n".
            \              "$hide#:#$patch",
        \}
"▶2 s:kwexpr
" TODO Add bisection status
let s:kwexpr={}
let s:kwexpr.hide        = [0, '@0@', 0]
let s:kwexpr.empty       = [0, '@@@']
let s:kwexpr.hex         = [0, '@@@']
let s:kwexpr.branch      = [0, '@@@', 'keep']
let s:kwexpr.user        = [0, '@@@']
let s:kwexpr.rev         = [0, '@@@', 'ignore']
let s:kwexpr.time        = [0, 'strftime(@0@, @@@)', '%d %b %Y %H:%M']
let s:kwexpr.parents     = [0, 'join(@@@)']
let s:kwexpr.children    = [0, 'join(@@@)']
let s:kwexpr.tags        = [0, 'join(@@@, @0@)', ', ']
let s:kwexpr.bookmarks   = [0, 'join(@@@, @0@)', ', ']
let s:kwexpr.summary     = [0, '@@@']
" TODO Add tab expansion
let s:kwexpr.description = [1, 'split(@@@, "\n")']
let s:kwexpr.patch       = [1, '@@@']
let s:kwexpr.stat        = [2, 's:F.temp.stat(@@@, a:cs.files, @<@)']
let s:kwexpr.files       = [2, 's:F.temp.multlfmt(@@@, a:cs.files, '.
            \                                    '@<@, @0@, '.
            \                                    '"file")', ', ']
let s:kwexpr.changes     = [2, 's:F.temp.multlfmt(@@@, a:cs.changes, '.
            \                                    '@<@, @0@, '.
            \                                    '"file")', ', ']
let s:kwexpr.renames     = [2, 's:F.temp.renames(@@@, a:cs.files, '.
            \                                   '@<@, @0@)', ' to ']
let s:kwexpr.copies      = [2, 's:F.temp.renames(@@@, a:cs.files, '.
            \                                   '@<@, @0@)', ' to ']
let s:kwmarg={}
let s:kwmarg.summary='matchstr(a:cs.description, "\\\\v^[^\\n]*")'
let s:kwmarg.stat='a:opts.repo.functions.getstats(a:opts.repo, diff, a:opts)'
let s:kwmarg.patch='diff'
let s:kwmarg.empty=''''''
let s:kwpempt=['parents', 'children', 'tags', 'bookmarks']
let s:kwreg={
            \'rev' : '\d\+',
            \'parents': '\v\x{12,}( \x{12,})?',
            \'children': '\v\x{12,}( \x{12,})*',
        \}
let s:kwreqseqkw=['hex', 'branch', 'user', 'rev', 'time', 'parents', 'children',
            \     'tags', 'bookmarks', 'description', 'files', 'changes']
let s:kwreqs = {'stat': {'files': 1},
            \'renames': {'files': 1, 'renames': 1},
            \ 'copies': {'files': 1, 'copies': 1},
            \}
call map(s:kwreqseqkw, 'extend(s:kwreqs, {v:val : {v:val : 1}})')
unlet s:kwreqseqkw
"▶2 temp.stat :: stats, idxlist, linebeg → ([String], sp)
function s:F.temp.stat(stats, idxlist, linebeg)
    let sitems=map(sort(keys(a:stats.files)),
                \  '[v:val, '.
                \  'a:stats.files[v:val].insertions, '.
                \  'a:stats.files[v:val].deletions, '.
                \  's:_r.strdisplaywidth(v:val), '.
                \  'index(a:idxlist, v:val)]')
    let maxflen=max(map(copy(sitems), 'v:val[3]'))
    let maxilen=len(a:stats.insertions)
    let maxdlen=len(a:stats.deletions)
    let rt=[]
    let special={}
    for [file, ins, del, flen, fi] in sitems
        if fi!=-1
            let special['file00'.fi.'_l']=[len(rt), 0]
        endif
        let rt+=['  '.file.repeat(' ', maxflen-flen+1).'|'.
                    \ repeat(' ', maxilen-len(ins)+1).ins.
                    \ repeat(' ', maxdlen-len(del)+1).del]
    endfor
    let special.stat_R=[[0, 0], [len(rt), 0]]
    let rt+=[printf('%u files changed, %u insertions, %u deletions',
                \   len(keys(a:stats.files)),
                \   a:stats.insertions, a:stats.deletions)]
    call map(rt, 'a:linebeg.v:val')
    return [rt, special]
endfunction
"▶2 temp.renames :: renames, idxlist, linebeg, rensep → ([String], sp)
function s:F.temp.renames(renames, idxlist, linebeg, rensep)
    let rt=[]
    let special={}
    let rsl=len(a:rensep)
    for [cur, old] in items(filter(copy(a:renames), 'type(v:val)=='.type('')))
        let cl=len(rt)
        let fl=len(cur)
        let ol=len(old)
        let rt+=[a:linebeg.old.a:rensep.cur]
        let ll=len(rt[-1])
        let fi=index(a:idxlist, cur)
        let special['file0'.fi.'_r']=[[cl, ll-fl], [cl, ll-1]]
        let special['oldname'.fi.'_r']=[[cl, ll-fl-rsl-ol], [cl, ll-fl-rsl]]
        let special['rename'.fi.'_l']=[cl, 0]
    endfor
    return [rt, special]
endfunction
"▶2 temp.multlfmt :: list, idxlist, linebeg, itemsep, itemname → ([String], sp)
function s:F.temp.multlfmt(list, idxlist, linebeg, itemsep, itemname)
    let rt=[a:linebeg]
    let special={}
    let winwidth=winwidth(0)-10
    let linewidth=s:_r.strdisplaywidth(a:linebeg)
    let curfilenum=0
    let ii=-1
    let seplen=len(a:itemsep)
    for item in a:list
        let iwidth=s:_r.strdisplaywidth(item, linewidth)
        if curfilenum && iwidth+linewidth>winwidth
            let rt+=[a:linebeg.item.a:itemsep]
            let linewidth=s:_r.strdisplaywidth(rt[-1])
            let curfilenum=0
        else
            let rt[-1].=item.a:itemsep
            let linewidth+=iwidth
        endif
        let cl=len(rt)-1
        let ilen=len(item)
        let linelen=len(rt[-1])
        if a:list is a:idxlist
            let ii+=1
        else
            let ii=index(a:idxlist, item)
        endif
        let special[a:itemname.ii.'_r']=[[cl, linelen-ilen-seplen],
                    \                    [cl, linelen-seplen]]
        let curfilenum+=1
    endfor
    call map(rt, 'v:val[:-'.(seplen+1).']')
    return [rt, special]
endfunction
"▶2 temp.parsearg :: String → dict
function s:F.temp.parsearg(str)
    let s=a:str
    let r={}
    let i=0
    while !empty(s)
        let key=matchstr(s, '\v^%(expr|synreg|flbeg|pref|suf):')[:-2]
        if empty(key)
            let arg=matchstr(s, '\v(\\.|[^,])*')
            let s=s[len(arg)+1:]
            let r[i]=substitute(arg, '\v\\([\\:#,])', '\1', 'g')
            let i+=1
            continue
        endif
        let s=s[len(key)+1:]
        let arg=matchstr(s, '\v(\\.|[^,])*')
        let s=s[len(arg)+1:]
        let r[key]=substitute(arg, '\v\\([\\:#,])', '\1', 'g')
    endwhile
    return r
endfunction
"▶2 temp.parse :: String → template
let s:parsecache={}
function s:F.temp.parse(str)
    if has_key(s:parsecache, a:str)
        return s:parsecache[a:str]
    endif
    let s=a:str
    let r=[[[]]]
    let lr=r[-1]
    let t=lr[0]
    while !empty(s)
        let lit=matchstr(s, "\\v^[^$\n]*")
        let t+=[lit]
        let s=s[len(lit):]
        let c=s[0]
        let s=s[1:]
        if empty(s)
            break
        endif
        if c is# "\n"
            let r+=[[[]]]
            let lr=r[-1]
            let t=lr[0]
            continue
        endif
        let kw=matchstr(s, '\v^\w+')
        let s=s[len(kw):]
        if !has_key(s:kwexpr, kw)
            if len(t)>1
                let t[-2].=remove(t, -1)
            endif
            continue
        endif
        let astr=matchstr(s, '\v^\#(\\.|[^#])+\#')
        let arg=s:F.temp.parsearg(astr[1:-2])
        if s:kwexpr[kw][0] && !empty(filter(lr[1:], 's:kwexpr[v:val[0]][0]'))
            call s:_f.throw('2multl')
        endif
        let s=s[len(astr):]
        let lr+=[[kw, arg]]
    endwhile
    let s:parsecache[a:str]=r
    return r
endfunction
"▶2 temp.skip
function s:F.temp.skip(meta, opts)
    for kw in map(copy(a:meta), 'v:val[0]')
        if (!get(a:opts, 'showfiles', 0) &&
                    \   (kw is# 'files' || kw is# 'changes')) ||
                    \(!get(a:opts, 'showrenames', 0) && kw is# 'renames') ||
                    \(!get(a:opts, 'showcopies',  0) && kw is# 'copies')  ||
                    \(!get(a:opts, 'patch',       0) && kw is# 'patch')   ||
                    \(!get(a:opts, 'stat',        0) && kw is# 'stat')
            return 1
        endif
    endfor
    return 0
endfunction
"▶2 temp.compile :: template, opts → Fref
let s:compilecache={}
function s:F.temp.compile(template, opts)
    "▶3 Cache
    let cid=''
    for o in ['patch', 'stat', 'showfiles', 'showrenames', 'showcopies']
        let cid.=get(a:opts, o, 0)
    endfor
    let cid.=has_key(a:opts, 'files')
    let cid.=string(a:template)[2:-3]
    if has_key(s:compilecache, cid)
        return s:compilecache[cid]
    endif
    "▶3 Define variables
    let func=['function d.template(cs, opts)',
                \'let r={"text": [], "special": {}}',
                \'let text=r.text',
                \'let special=r.special',]
    let hasfiles=has_key(a:opts, 'files')
    if hasfiles
        let func+=['let files=a:opts.csfiles[a:cs.hex]']
    endif
    let hasrevisions=get(a:opts.repo, 'hasrevisions', 1)
    if get(a:opts, 'patch', 0) || get(a:opts, 'stat', 0)
        let filesarg=((hasfiles && !has_key(a:opts.ignorefiles, 'patch'))?
                    \   ('files'):
                    \   ('[]'))
        let func+=['if !empty(a:cs.parents)',
                    \'let diff=a:opts.repo.functions.diff(a:opts.repo, '.
                    \                                    'a:cs.hex, '.
                    \                                    'a:cs.parents[0], '.
                    \                                     filesarg.', '.
                    \                                    'a:opts)',
                    \'endif']
    endif
    let reqs={}
    "▲3
    for [lit; meta] in a:template
        if s:F.temp.skip(meta, a:opts)
            continue
        endif
        let addedif=0
        let lmeta=len(meta)
        if lmeta
            let kw=meta[0][0]
            let lkw=meta[-1][0]
        endif
        "▶3 Skip line under certain conditions
        if !lmeta
        elseif lmeta==1 && !s:kwexpr[meta[0][0]][0]
            if index(s:kwpempt, kw)!=-1
                let addedif=1
                let func+=['if !empty(a:cs.'.kw.')']
            elseif kw is# 'branch'
                let addedif=1
                let func+=['if a:cs.branch isnot# "default"']
            elseif kw is# 'rev' && !hasrevisions
                continue
            endif
            let func+=['let special.'.meta[0][0].'_l=[len(text), 0]']
        elseif lkw is# 'patch' || lkw is# 'stat'
            let addedif=1
            let func+=['if exists("diff")']
        elseif lkw is# 'files' || lkw is# 'changes'
            let addedif=1
            let func+=['if !empty(a:cs.'.kw.')']
        endif
        "▲3
        let func+=['let text+=[""]']
        let i=-1
        for str in lit
            let i+=1
            if !empty(str)
                let func+=['let text[-1].='.string(str)]
            endif
            if lmeta>i
                "▶3 Define variables
                let [kw, arg]=meta[i]
                let ke=s:kwexpr[kw]
                "▶3 Get expression
                if has_key(arg, 'expr')
                    let expr=arg.expr
                else
                    let expr=ke[1]
                endif
                "▶4 Determine what should be used as {word} argument
                if has_key(s:kwmarg, kw)
                    let marg=s:kwmarg[kw]
                elseif hasfiles && (kw is# 'files' || kw is# 'changes') &&
                            \!has_key(a:opts.ignorefiles, 'files')
                    let marg='files'
                elseif hasfiles && (kw is# 'renames' || kw is# 'copies') &&
                            \!has_key(a:opts.ignorefiles, kw)
                    let marg='filter(copy(a:cs.'.kw.'), '.
                                \   '"index(files, v:val)!=-1")'
                else
                    let marg='a:cs.'.kw
                endif
                "▲4
                let expr=substitute(expr, '@@@', marg, 'g')
                "▶3 Get positional parameters if required
                let j=0
                for a in ke[2:]
                    let s=get(arg, j, a)
                    let arg[j]=s
                    if s is 0
                        call s:_f.throw('argmis', j, kw)
                    endif
                    let expr=substitute(expr, '@'.j.'@',
                                \       escape(string(s), '&~\'), 'g')
                    let j+=1
                endfor
                "▶3 Skip meta if required
                if kw is# 'rev' && !hasrevisions && arg.0 isnot# 'keep'
                    continue
                endif
                "▶3 Add requirements information
                if has_key(s:kwreqs, kw)
                    call extend(reqs, s:kwreqs[kw])
                endif
                "▶3 Add complex multiline statement
                let addedif2=0
                if ke[0]==2
                    "▶4 Add missing if’s
                    if !addedif
                        if kw is# 'stat'
                            let addedif2=1
                            let func+=['if exists("diff")']
                        elseif kw is# 'files' || kw is# 'changes'
                            let addedif2=1
                            let func+=['if !empty(a:cs.'.kw.')']
                        endif
                    endif
                    "▲4
                    let expr=substitute(expr, '@<@', 'lstr', 'g')
                    let func+=['let lstr=remove(text, -1)',
                                \'let [ntext, sp]='.expr]+
                                \   (has_key(arg, 'flbeg')?
                                \       ['let ntext[0]='.string(arg.flbeg).
                                \                                  '.ntext[0]']:
                                \       [])+[
                                \'call s:F.glog.addlines(sp, len(text))',
                                \'let text+=ntext',
                                \'call extend(special, sp)']
                "▶3 Add simple multiline statement
                elseif ke[0]
                    "▶4 Add missing if’s
                    if !addedif && kw is# 'patch'
                        let addedif2=1
                        let func+=['if exists("diff")']
                    endif
                    "▲4
                    let func+=['let ntext='.expr,
                                \'call map(ntext, '.
                                \         'string(remove(text, -1)).".v:val")']+
                                \   (has_key(arg, 'flbeg')?
                                \       ['let ntext[0]='.string(arg.flbeg).
                                \                                  '.ntext[0]']:
                                \       [])+[
                                \'let special.'.kw.'_R=[[len(text), 0], '.
                                \                '[len(text)+len(ntext)-1, 0]]',
                                \'let text+=ntext']
                "▶3 Add single-line statement
                else
                    if kw is# 'branch' && arg.0 isnot# 'keep'
                        let func+=['if a:cs.branch isnot# "default"']
                    endif
                    let func+=['let estr='.expr]
                    "▶4 Add suffix or prefix
                    if index(s:kwpempt, kw)!=-1
                        let condition='!empty(estr)'
                    elseif kw is# 'branch'
                        let condition='estr isnot# "default"'
                    elseif kw is# 'rev'
                        let condition=0
                    endif
                    if exists('condition')
                        let addif=(condition isnot 0) &&
                                    \(has_key(arg, 'pref') ||
                                    \ has_key(arg, 'suf'))
                        if addif
                            let func+=['if '.condition]
                        endif
                        if has_key(arg, 'pref')
                            let func+=['let estr='.string(arg.pref).'.estr']
                        endif
                        if has_key(arg, 'suf')
                            let func+=['let estr.='.string(arg.suf)]
                        endif
                        if addif
                            let func+=['endif']
                        endif
                    endif
                    "▲4
                    let func+=['let special.'.kw.'_r='.
                                \  '[[len(text)-1, len(text[-1])], '.
                                \   '[len(text)-1, len(text[-1])+len(estr)-1]]',
                                \'let text[-1].=estr',]
                    if kw is# 'branch' && arg.0 isnot# 'keep'
                        let func+=['endif']
                    endif
                endif
                "▲3
                if addedif2
                    let func+=['endif']
                endif
            endif
        endfor
        if addedif
            let func+=['endif']
        endif
    endfor
    let func+=['return r',
                \'endfunction']
    let d={}
    execute join(func, "\n")
    let r=[reqs, d.template]
    let s:compilecache[cid]=r
    return r
endfunction
"▶2 temp.addgroup
function s:F.temp.addgroup(r, nlgroups, group)
    let i=0
    for [line, lnr] in filter(map(copy(a:r), '[v:val, v:key]'),
                \             'stridx(",=", v:val[0][-1:])!=-1')
        let a:r[lnr].=a:group
        let i+=1
    endfor
    if !i
        call add(a:nlgroups, a:group)
    endif
endfunction
"▶2 temp.syntax :: template, opts → [VimCommand] + :syn
"▶3 Some globals
let s:syncache={}
let s:noargtimereg='\v\d\d \S+ \d{4,} \d\d:\d\d'
let s:ukntkws=['c', 'x', 'X', '+']
let s:timekwregs={
            \'a': '\S\{1,3}',
            \'A': '\S\+',
            \'b': '\S\{1,3}',
            \'B': '\S\+',
            \'C': '\d\d',
            \'d': '\d\d',
            \'D': '\d\d\/\d\d\/\d\d',
            \'e': '\[1-3 ]\d',
            \'F': '\d\{4,}-\d\d-\d\d',
            \'G': '\d\{4,}',
            \'g': '\d\d',
            \'h': '\S\{1,3}',
            \'H': '\d\d',
            \'I': '\d\d',
            \'j': '\d\{3}',
            \'k': '\[12 ]\d',
            \'l': '\[1 ]\d',
            \'m': '\d\d',
            \'M': '\d\d',
            \'n': '\n',
            \'p': '\[AP]M',
            \'P': '\[ap]m',
            \'r': '\d\d:\d\d:\d\d \[AP]M',
            \'R': '\d\d:\d\d',
            \'s': '\d\+',
            \'S': '\d\d',
            \'t': '\t',
            \'T': '\d\d:\d\d:\d\d',
            \'u': '\[1-7]',
            \'U': '\d\d',
            \'V': '\d\d',
            \'w': '\[0-6]',
            \'W': '\d\d',
            \'y': '\d\d',
            \'Y': '\d\{4,}',
            \'z': '\[+\-]\d\{4}',
            \'Z': '\S\{3}',
            \'%': '%',
        \}
"▲3
function s:F.temp.syntax(template, opts)
    "▶3 Cache
    let cid=string(a:opts.templatefunc)[10:-3]
    if has_key(s:syncache, cid)
        return s:syncache[cid]
    endif
    "▶3 Define variables
    let r=[]
    let topgroups=[]
    let hasrevisions=get(a:opts.repo, 'hasrevisions', 1)
    "▲3
    let r+=['syn match auLogFirstLineStart =\v^[^ ]*[@o][^ ]* = '.
                \'skipwhite nextgroup=']
    let i=0
    let nlgroups=[]
    for [lit; meta] in a:template
        if s:F.temp.skip(meta, a:opts)
            continue
        endif
        let lmeta=len(meta)
        let llit=len(lit)
        let j=0
        let hasmult=0
        for str in lit
            if !empty(str)
                if lmeta>j
                    let skname='SkipBefore_'.meta[j][0]
                else
                    let skname='Text'.i
                endif
                let skname='auLog'.skname
                call s:F.temp.addgroup(r, nlgroups, skname)
                let r+=['syn match '.skname.' ']
                if lmeta>j
                    let r[-1].='/\V'.escape(str, '\/').'/'
                else
                    let r[-1].='/\v.*/'
                endif
                let r[-1].=' contained nextgroup='
            endif
            if lmeta>j
                let [kw, arg]=meta[j]
                if s:kwexpr[kw][0]
                    let hasmult=1
                endif
                if kw is# 'empty' || (kw is# 'rev' && !hasrevisions &&
                            \         arg.0 isnot# 'keep')
                    let r[-1]=substitute(r[-1], '\v\w+$', '', '')
                elseif has_key(arg, 'synreg')
                    call s:F.temp.addgroup(r, nlgroups, 'auLog_'.kw)
                    let r+=['syn match auLog_'.kw.' /'.arg.synreg.'/ '.
                                \'contained nextgroup=']
                elseif kw is# 'hex'
                    call s:F.temp.addgroup(r, nlgroups, 'auLogHexStart')
                    let r+=['syn match auLogHexStart /\v\x{12}/ contained'.
                                \' nextgroup=auLogHexEnd',
                            \'syn match auLogHexEnd /\v\x+/ contained '.
                            \   (has('conceal')?('conceal'):('')).' nextgroup=']
                elseif kw is# 'patch'
                    call s:F.temp.addgroup(r, nlgroups,
                                \'auLogPatchAdded,auLogPatchRemoved,'.
                                \'auLogPatchFile,auLogPatchNewFile,'.
                                \'auLogPatchOldFile,auLogPatchOther,'.
                                \'auLogPatchNotModified,'.
                                \'auLogPatchChunkHeader')
                    let newr=[   'Added   /\V+\.\*/',
                                \'Removed /\V-\.\*/',
                                \'File    /\vdiff.*/',
                                \'NewFile /\V+++ \.\*/',
                                \'OldFile /\V--- \.\*/',
                                \'NotModified  / \v.*/',
                                \'ChunkHeader /@\v.*/ contains=auLogPatchSect',
                                \'Sect    /\V @@\.\+/ms=s+3',
                                \]
                    call map(newr, '"syn match auLogPatch".v:val.'.
                                \  '" contained skipnl '.
                                \    'nextgroup=auLogNextLineStart"')
                    let r+=newr
                elseif kw is# 'stat'
                    call s:F.temp.addgroup(r, nlgroups,
                                \'auLogStatFiles,auLogStatFileSep')
                    let newr=[   'Files /\v\d+/ nextgroup=auLogStatFilesMsg',
                                \'FilesMsg / files changed, / '.
                                \              'nextgroup=auLogStatIns',
                                \'Ins /\v\d+/ nextgroup=auLogStatInsMsg',
                                \'InsMsg / insertions, / '.
                                \               'nextgroup=auLogStatDel',
                                \'Del /\v\d+/ nextgroup=auLogStatDelMsg',
                                \'DelMsg / deletions/ skipnl '.
                                \           'nextgroup=auLogNextLineStart',
                                \'FileSep /  / nextgroup=auLogStatFile',
                                \'File /\v%(%(\ \|\ )@!.)+/ '.
                                \             'nextgroup=auLogStatTSep',
                                \'TSep /\v\s+\|\s+/ nextgroup=auLogStatTIns',
                                \'TIns /\v\d+/ nextgroup=auLogStatTNumSep',
                                \'TNumSep /\v\s+/ nextgroup=auLogStatTDel',
                                \'TDel /\v\d+/ skipnl '.
                                \           'nextgroup=auLogNextLineStart']
                    call map(newr, '"syn match auLogStat".v:val.'.
                                \  '" contained"')
                    let r+=newr
                elseif kw is# 'hide'
                    let sname='auLog_hide'.i.'_'.j
                    call s:F.temp.addgroup(r, nlgroups, sname)
                    let r+=['hi def link '.sname.' Ignore']
                    let r+=['syn match '.sname.' /\V'.escape(arg[0], '\/').'/ '.
                                \'contained nextgroup=']
                elseif (index(s:kwpempt, kw)!=-1 || kw is# 'branch' ||
                            \                       kw is# 'rev') &&
                            \(has_key(arg, 'pref') || has_key(arg, 'suf'))
                    if has_key(arg, 'pref')
                        call s:F.temp.addgroup(r,nlgroups,'auLog_'.kw.'_pref,')
                        let r+=['syn match auLog_'.kw.'_pref '.
                                    \'/\V'.escape(arg.pref, '\/').'/ '.
                                    \'contained nextgroup=auLog_'.kw]
                    else
                        call s:F.temp.addgroup(r, nlgroups, 'auLog_'.kw.',')
                    endif
                    let nextlit=get(arg, 'suf', get(lit, j+1, 0))
                    let r+=['syn match auLog_'.kw.' '.
                                \'/'.s:F.getkwreg(kw, nextlit).'/ '.
                                \'contained nextgroup=']
                    if has_key(arg, 'suf')
                        let r[-1].='auLog_'.kw.'_suf'
                        let r+=['syn match auLog_'.kw.'_suf '.
                                    \'/\V'.escape(arg.suf, '\/').'/ '.
                                    \'contained nextgroup=']
                    endif
                elseif lmeta==j+1 && llit<=j+1
                    call s:F.temp.addgroup(r, nlgroups, 'auLog_'.kw)
                    let r+=['syn match auLog_'.kw.' /\v.*/ '.
                                \'contained nextgroup=']
                elseif kw is# 'time'
                    call s:F.temp.addgroup(r, nlgroups, 'auLog_'.kw)
                    if has_key(arg, 0)
                        if j<=llit && !empty(lit[j+1])
                            let creg='\%(\%('.escape(lit[j+1], '\/').'\)\@!'.
                                        \'\.\)\*'
                        else
                            let creg='\.\*'
                        endif
                        let reg='\V'.substitute(escape(arg.0, '\/'), '\v\%(.)',
                                    \'\=index(s:ukntkws, submatch(1))==-1 ?'.
                                    \   'get(s:timekwregs, submatch(1), '.
                                    \       'submatch(0)) :'.
                                    \   'creg', 'g')
                    else
                        let reg=s:noargtimereg
                    endif
                    let r+=['syn match auLog_time '.
                                \'/'.reg.'/ '.
                                \'contained nextgroup=']
                else
                    call s:F.temp.addgroup(r, nlgroups, 'auLog_'.kw)
                    let r+=['syn match auLog_'.kw.' /'.
                                \s:F.getkwreg(kw, get(lit, j+1, 0)).'/ '.
                                \'contained nextgroup=']
                endif
            endif
            let j+=1
        endfor
        call s:F.temp.addgroup(r, nlgroups, 'auLogNextLineStart')
        let r[-1].=' skipnl'
        let i+=1
    endfor
    if !empty(nlgroups)
        let r+=['syn match auLogNextLineStart @\v^[^ ]+ @ skipwhite '.
                    \' nextgroup='.join(nlgroups, ',')]
    endif
    call add(r, remove(r, 0))
    if len(r)==1
        return []
    endif
    let s:syncache[cid]=r
    return r
endfunction
"▶1 comparedates :: datesel, time → -1|0|1
let s:datechars='YmdHM'
function s:F.comparedates(datesel, time)
    let j=0
    for selnum in a:datesel
        if selnum isnot# '*'
            let spec='%'.s:datechars[j]
            if selnum is# '.'
                let selnum=str2nr(strftime(spec))
            endif
            let actnum=str2nr(strftime(spec, a:time))
            if actnum!=selnum
                if actnum<selnum
                    return -1
                else
                    return 1
                endif
            endif
        endif
        let j+=1
    endfor
    return 0
endfunction
"▶1 iterfuncs.check
" startfunc (here)  :: repo, opts → d
let s:fcheckpropslist=['renames', 'copies', 'changes', 'files']
let s:iterfuncs.check={}
"▶2 iterfuncs.check.start
"▶3 addcentury
function s:F.addcentury(year)
    if type(a:year)==type(0) && a:year<100
        let curyear=str2nr(strftime('%y'))
        let century=str2nr(strftime('%Y')[:-3])
        if a:year<=curyear
            let r=((century*100)+a:year)
        else
            let r=(((century-1)*100)+a:year)
        endif
        return r
    endif
    return a:year
endfunction
"▶3 redate
function s:F.redate(datespec)
    let date=map(split(a:datespec, '\v[^0-9*.]+'),
                \'v:val=~#"\\d" ? str2nr(v:val) : v:val')
    let date[0]=s:F.addcentury(date[0])
    return date
endfunction
"▲3
let s:keytoexpr={
            \'branch': '"a:cs.branch isnot# ".string(v:val)',
            \'merges': '(v:val)?("len(a:cs.parents)<=1"):'.
            \                  '("len(a:cs.parents)>1")',
            \'search': '"a:cs.description!~#".string(v:val)',
            \  'user':        '"a:cs.user!~#".string(v:val)',
        \}
function s:iterfuncs.check.start(repo, opts)
    let r={'repo': a:repo, 'hasfiles': 0, 'hasdaterange': 0, 'hasdate': 0}
    "▶3 Define variables for files filtering
    if has_key(a:opts, 'files')
        let r.hasfiles=1
        let r.csfiles={}
        let r.filepats=a:opts.filepats
        let r.tocheck={}
        let a:opts.csfiles=r.csfiles
    endif
    "▶3 Define variables for date filtering
    if has_key(a:opts, 'date')
        let idx=match(a:opts.date, '\V<=\?>')
        if idx==-1
            let r.hasdate=1
            let r.selector=(stridx('<>', a:opts.date[0])==-1)?(''):
                        \                                     (a:opts.date[0])
            let r.acceptexact=(empty(r.selector) || a:opts.date[1] is# '=')
            let r.date=s:F.redate(a:opts.date[empty(r.selector)?(0):
                        \                     (len(r.selector)+r.acceptexact):])
        else
            let r.hasdaterange=1
            let r.date1=s:F.redate(a:opts.date[:(idx-1)])
            let r.acceptexact=(a:opts.date[idx+1] is# '=')
            let r.date2=s:F.redate(a:opts.date[(idx+2+r.acceptexact):])
        endif
    endif
    "▶3 Determine other filters
    let r.expr=join(values(map(filter(copy(a:opts),
                \                     'has_key(s:keytoexpr, v:key)'),
                \              'eval(s:keytoexpr[v:key])')), '||')
    "▲3
    return r
endfunction
"▶2 iterfuncs.check.check
function s:iterfuncs.check.check(d, cs)
    "▶3 Check simple cases
    if !empty(a:d.expr) && eval(a:d.expr)
        return 0
    endif
    "▶3 Check files
    if a:d.hasfiles
        let copies =a:d.repo.functions.getcsprop(a:d.repo, a:cs, 'copies' )
        let renames=a:d.repo.functions.getcsprop(a:d.repo, a:cs, 'renames')
        let changes=a:d.repo.functions.getcsprop(a:d.repo, a:cs, 'changes')[:]
        let csfiles=[]
        let tcfiles=[]
        let a:d.csfiles[a:cs.hex]=csfiles
        if has_key(a:d.tocheck,a:cs.hex)
            let tc=a:d.tocheck[a:cs.hex]
            call filter(changes, '(index(tc, v:val)==-1)?(1):'.
                        \           '([0, add(csfiles, v:val)][0])')
            call filter(tc, 'index(csfiles, v:val)==-1')
            if !empty(tc)
                let allfiles=a:d.repo.functions.getcsprop(a:d.repo, a:cs,
                            \                             'allfiles')
                let tcfiles+=filter(copy(allfiles), 'index(tc, v:val)!=-1')
            endif
        endif
        for pattern in a:d.filepats
            let newchanges=[]
            call map(copy(changes), 'add(((v:val=~#'.string(pattern).')?'.
                        \                   '(csfiles):'.
                        \                   '(newchanges)), v:val)')
            if empty(newchanges)
                break
            endif
            let changes=newchanges
        endfor
        for file in csfiles
            let tcfiles+=map(filter(['renames', 'copies'],
                        \           'has_key({v:val}, file) && '.
                        \           '{v:val}[file] isnot 0'),
                        \    '{v:val}[file]')
        endfor
        if !empty(tcfiles)
            call map(copy(a:cs.parents), 'extend(a:d.tocheck, '.
                        \'{v:val : get(a:d.tocheck, v:val, [])+tcfiles})')
        endif
        if empty(csfiles)
            return 0
        endif
    endif
    "▶3 Check date
    if a:d.hasdate
        let cmpresult=s:F.comparedates(a:d.date, a:cs.time)
        if !((a:d.acceptexact && cmpresult==0) ||
                    \(a:d.selector is# '<' && cmpresult==-1) ||
                    \(a:d.selector is# '>' && cmpresult==1))
            return 0
        endif
    elseif a:d.hasdaterange
        let cmp1result=s:F.comparedates(a:d.date1, a:cs.time)
        let cmp2result=s:F.comparedates(a:d.date2, a:cs.time)
        if !((cmp1result==1 && cmp2result==-1) ||
                    \(a:d.acceptexact && (cmp1result==0 ||
                    \                     cmp2result==0)))
            return 0
        endif
    endif
    "▲3
    return 1
endfunction
"▶1 setup
"▶2 getkwreg
function s:F.getkwreg(kw, nextlit)
    if has_key(s:kwreg, a:kw)
        return s:kwreg[a:kw]
    " XXX 0 is empty
    elseif !empty(a:nextlit)
        return '\V\%(\%('.escape(a:nextlit, '\/').'\)\@!\.\)\*'
    else
        return '.*'
    endif
endfunction
"▲2
function s:F.setup(read, repo, opts)
    let opts=a:opts
    let bvar={}
    "▶2 Add `ignorefiles'
    let ignorefiles=(has_key(opts, 'ignfiles')?
                \               (opts.ignfiles):
                \               (s:_f.getoption('ignorefiles')))
    let opts.ignorefiles={}
    call map(copy(ignorefiles), 'extend(opts.ignorefiles, {v:val : 1})')
    unlet ignorefiles
    "▶2 Get cslist
    let csiterfuncsname=((has_key(opts, 'revision'))?
                \          ('ancestors'):
                \       ((has_key(opts, 'revrange'))?
                \          ('revrange')
                \       :
                \          ('changesets')))
    let csiterfuncs=a:repo.iterfuncs[csiterfuncsname]
    "▶2 Get template
    if has_key(opts, 'template')
        let template=eval(opts.template)
    elseif has_key(opts, 'style')
        let template=s:templates[opts.style]
    else
        let template=s:templates.default
    endif
    let opts.repo=a:repo
    let bvar.templatelist=s:F.temp.parse(template)
    let [opts.reqs, opts.templatefunc]=s:F.temp.compile(bvar.templatelist, opts)
    "▲2
    if !a:read
        "▶ Required for setting syntax definitions and also for maps to work
        " Is normally done by edit.vim, but in our case it is needed earlier
        let bvar.opts=a:opts
        let bvar.repo=a:repo
        let s:_r.bufvars[bufnr('%')]=bvar
        "▲
        let bvar.procinput=(has_key(a:opts, 'procinput')?
                    \           (2*a:opts.procinput):
                    \           s:_f.getoption('procinput'))
        if bvar.procinput==1 && getchar(1)
            let bvar.procinput=0
        endif
        setlocal buftype=nofile filetype=aurumlog
        augroup AuLogNoInsert
            autocmd InsertEnter <buffer> :call feedkeys("\e", "n")
        augroup END
    endif
    let bvar.cw=s:_f.getoption('closewindow')
    let text=s:F.glog.graphlog(a:repo, opts, csiterfuncs, bvar, a:read)
    if a:read
        call s:_r.setlines(text, a:read)
    else
        setlocal readonly nomodifiable
    endif
    return bvar
endfunction
let s:_augroups+=['AuLogNoInsert']
"▶1 syndef
function s:F.syndef()
    let buf=+expand('<abuf>')
    if !has_key(s:_r.bufvars, buf)
        return
    endif
    let bvar=s:_r.bufvars[buf]
    let bvar.templatesyn=s:F.temp.syntax(bvar.templatelist, bvar.opts)
    for line in bvar.templatesyn
        execute line
    endfor
endfunction
augroup auLogSyntax
    autocmd Syntax aurumlog :call s:F.syndef()
augroup END
let s:_augroups+=['auLogSyntax']
"▶1 logfunc
function s:logfunc.function(repopath, opts)
    let opts=copy(a:opts)
    if has_key(opts, 'files')
        if opts.files[0] is# ':'
            let curfile=s:_r.cmdutils.getrrf(opts, 'nocurf', -1)[3]
            if curfile is 0
                call remove(opts.files, 0)
            else
                let opts.files[0]=s:_r.cmdutils.globescape(curfile)
            endif
        endif
        if a:repopath is# ':'
            let repo=s:_r.repo.get(opts.files[0])
        else
            let repo=s:_r.repo.get(a:repopath)
        endif
        call map(opts.files, 'repo.functions.reltorepo(repo, v:val)')
    else
        let repo=s:_r.repo.get(a:repopath)
    endif
    call s:_r.cmdutils.checkrepo(repo)
    if has_key(opts, 'cmd')
        let cmd=remove(opts, 'cmd')
    else
        let cmd='silent new'
    endif
    call s:_r.run(cmd, 'log', repo, opts)
    if !has_key(opts, 'cmd')
        setlocal bufhidden=wipe
    endif
endfunction
let s:datereg='%(\d\d%(\d\d)?|[*.])'.
            \ '%(\-%(\d\d?|[*.])'.
            \ '%(\-%(\d\d?|[*.])'.
            \ '%([ _]%(\d\d?|[*.])'.
            \ '%(\:%(\d\d?|[*.]))?)?)?)?'
let s:logfunc['@FWC']=['-onlystrings '.
            \          '['.s:_r.cmdutils.nogetrepoarg.']'.
            \          '{ *?files    (type "")'.
            \          '  *?ignfiles in [patch renames copies files] ~start'.
            \          '   ?date     match /\v[<>]?\=?'.s:datereg.'|'.
            \                                 s:datereg.'\<\=?\>'.s:datereg.'/'.
            \          '   ?search   isreg'.
            \          '   ?user     isreg'.
            \          '   ?branch   type ""'.
            \          '   ?limit    range 1 inf'.
            \          '   ?revision type ""'.
            \          ' +2?revrange type "" type ""'.
            \          '   ?style    key templates'.
            \          '   ?template idof variable'.
            \          '  !?merges'.
            \          '  !?patch'.
            \          '  !?stat'.
            \          '  !?showfiles'.
            \          '  !?showrenames'.
            \          '  !?showcopies'.
            \          '  !?procinput'.
            \          s:_r.repo.diffoptsstr.
            \          '   ?cmd      type ""'.
            \          '}', 'filter']
call add(s:logcomp, substitute(substitute(
            \substitute(substitute(substitute(substitute(s:logfunc['@FWC'][0],
            \'\V|*_r.repo.get',        '',                                  ''),
            \'\vfiles\s+\([^)]*\)',    'files path',                        ''),
            \'\Vcmd\s\+type ""',       'cmd first (in cmds, idof command)', ''),
            \'\vrevision\s+\Vtype ""', 'revision '.s:_r.comp.rev,           ''),
            \'\vbranch\s+\Vtype ""',   'branch '.s:_r.comp.branch,          ''),
            \'\vrevrange\s+\Vtype "" type ""',
            \                         'revrange '.s:_r.comp.rev.' '.
            \                                     s:_r.comp.rev,            ''))
"▶1 Post resource
call s:_f.newcommand({
            \'function': s:F.setup,
            \ 'options': {'list': ['files', 'revrange', 'ignfiles'],
            \             'bool': ['merges', 'patch', 'stat', 'showfiles',
            \                      'showrenames', 'showcopies', 'procinput'],
            \              'num': ['limit']+s:_r.repo.diffoptslst,
            \              'str': ['date', 'search', 'user', 'branch',
            \                      'revision', 'style', 'template',
            \                      'crrestrict'],
            \             'pats': ['files'],
            \            },
            \'filetype': 'aurumlog',
            \})
"▶1
call frawor#Lockvar(s:, '_r,_pluginloaded,compilecache,parsecache,syncache')
" vim: ft=vim ts=4 sts=4 et fmr=▶,▲
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.