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
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
|
; Copyright (C) 1990 Mark B. Motl
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Publich License as published by
; the Free Software Foundation.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; To obtain a copy of the GNU General Public License, write to:
; Free Software Foundation, Inc.
; 675 Mass Ave.
; Cambridge, MA 02139
; USA
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; AUTHOR: Mark B. Motl <motl@cssun.tamu.edu>
; Department of Computer Science
; Texas A&M University
; College Station, TX 77843-3112
;
; PURPOSE: The following functions are a set of GNU Emacs Lisp functions
; to extend Emacs so that it is sensitive to the WEB style of
; programming.
;
; DATE: The preliminary version of these functions was written in
; Summer/Fall 1989.
;
; ADVISOR: Dr. S. Bart Childs <bart@cssun.tamu.edu>
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; <DISCLAIMER>
; This program is still under development. The author accepts no
; responsibility to anyone for the consequences of using it, for whether
; it serves any particular purpose, or even works at all.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Any bugs or comments should be mailed to the author at the above address.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; REVISION HISTORY
;
; Late November 1989
;
; Made a significant change to the type of list maintained for the module
; names. It now looks like
;
; (("Module Name 1" (Defined in Module #'s) (Used in Module #'s))
; ("Module Name 2" (Defined in Module #'s) (Used in Module #'s))
; ...
; ("Module Name n" (Defined in Module #'s) (Used in Module #'s))
; )
;
; As a consequence of this reorganization, the following functions had to
; be modified: any-modules-undefined-initially, collect-module-names,
; display-module-names, module-lookup, options-for-module-name-insertion,
; and view-module-names.
;
; Two functions were deleted: print-module-names and replace-nth-element.
;
; The function "append-a-stub-module" was modified so that a stub module
; is now added at the end of the section in which it is first used
; instead of at the end of the buffer.
;
; Some new functions have been added:
; 1) "collect-section-names" -- constructs a list of the major sections
; and the module in which each section starts
; 2) "view-section-names" -- prints the list of section names to another
; buffer
; 3) "switch-to-module" -- this function is useful when one is switched
; to another buffer (e.g., running "view-section-names") and wants to
; return to the buffer where the WEB document is. It prompts for a
; module number to return to in the WEB; or, alternatively, one can
; provide a prefix argument.
; 4) "insert-new-module-name-in-list-of-module-names" -- this replaces
; the old function "replace-nth-element".
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Early December 1989
;
; Added several functions so that traversal of the Defined In and Used In
; lists in the list of module names could be accomplished. These are:
;
; first-use and first-define -- these can be executed from either the buffer
; containing the WEB document or the buffer where the module names are
; displayed. The only way to select a module is in the buffer containing
; the list of module names (position the cursor on the line containing
; the module name of interest). Once a module name has been selected,
; first-use switches back to the buffer containing the WEB document at
; the module where the selected module name was first used. If the
; command is issued from the buffer containing the WEB document, point
; is positioned at the beginning of the module where the most recently
; selected module name was first used. The function first-define is analogous
; to the operation of first-use except that it works on the Defined In
; list instead of the Used In list.
;
; next-use, previous-use, next-define, and previous-define -- These functions
; work as one would expect. These functions can only be used in the buffer
; containing the WEB document.
;
; An internal support function, convert-list-to-string, was added so that
; the lists Defined In and Used In (lists of integers) could be inserted
; in the buffer where the module names are displayed.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Late December 1989
;
; Added some new functions to aid in communication with the index that
; Weave creates. These are: eliminate-control-sequences, first-index-use,
; next-index-use, previous-index-use, reformat-the-index, and view-index.
; The second, third, fourth, and last of these are interactive; the remaining
; ones are support functions. When the command view-index is invoked, it
; first checks to see if the file INDEX.tex is present (we have modified the
; output generated by Weave so that in addition to the TeX file, it also
; creates two other files: INDEX.tex which contains the index and
; MODULE_NAMES.tex which contains the list of section names). If not present,
; it creates another process and Weaves the current buffer. The file
; INDEX.tex is then read in and some reformatting is done so that it is more
; readable. The user selects an index entry of interest by placing the
; cursor anywhere on the line(s) where the index entry is located. An index
; entry is selected then by issuing the command first-index-use. This command
; can be issued from the buffer where the index is displayed or it can be
; issued from the buffer containing the WEB document. If invoked from the
; former, it switches back to the buffer containing the WEB document at the
; beginning of the module where the selected index entry was first referenced.
; If invoked from the latter, point is positioned at the beginning of the
; module where the most recently selected index entry was first referenced.
;
; Once an index entry has been selected, the functions next-index-use and
; previous-index-use can be used to traverse the list of references for the
; most recently selected index entry.
;
; Also added functions count-sections (provides a count of the total number
; of sections in the WEB), goto-section (which goes to the beginning of the
; n-th section), and what-section (which informs the user of the section
; that point is currently positioned in).
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; ACCOMMODATIONS FOR A CHANGE FILE
;
; In late December 1989, I added five new functions that deal with CHange
; files. These are:
;
; 1) change-module --- Used in the buffer that contains the Web
; document. The user positions point in the module that he wishes to
; change and then invokes the function. It copies the entire module
; contents from the Web buffer to the buffer containing the CHange file
; twice---once between an @x @y and once between an @y @z. The text
; is inserted in the proper position in the CHange file.
;
; 2) collect-list-of-changed-module-numbers --- collects and returns a list
; of module numbers that have been changed in the CHange file.
;
; 3) escape-special-characters-in-regexp --- used when determining what
; module in the Web a particular change corresponds to. Because the
; text between the @x and @y may contain special characters Emacs uses
; in regular expression searches, it is necessary to turn them into
; ordinary characters.
;
; 4) view-list-of-changed-modules --- available in both the buffer
; containing the Web document and the buffer containing the CHange file.
; It displays a list of which modules in the Web have been changed in the
; CHange file.
;
; 5) what-change --- available only in the buffer containing the CHange
; file. Based on the position of point, it displays a descriptive message
; in the minibufer indicating which module in the Web is being changed.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; January 3, 1990
;
; Changed the names of some functions:
; FROM Name: TO Name:
; module-count count-modules
; section-count count-sections
; show-index view-index
; show-list-of-changed-modules view-list-of-changed-modules
; show-module-names view-module-names
; show-section-names view-section-names
; statistics determine-statistics
; what-module-does-this-change-correspond-to what-change
;
; Also added key-bindings which are accomplished at load time. I used the
; convention: Each command takes the form
; ESC (or META)
; CTRL first-letter-of-function-name
; CTRL first-letter-of-second-word-in-function-name
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; January 8, 1990
;
; Added two new functions change-file and web-file. When invoked they
; set the current buffer to the CHange or Web file, respectively.
; Eliminated the function switch-to-module.
;
; Changed some function names:
; FROM TO
; change-this-module edit-module
; check-balance-of-module-delimiters delimiter-match-check
; determine-statistics determine-characteristics
; first-index-use first-index
; next-index-use next-index
; previous-index-use previous-index
; view-list-of-changed-modules view-changed-modules-list
; view-module-names view-module-names-list
; view-section-names view-section-names-list
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; January 10, 1990
;
; Added four new functions:
; 1) count-changes -- counts the number of changes in the CHange file.
; 2) goto-change -- goes to the n-th change in the CHange file. The
; changes are numbered sequentially beginning with 1.
; 3) next-change -- positions point at the beginning of the next change.
; 4) previous-change -- positions point at the beginning of the previous
; change.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; January 13, 1990
;
; Added two new functions:
; 1) initialize-module-names-list -- this function is invoked by web-mode
; if two conditions prevail:
; a) the file .mods exists for the WEB beging edited and
; b) the file .mods is newer than the WEB
; If both of these conditions are true, the information to initialize
; the module-names list is read in from the file .mods. This saves
; a considerable amount of time when the WEB is quite large, such as
; initex.web. Thus, if the file initex.mods exists and it is newer
; than initex.web, a lot of time can be saved in the initial startup.
; 2) write-module-names-to-a-file -- this is also an internal support function.
; Every time the module-names must be collected, this function is invoked
; so that the new information can be written to the file .mods.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; January 16, 1990
;
; Completely changed the function collect-list-of-changed-module-numbers.
; The method the function now uses closely resembles the method used by
; Knuth in TANGLE and WEAVE. See modules 128 through 137 in TANGLE.WEB.
; As a result of this change, I was able to delete the function escape-
; special-characters-in-regexp.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; January 27, 1990
;
; Reworked the function collect-module-names so that it works considerably
; faster.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; April 7, 1990
;
; Eliminated the functions first-index, first-define, and first-use. Made
; the functions next-define, next-use, next-index, previous-define,
; previous-use, and previous-index more logical. They work in either the
; buffer displaying the index or module names or in the buffer containing
; the Web document. If in one of the special buffers and one of these
; commands is issued, the user is switched back to the Web document at the
; next or previous occurrence based on point's position in the Web document
; before the switch over to the special buffer.
;
; Added a global variable web-module-changed-then-goto-change. Its purpose
; is to indicate where point is to be positioned when going to a module that
; has been changed. If the variable's value is true, then point is positioned
; in the CHange file at the change that corresponds to the module that the
; user wants to go to. If the variables value is not true, then point is
; positioned in the Web document with a message in the minibuffer that says
; that the module has been changed.
;
; Renamed all functions and global variables so that web- precedes their name.
; This was done in an effort to avoid any collisions when web-mode is used in
; conjunction with other modes.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; July 30, 1990
;
; After looking at some journal files, I realized that when web-mode-save-
; buffers-kill-emacs is invoked, the web-journal function doesn't write out
; the proper count for web-mode-save-buffers-kill-emacs because the file
; is written before the vector containing the counts gets updated.
;
; 1. Extend reformat or rewrite it to produce statistics.
; These should include the usual things but for webs
; it should also read a config file and produce things
; like counts of @<*@>, @<sys*@>, and all other index
; things, ...
;
; 2. The environment of Mark does not need this but a WEB
; user does. Each library should have a corresponding
; library whose elements are WEB sources for documenting
; calls. For example: calling LEQT1F from IMSL should
; be complemented by emacs including /usr/local/doc/imsl/leqt1f.web
; and editing for the local use.
;
; 3. Major sections need a complementary command of the type
; of @*subprogram-name@*. This string could be passed
; to the index for scoping variables and comments that
; may be entered into the index. Global vs local variables.
;
; 4. C prototypes and Pascal forward references: display of
; these kinds of items could be handy for a programmer.
; This is somewhat related to 2. above.
;
; 5. Integration with other tools such as Marcus' LPT or
; Kevin Borden's work with X. Two particular items that
; would yield the most benefit would be a tex previewer
; and source level debugger. These may be possible now,
; just not yet documented.
;
; 6. Also need to set up a default directory for Emacs to
; search when @i's are encountered.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; GLOBAL variables and constants used in web-mode.
;
(defvar web-buffer-name "" "Name of Web document being edited.")
(defvar web-change-buffer-name nil
"Name of the buffer containing the CHange file")
(defvar web-default-directory nil
"The default-directory that the Web is located in.")
(defvar web-defined-in-occurrence -1
"Used as a pointer into the (Defined In) list of the most recently selected
module name.")
(defvar web-defined-in-used-in-location -1
"Used as a pointer into the list of module names. Used to take the
(web-defined-in-used-in-location)-th car of module-names.")
(defvar web-files nil
"A list of the files used in the WEB. The general form of the list is:
(\"CHange file name\" \"WEB file name\" \"include file 1\" \"include file 2\"
... \"include file n\")")
(defvar web-index-buffer-name ""
"Name of the buffer where the index is displayed.")
(defvar web-index-entry ""
"The selected index entry.")
(defvar web-interactive-function-usage nil
"A vector containing the number of times that the interactive functions
were executed. The i-th element corresponds to the i-th car of
web-interactive-functions")
(defvar web-interactive-functions nil
"List of the interactive functions available in web-mode.")
; initialize web-interactive-functions
(setq web-interactive-functions
'("web-change-file"
"web-collect-module-names"
"web-count-changes"
"web-count-modules"
"web-count-sections"
"web-delimiter-match-check"
"web-determine-characteristics"
"web-edit-module"
"web-file"
"web-goto-change-corresponding-to-module"
"web-goto-module"
"web-goto-section"
"web-include-file"
"web-insert-index-entry"
"web-insert-module-name"
"web-is-this-a-new-module-beginning"
"web-mode"
"web-mode-save-buffers-kill-emacs"
"web-newline"
"web-next-change"
"web-next-define"
"web-next-index"
"web-next-module"
"web-next-section"
"web-next-use"
"web-previous-change"
"web-previous-define"
"web-previous-index"
"web-previous-module"
"web-previous-section"
"web-previous-use"
"web-rename-module"
"web-view-changed-modules-list"
"web-view-index"
"web-view-module-names-list"
"web-view-section-names-list"
"web-what-change"
"web-what-module"
"web-what-section"
) ; end list
) ; end setq
(defvar web-location-in-selected-index-entry-occurrences -1
"Used as a pointer into the list selected-web-index-entry-occurrences.")
(defvar web-location-of-module nil
"A vector of vectors. The i-th element contains information about the i-th
module. Each element is a vector of 4 parts: the first part is an index into
the list web-files indicative of which file the i-th module is located; the
second part is the module number relative to the file that it is located in;
the third part tells the major section that the i-th mdoule is located in;
the fourth part indicates if the i-th module has been changed (0=no, 1=yes);
and the fifth indicates the position of the CHange in the CHange file.")
(defconst web-max-number-of-modules 2000
"The maximum number of modules in the WEB and its associated include
files.")
(defvar web-mode-map nil "Keymap used in Web Mode.")
(defvar web-module-begins "^@\\( \\|\t\\|\n\\|\\*\\)"
"Regular expression used for determining the beginning of a module.")
(defvar web-module-changed-then-goto-change nil
"Boolean variable. When going to a module and it is true, point is
positioned in the CHange buffer at the CHange corresponding to the module
number; otherwise, point is positioned at the module in the Web file.")
(defvar web-module-name "\\(@@\\)*@<\\(@'\\|@\"\\|@@\\|[^@]\\)+@>"
"Regular expression used for isolating a valid module name.")
(defvar web-module-name-defined-in-used-in nil
"A list of the Web's module names. The list takes the form
((\"Module Name 1\" (Defined in Module #'s) (Used in Module #'s))
(\"Module Name 2\" (Defined in Module #'s) (Used in Module #'s))
...
(\"Module Name n\" (Defined in Module #'s) (Used in Module #'s))
)")
(defvar web-module-names nil "List of Web document's module names.")
(defvar web-number-of-lines-in-window 0
"Total number of lines in window where Emacs is used.")
(defvar web-number-of-module-names 0
"Total number of module names in the Web.")
(defvar web-number-of-modules-in-file nil
"A vector that contains number of modules in each of the WEB files. The
elements are interpretted as follows: 0 - # of modules in the CHange file;
1 - # of modules in the WEB file; 2 - # of modules in include file 1;
3 - # of modules in include file 2; etc.")
(defvar web-selected-index-entry-occurrences nil
"A list comprised of the module numbers where the most recently selected
index entry was referenced.")
(defvar web-selected-module-name ""
"Represents the name of the most recently selected module name.")
(defvar web-used-in-occurrence -1
"Used as a pointer into the (Used In) list of the most recently selected
module name.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Initialize the key-map used in web-mode. This is done at load-time.
;
(if web-mode-map
; then the user has defined one
()
; else
(let ((map (make-sparse-keymap)))
(define-key map "\e\C-c\C-f" 'web-change-file)
(define-key map "\e\C-c\C-c" 'web-count-changes)
(define-key map "\e\C-c\C-m" 'web-count-modules)
(define-key map "\e\C-c\C-s" 'web-count-sections)
(define-key map "\e\C-d\C-m" 'web-delimiter-match-check)
(define-key map "\e\C-d\C-c" 'web-determine-characteristics)
(define-key map "\e\C-e\C-m" 'web-edit-module)
(define-key map "\e\C-w\C-f" 'web-file)
(define-key map "\e\C-g\C-c" 'web-goto-change-corresponding-to-module)
(define-key map "\e\C-g\C-m" 'web-goto-module)
(define-key map "\e\C-g\C-s" 'web-goto-section)
(define-key map "\e\C-i\C-f" 'web-include-file)
(define-key map "\e\C-i\C-i" 'web-insert-index-entry)
(define-key map "<" 'web-insert-module-name)
(define-key map "@" 'web-is-this-a-new-module-beginning)
(define-key map "\015" 'web-newline)
(define-key map "\e\C-n\C-c" 'web-next-change)
(define-key map "\e\C-n\C-d" 'web-next-define)
(define-key map "\e\C-n\C-i" 'web-next-index)
(define-key map "\e\C-n\C-m" 'web-next-module)
(define-key map "\e\C-n\C-s" 'web-next-section)
(define-key map "\e\C-n\C-u" 'web-next-use)
(define-key map "\e\C-p\C-c" 'web-previous-change)
(define-key map "\e\C-p\C-d" 'web-previous-define)
(define-key map "\e\C-p\C-i" 'web-previous-index)
(define-key map "\e\C-p\C-m" 'web-previous-module)
(define-key map "\e\C-p\C-s" 'web-previous-section)
(define-key map "\e\C-p\C-u" 'web-previous-use)
(define-key map "\e\C-r\C-m" 'web-rename-module)
(define-key map "\e\C-v\C-c" 'web-view-changed-modules-list)
(define-key map "\e\C-v\C-i" 'web-view-index)
(define-key map "\e\C-v\C-m" 'web-view-module-names-list)
(define-key map "\e\C-v\C-s" 'web-view-section-names-list)
(define-key map "\e\C-w\C-c" 'web-what-change)
(define-key map "\e\C-w\C-m" 'web-what-module)
(define-key map "\e\C-w\C-s" 'web-what-section)
(setq web-mode-map map)
) ; end let
) ; end if
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Here are the functions that comprise web-mode.el
;
(defun web-any-modules-undefined-initially ()
"This function is invoked by \\[web-mode]. It checks to make sure that all
modules are defined. If a module is undefined, a stub module is appended.
ARGUMENTS : None
GLOBAL Variables : web-module-name-defined-in-used-in and web-module-names
LOCAL Variable : ctr and ptr
RETURNS : Nothing
USES : web-append-a-stub-module and web-goto-module"
(let ((ctr 0)
(ptr 0)
)
(while (nth ctr web-module-names)
(setq ptr (string-to-int (substring (nth ctr web-module-names)
(+ (string-match " " (nth ctr web-module-names)) 2))))
(if (null (car (car (cdr (nth ptr web-module-name-defined-in-used-in)))))
; then
(progn
(ding)
(message "Appending a module for %s"
(substring (car (nth ptr web-module-name-defined-in-used-in)) 0
(length (car (nth ptr web-module-name-defined-in-used-in)))))
(sit-for 2)
(web-goto-module (car (car (cdr (cdr
(nth ptr web-module-name-defined-in-used-in))))))
(setq module-number-of-stub (web-append-a-stub-module (substring
(car (nth ptr web-module-name-defined-in-used-in)) 0
(length (car (nth ptr web-module-name-defined-in-used-in))))))
(setcdr (nth ptr web-module-name-defined-in-used-in)
(append (list (list module-number-of-stub))
(list (car (cdr (cdr
(nth ptr web-module-name-defined-in-used-in)))))))
) ; end then
) ; end if
(setq ctr (1+ ctr))
) ; end while
) ; end let
)
(defun web-append-a-stub-module (module-name)
"This function is invoked when a new stub module needs to be inserted. It
appends a module with no commentary, an index entry indicating that this module
is a stub, and the named module MODULE-NAME with no code.
ARGUMENT : module-name (required)
GLOBAL Variables : None
LOCAL Variables : module-number-of-stub
RETURNS : module-number-of-stub
USES : web-insert-index-entry, web-update-the-location-of-module-vector,
web-update-the-module-name-defined-in-used-in-list, and web-what-module"
(save-excursion
(let ((module-number-of-stub))
(if (re-search-forward "^@\\*" nil t)
; then position point at the end of the current section
(forward-line -1)
; else position point at the end of the buffer
; (i.e., there is no next section)
(goto-char (point-max))
(newline)
) ; end if
(newline)
(insert-string "@ ")
(web-update-the-location-of-module-vector ? )
(web-insert-index-entry "R" "Stub")
(insert-string (concat "@<" module-name "@>=\n"))
(setq module-number-of-stub (web-what-module))
(web-update-the-module-name-defined-in-used-in-list
module-number-of-stub)
module-number-of-stub
) ; end let
) ; end excursion
)
(defun web-binary-search-of-names (names num-elements-in-names search-key len)
"This is an internal support function that performs a binary search on the
list NAMES with NUM-ELEMENTS-IN-NAMES elements to find SEARCH-KEY of length
LEN.
ARGUMENTS : names, num-elements-in-names, search-key, and len (all required)
LOCAL Variables : bottom, found, location, mid, and top
GLOBAL Variables : None
RETURNS : location
USES : Nothing"
(let ((bottom (1- num-elements-in-names))
found
(location -1)
(mid 0)
(top 0)
)
(while (and (not (null names))
(not found)
(<= top bottom)
)
(setq mid (/ (+ top bottom) 2))
(cond
((string= (substring search-key 0 len)
(substring (nth mid names) 0
(min len (length (nth mid names)))))
; then we have a match
(setq found t
location mid)
) ; end case
((string< (substring search-key 0 len)
(substring (nth mid names) 0
(min len (length (nth mid names)))))
(setq bottom (1- mid))
) ; end case
(t
(setq top (1+ mid))
) ; end case
) ; end cond
) ; end while
location ; return the location
) ; end let
)
(defun web-change-file ()
"Makes the buffer that contains the CHange file the current buffer.
ARGUMENTS : None
LOCAL Variables : None
GLOBAL Variable : web-change-buffer-name
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files and web-journal"
(interactive)
(web-journal "web-change-file")
(web-check-if-buffer-is-one-of-the-web-files)
(switch-to-buffer web-change-buffer-name)
)
(defun web-check-if-buffer-is-one-of-the-web-files ()
"This function checks if the current buffer is one of the files included
in web-files. If the current buffer is not one of the files include in
web-files, an error is signaled indicating that a user has attempted to use
one of the functions in web-mode in a buffer that \\[web-mode] was not used
on.
ARGUMENTS : None
GLOBAL Variables : web-default-directory and web-files
LOCAL Variable : ctr
RETURNS : pointer into the web-files list
USES : Nothing"
(let ((ctr 0)
current-buffer-is-one-of-the-web-files
)
(while (and (not current-buffer-is-one-of-the-web-files)
(nth ctr web-files))
(if (string-equal
(expand-file-name (nth ctr web-files) web-default-directory)
(buffer-file-name))
; then
(setq current-buffer-is-one-of-the-web-files t)
; else
(setq ctr (1+ ctr))
) ; end if
) ; end while
(if (not current-buffer-is-one-of-the-web-files)
; then
(if (not (or (string= (buffer-name (current-buffer))
(concat "STATISTICS for " web-buffer-name "*"))
(string= (buffer-name (current-buffer))
"*Module Names*")
(string= (buffer-name (current-buffer))
web-index-buffer-name)
(string= (buffer-name (current-buffer))
"*CHanged Modules*")
(string= (buffer-name (current-buffer))
"*Module Name (Defined In) (Used In)*")
(string= (buffer-name (current-buffer))
"*Section Names*")
(string= (buffer-name (current-buffer))
"web-mode.jou")
) ; end or
) ; end not
; then
(error "Attempting to use a function in a non-Web buffer.")
) ; end if
; else
ctr ; return the location of the current-buffer in web-files
) ; end if
) ; end let
)
(defun web-collect-list-of-changed-module-numbers ()
"This is an internal support function used by \\[web-edit-module],
\\[web-view-changed-modules-list], and \\[web-what-change]. It returns a list
of the module numbers in the Web being edited that have been changed in the
CHange file.
ARGUMENTS : None
GLOBAL Variables : web-change-buffer-name and web-buffer-name
LOCAL Variables : change-begins-at, changed-module, discrepancies,
discrepancies-begin-at, line-in-change-file, and
line-no-in-web
RETURNS : Nothing
USES : web-what-module"
(let ((change-begins-at 0)
(changed-module 0)
(ctr 0)
(discrepancies 0)
(discrepancies-begin-at 0)
line-in-change-file
(line-no-in-web 1)
)
(message "Determining which modules have been CHanged...")
(save-excursion
(set-buffer web-change-buffer-name)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "^@\\(x\\|y\\|z\\)" nil t)
(if (or (char-equal (downcase (string-to-char (buffer-substring
(match-beginning 1) (match-end 1)))) ?y)
(char-equal (downcase (string-to-char (buffer-substring
(match-beginning 1) (match-end 1)))) ?z)
) ; end condition
; then
(error "CHange beginning on line %d in %s is missing an @x."
(count-lines (point-min) (point)) web-change-buffer-name)
; else
(setq change-begins-at (count-lines (point-min) (point)))
(forward-line 1)
(if (eobp) (error "CHange file ended before @y."))
(setq line-in-change-file (buffer-substring (point)
(save-excursion (end-of-line) (point))))
(save-excursion ; find this line's position in the WEB file
(set-buffer web-buffer-name)
(save-excursion
(goto-line line-no-in-web)
(if (not (search-forward line-in-change-file nil t))
; then couldn't find line from the change file
(error "WEB file ended during CHange.")
; else did find the line from the change file
(setq line-no-in-web (count-lines (point-min) (point))
changed-module (web-what-module))
) ; end if
) ; end excursion
) ; end excursion
(setq line-no-in-web (1+ line-no-in-web)
discrepancies 0)
(forward-line 1)
(if (eobp) (error "CHange file ended before @y."))
(while (not (looking-at "^@\\(x\\|y\\|z\\)"))
(if (not
(string-equal
(buffer-substring (point) (save-excursion (end-of-line)
(point)))
(save-excursion
(set-buffer web-buffer-name)
(save-excursion
(goto-line line-no-in-web)
(if (eobp) (error "WEB ended during CHange."))
(buffer-substring (point)
(save-excursion (end-of-line)
(point)))
) ; end excursion
) ; end excursion
) ; end string-equal
) ; end not
; then
(progn
(if (zerop discrepancies)
; then
(setq discrepancies-begin-at line-no-in-web)
) ; end if
(setq discrepancies (1+ discrepancies))
) ; end then
) ; end if
(setq line-no-in-web (1+ line-no-in-web))
(forward-line 1)
(if (eobp) (error "CHange file ended during CHange."))
) ; end while
(if (or (char-equal (downcase (string-to-char (buffer-substring
(match-beginning 1) (match-end 1)))) ?x)
(char-equal (downcase (string-to-char (buffer-substring
(match-beginning 1) (match-end 1)))) ?z)
) ; end condition
; then
(error "The @x located on line %d in %s has no matching @y."
change-begins-at web-change-buffer-name)
; else scan forward to the next @
(if (not (zerop discrepancies))
; then
(if (= discrepancies 1)
; then
(error
"Hmm... %d line beginning at line %d in %s failed to match."
discrepancies discrepancies-begin-at web-buffer-name)
; else
(error
"Hmm... %d lines beginning at line %d in %s failed to match."
discrepancies discrepancies-begin-at web-buffer-name)
) ; end if
) ; end if
(forward-line 1)
(if (eobp) (error "CHange file ended before @z."))
(while (not (looking-at "^@\\(x\\|y\\|z\\)"))
(forward-line 1)
(if (eobp) (error "CHange file ended before @z."))
) ; end while
(if (or (char-equal (downcase (string-to-char (buffer-substring
(match-beginning 1) (match-end 1)))) ?x)
(char-equal (downcase (string-to-char (buffer-substring
(match-beginning 1) (match-end 1)))) ?y)
) ; end condition
; then
(error "The @x located on line %d in %s has no matching @z."
change-begins-at web-change-buffer-name)
; else
(end-of-line)
) ; end if
(aset (aref web-location-of-module changed-module) 3 1)
(if (zerop (aref (aref web-location-of-module changed-module) 4))
; then
(save-excursion
(goto-line change-begins-at)
(forward-char 2)
(setq change-begins-at (point))
(goto-char (point-min))
(setq ctr 0)
(while (re-search-forward "^@x" change-begins-at t)
(setq ctr (1+ ctr))
) ; end while
(aset (aref web-location-of-module changed-module) 4 ctr)
) ; end excursion
) ; end if
) ; end if
) ; end while
) ; end while
) ; end excursion
) ; end excursion
(message "Determining which modules have been CHanged...done")
) ; end let
)
(defun web-collect-location-of-modules ()
"This function actually initializes the vector web-location-of-module. The
vector consists of vectors. The i-th vector gives information about the i-th
module in the Web. Each of these vectors has three elements: the first is a
index into the list web-files which is indicative of the file that the i-th
module is located; the secend the i-th module's position relative to the
beginning of the file that it is located in; and the third element is
indicative of the section that the i-th module is in.
ARGUMENTS : NONE
GLOBAL Variables : web-location-of-module, web-number-of-modules-in-file,
web-files, and web-mode-map
LOCAL Variables : file-number, include-file-name, module-number, and
section-number
RETURNS : Nothing
USES : web-collect-location-of-modules and web-eliminate-white-space"
(save-excursion
(goto-char (point-min))
(while (re-search-forward "^@\\(i\\| \\|\n\\|\t\\|\\*\\)" nil t)
(if (char-equal ?i
(string-to-char (buffer-substring (match-beginning 1) (match-end 1))))
; then
(progn
(setq include-file-name (buffer-substring (point)
(save-excursion (end-of-line) (point))))
(setq include-file-name (substring include-file-name 0
(string-match " " include-file-name 1)))
(setq web-files (append web-files (list
(web-eliminate-white-space include-file-name))))
(setq file-number (cons (1- (length web-files)) file-number))
(save-excursion
(find-file-noselect (expand-file-name
(nth (car file-number) web-files) web-default-directory))
(set-buffer (get-file-buffer (expand-file-name
(nth (car file-number) web-files) web-default-directory)))
(setq major-mode 'Web-mode
mode-name "Web")
(use-local-map web-mode-map)
(web-collect-location-of-modules)
) ; end excursion
) ; end then
; else
(if (char-equal ?*
(string-to-char (buffer-substring (match-beginning 1) (match-end 1))))
; then
(setq section-number (1+ section-number))
) ; end if
(aset web-number-of-modules-in-file (car file-number)
(1+ (aref web-number-of-modules-in-file (car file-number))))
(aset web-location-of-module module-number
(vector (car file-number)
(aref web-number-of-modules-in-file (car file-number))
section-number
0 ; has it changed
0 ; if changed, the relative position in the CHange file
) ; end vector
) ; end aset
(setq module-number (1+ module-number))
) ; end if
) ; end while
(setq file-number (cdr file-number))
) ; end excursion
)
(defun web-collect-module-names ()
"This function is invoked by \\[web-mode]. It collects the list
module-name-defined-i9n-used-in list. This function can be invoked by the user
if the list is in error (e.g., if a module name has been added but then the
user deletes it--\\[web-mode] has no way of knowing when a module name or a
module has been deleted
ARGUMENTS : None
GLOBAL Variables : web-module-name-defined-in-used-in, web-module-names,
web-number-of-module-names, web-default-directory,
and web-files
LOCAL Variable : module-number
RETURNS : Nothing
USES : web-collect-module-names-in-buffer, web-journal, and
web-write-module-names-to-a-file"
(interactive)
(web-journal "web-collect-module-names")
(let ((module-number 1))
(setq web-module-name-defined-in-used-in ()
web-module-names ()
web-number-of-module-names 0)
(save-excursion
(set-buffer (get-file-buffer (expand-file-name (nth 1 web-files)
web-default-directory)))
(web-collect-module-names-in-buffer)
) ; end excursion
(web-write-module-names-to-a-file)
) ; end let
)
(defun web-collect-module-names-in-buffer ()
"This function is used to collect a list of all valid module names. The list
takes the form
((\"Module Name 1\" (Defined in Module #'s) (Used in Module #'s))
(\"Module Name 2\" (Defined in Module #'s) (Used in Module #'s))
...
(\"Module Name n\" (Defined in Module #'s) (Used in Module #'s))
)
First it must determine the beginning and ending points of where a module name
begins and ends. Once it has the name isolated, it checks the last three
characters. If the last three characters are an ellipsis the length of the
module name is set to the number of characters between the starting and ending
positions less 3; otherwise the length is set to the number of characters
between the starting and ending positons of the module name. The list as
mentioned above is not kept in alphabetical order. The module names themselves
are maintained in a separate list in alphabetical order. Each module name has
an integer appended to it which is used as a pointer into the list as mentioned
above. This module name is then compared with the module names already in the
list that contains only module names. If no match is found, the new module
name is inserted into both lists. If a match is found, update either the
Defined In or Used In list that accompanies the module name in the big list.
ARGUMENTS : None
GLOBAL Variables : web-module-name-defined-in-used-in, web-module-names,
web-number-of-module-names, web-default-directory,
and web-module-name
LOCAL Variables : char-after-at-greater, include-file-name, len, location,
module-name, module-number, next-module-begins, and
number-of-modules
RETURNS : web-module-names
USES : web-binary-search-of-names, web-collect-module-names-in-buffer,
and web-eliminate-white-space"
(let (char-after-at-greater
(len 0)
include-file-name
(location -1)
module-name
(next-module-begins (point))
)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "^@\\(i\\| \\|\n\\|\t\\|\\*\\)" nil t)
(if (char-equal ?i (string-to-char (buffer-substring
(match-beginning 1) (match-end 1))))
; then
(save-excursion
(setq include-file-name (buffer-substring (point)
(save-excursion (end-of-line) (point))))
(setq include-file-name
(substring include-file-name 0
(string-match " " include-file-name 1)))
(set-buffer (get-file-buffer (expand-file-name
(web-eliminate-white-space include-file-name)
web-default-directory)))
(web-collect-module-names-in-buffer)
) ; end excursion
; else
(save-excursion
(if (re-search-forward "^@\\(i\\| \\|\n\\|\t\\|\\*\\)" nil t)
; then
(setq next-module-begins (point))
; else
(setq next-module-begins (point-max))
) ; end if
) ; end excursion
(message "Collecting module names in Module %d" module-number)
(while (re-search-forward web-module-name next-module-begins t)
(setq module-name (web-eliminate-white-space
(buffer-substring (match-beginning 2) (match-end 2))))
(setq len (length module-name))
(if (and (> len 3) (string-equal "..."
(substring module-name (- len 3) len)))
; then
(setq len (- len 3))
) ; end if
(if (looking-at "=")
; then
(setq char-after-at-greater ?=)
; else
(setq char-after-at-greater ? )
) ; end if
(setq location
(web-binary-search-of-names web-module-names
web-number-of-module-names module-name len))
(if (= location -1)
; then a new module name has been encountered
(progn
(setq web-module-names (sort (append web-module-names
(list (concat module-name
" " (int-to-string web-number-of-module-names))))
'string<)
web-number-of-module-names
(1+ web-number-of-module-names))
(if (char-equal ?= char-after-at-greater)
; then this new module was defined (i.e., @<...@>=)
(setq web-module-name-defined-in-used-in
(append web-module-name-defined-in-used-in
(list (list module-name (list module-number)
(list ())))))
; else this new module was used before defined
(setq web-module-name-defined-in-used-in
(append web-module-name-defined-in-used-in
(list (list module-name (list ())
(list module-number)))))
) ; end if
) ; end then
; else the module name is already in list
(setq location (string-to-int
(substring (nth location web-module-names)
(+ (string-match " " (nth location web-module-names)) 2))))
(if (char-equal ?= char-after-at-greater)
; then an existing module name has been redefined
(if (null (car (car (cdr
(nth location web-module-name-defined-in-used-in)))))
; then
(setcdr (nth location web-module-name-defined-in-used-in)
(append (list (list module-number))
(cdr (cdr (nth
location web-module-name-defined-in-used-in)))))
; else
(setcdr (nth location web-module-name-defined-in-used-in)
(append (list (append
(car (cdr (nth
location web-module-name-defined-in-used-in)))
(list module-number)))
(cdr (cdr (nth
location web-module-name-defined-in-used-in)))))
) ; end if
; else an existing module has been used
(if (null (car (car (cdr (cdr
(nth location web-module-name-defined-in-used-in))))))
; then
(setcdr (nth location web-module-name-defined-in-used-in)
(append (list (car (cdr
(nth location web-module-name-defined-in-used-in))))
(list (list module-number))))
; else
(setcdr (nth location web-module-name-defined-in-used-in)
(append (list (car (cdr
(nth location web-module-name-defined-in-used-in))))
(list (append (car (cdr (cdr
(nth location web-module-name-defined-in-used-in))))
(list module-number)))))
) ; end if
) ; end if
) ; end if
) ; end while
(setq module-number (1+ module-number))
) ; end if
) ; end while
) ; end excursion
) ; end let
)
(defun web-collect-section-names ()
"This function collects a list of the major section names used in the Web.
It also keeps track of the module number where each major section begins.
ARGUMENTS: None
GLOBAL Variables : None
LOCAL Variables : ctr and section-names
RETURNS : section-names
USES : web-count-sections, web-eliminate-white-space, web-goto-section,
and web-what-module"
(let ((ctr 1)
(num-of-sections (web-count-sections))
section-names
)
(save-excursion
(while (<= ctr num-of-sections)
(web-goto-section ctr)
(re-search-forward "^@\\*\\(.*\\)\\.\\( \\|\n\\)" nil t)
(setq section-names (append section-names (list
(list (web-eliminate-white-space (buffer-substring
(match-beginning 1) (match-end 1)))
(web-what-module)))))
(setq ctr (1+ ctr))
) ; end while
) ; end excursion
section-names ; return the list
) ; end let
)
(defun web-convert-list-to-string (list-of-numbers)
"This is an internal support function that accepts a LIST-OF-NUMBERS and
converts it into a string.
ARGUMENT : list-of-numbers (required)
GLOBAL Variables : None
LOCAL Variables : ctr and list-as-string
RETURNS : list-as-string
USES : Nothing"
(let ((ctr 0)
list-as-string)
(while (not (null (nth ctr list-of-numbers)))
(setq list-as-string (concat list-as-string
(int-to-string (nth ctr list-of-numbers)) " "))
(setq ctr (1+ ctr))
) ; end while
(if (> (length list-as-string) 1)
; then eliminate the trailing space
(setq list-as-string
(substring list-as-string 0 (1- (length list-as-string))))
) ; end if
list-as-string ; return the list of numbers as a string
) ; end let
)
(defun web-count-changes ()
"Count the number of changes in the CHange file.
ARGUMENTS : None
GLOBAL Variable : web-location-of-module
LOCAL Variables : count, index, and number-of-modules
RETURNS : count
USES : web-check-if-buffer-is-one-of-the-web-files, web-count-modules,
and web-journal"
(interactive)
(web-journal "web-count-changes")
(web-check-if-buffer-is-one-of-the-web-files)
(let ((count 0)
(index 0)
(number-of-modules (web-count-modules))
)
(while (< index number-of-modules)
(if (not (zerop (aref (aref web-location-of-module index) 3)))
; then
(setq count (1+ count))
) ; end if
(setq index (1+ index))
) ; end while
(message "%d modules have been CHanged." count)
count ; return the number of changes in the web
) ; end let
)
(defun web-count-modules ()
"Count the number of modules in the Web file.
ARGUMENTS : None
GLOBAL Variables : web-number-of-modules-in-file and web-files
LOCAL Variable : ctr and module-count
RETURNS : module-count
USES : web-check-if-buffer-is-one-of-the-web-files and web-journal"
(interactive)
(web-journal "web-count-modules")
(web-check-if-buffer-is-one-of-the-web-files)
(let ((module-count 0)
(ctr 1)
)
(while (<= ctr (length web-files))
(setq module-count (+ module-count
(aref web-number-of-modules-in-file ctr))
ctr (1+ ctr))
) ; end while
(message "The number of modules in %s is %d"
(upcase (nth 1 web-files)) module-count)
module-count ; return the number of modules in the web
) ; end let
)
(defun web-count-sections ()
"Count the number of sections in the Web file.
ARGUMENTS : None
GLOBAL Variables : None
LOCAL Variable : module-count
RETURNS : the number of sections
USES : web-check-if-buffer-is-one-of-the-web-files, web-count-modules, and
web-journal"
(interactive)
(web-journal "web-count-sections")
(web-check-if-buffer-is-one-of-the-web-files)
(let ((module-count (web-count-modules)))
(message "The number of sections in %s is %d"
(upcase (nth 1 web-files))
(aref (aref web-location-of-module module-count) 2))
(aref (aref web-location-of-module module-count) 2) ; return # of sections
) ; end let
)
(defun web-count-the-matches (search-string)
"This is an internal support function that counts the number of occurrences
of SEARCH-STRING in the Web files.
ARGUMENT : search-string (required)
GLOBAL Variables : done, file-number, module-count, stopping-point, and
web-default-directory
LOCAL Variable : file-no and include-file-name
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-count-the-matches, and
web-eliminate-white-space"
(save-excursion
(let ((file-no (web-check-if-buffer-is-one-of-the-web-files))
include-file-name
)
(goto-char (point-min))
(while (and (not done)
(re-search-forward search-string
(aref stopping-point file-no) t)
) ; end condition
(if (char-equal ?i
(string-to-char (buffer-substring (match-beginning 1)
(match-end 1))))
; then
(save-excursion
(setq include-file-name (buffer-substring (point)
(save-excursion (end-of-line) (point))))
(setq include-file-name (substring include-file-name 0
(string-match " " include-file-name 1)))
(set-buffer (get-file-buffer (expand-file-name
(web-eliminate-white-space include-file-name)
web-default-directory)))
(web-count-the-matches "^@\\(i\\| \\|\t\\|\n\\|\\*\\)")
) ; end excursion
; else
(setq module-count (1+ module-count))
) ; end if
) ; end while
(if (= file-no file-number)
; then we are done
(setq done t)
) ; end if
) ; end let
) ; end excursion
)
(defun web-delimiter-match-check ()
"This function checks if all module delimiters (namely, @<...@>) are matched.
It records any missing delimiter pairs, whether they be opening or closing
pairs that are missing. If any missing delimiters are discovered, a window
pops up with the pertinent information. The user then needs to rectify the
situation and re-invoke \\[web-mode].
ARGUMENTS : None
GLOBAL Variable : web-module-begins
LOCAL Variables : balance, bound-for-search, closing-delimiters,
next-module-begins, opening-char, opening-delimiters,
and valid-delimiter
RETURNS : balance (boolean indicating if module delimiters are balanced)
USES : web-check-if-buffer-is-one-of-the-web-files and web-journal"
(interactive)
(web-journal "web-delimiter-match-check")
(web-check-if-buffer-is-one-of-the-web-files)
(let ((balance t)
(bound-for-search 1)
closing-delimiters
(module-number 1)
(next-module-begins 0)
opening-char
opening-delimiters
valid-delimiter
)
(save-excursion
(goto-char (point-min))
(while (re-search-forward web-module-begins nil t)
(message "Checking balance in Module %d" module-number)
(setq bound-for-searc (point))
(save-excursion
(if (not (re-search-forward web-module-begins nil t))
; then
(setq next-module-begins (point-max))
; else
(goto-char (match-beginning 0))
(setq next-module-begins (point))
) ; end if
) ; end excursion
(while (re-search-forward "\\(@@\\)*@\\(<\\|>\\)"
next-module-begins t)
(save-excursion
(goto-char (match-beginning 0))
(if (char-equal (preceding-char) ?@)
; then
(setq valid-delimiter nil)
; else
(setq valid-delimiter t)
) ; end if
) ; end excursion
(if valid-delimiter
; then
(progn
(cond
((char-equal (preceding-char) ?<)
(setq opening-delimiters (cons
(count-lines (point-min) (point)) opening-delimiters))
) ; end case
((char-equal (preceding-char) ?>)
(save-excursion
(setq opening-char nil)
(while (and (null opening-char)
(re-search-backward
"\\(@@\\)*@\\(\\^\\|\\.\\|:\\|t\\|=\\|<\\)"
bound-for-search t))
(if (char-equal (preceding-char) ?@)
; then keep searching backward
()
; else
(setq opening-char (string-to-char (buffer-substring
(match-beginning 2) (match-end 2))))
) ; end if
) ; end while
) ; end excursion
(cond
((null opening-char) ; then missing an opening delimiter
(setq closing-delimiters (append closing-delimiters
(list (count-lines (point-min) (point)))))
) ; end case
((char-equal opening-char ?<) ; valid module name
(setq opening-delimiters (cdr opening-delimiters))
) ; end case
) ; end cond
(setq bound-for-search (point))
) ; end case
) ; end cond
) ; end then
) ; end if
) ; end while
(setq module-number (1+ module-number))
) ; end while
) ; end excursion
(if (and (null opening-delimiters) (null closing-delimiters))
; then
(message "All module delimiters match")
; else
(setq balance nil)
(with-output-to-temp-buffer "*Missing Delimiters*"
(princ
"After these errors are fixed, reissue the command M-x web-mode.")
(if (not (null opening-delimiters))
; then
(if (nth 1 opening-delimiters)
; then
(princ (format
"\nThe @<'s located on lines %s are missing an @>."
(sort opening-delimiters '<)))
; else
(princ (format "\nThe @< located on line %d is missing an @>."
(car opening-delimiters)))
) ; end if
) ; end if
(if (not (null closing-delimiters))
; then
(if (nth 1 closing-delimiters)
; then
(princ (format
"\nThe @>'s located on lines %s are missing an @<."
closing-delimiters))
; else
(princ (format "\nThe @> located on line %d is missing an @<."
(car closing-delimiters)))
) ; end if
) ; end if
) ; end output to temp buffer
) ; end if
balance ; return the boolean indicating if module delimiters balance
) ; end let
)
(defun web-determine-characteristics ()
"This function is used to give the user an idea of how many lines of text
exist in each module's commentary, definition/macro, and code parts.
ARGUMENTS : None
GLOBAL Variables : web-default-directory and web-files
LOCAL Variables : code, code-begins, ctr, current-position, divider,
done, file-no, header, header1, header2, header3, header4,
line-in-table, lines-in-code, lines-in-commentary,
lines-in-macros, macros, macros-begin, max-module,
module-no, next-module-begins, number-of-columns,
space-to-left-of-table, spacer, spanner, stat-buffer-name,
title, and width-of-table
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-count-modules,
web-determine-characteristics-for-buffer, and web-journal"
(interactive)
(web-journal "web-determine-characteristics")
(web-check-if-buffer-is-one-of-the-web-files)
(let* ((module-no 1)
(max-module (web-count-modules))
(number-of-columns 4)
(header1 "Module #")
(header2 "Commentary")
(header3 "Macros")
(header4 "Code")
(spanner "Number of Lines in")
(title (concat "STATISTICS FOR "
(upcase (buffer-name (current-buffer)))))
(spacer 2)
(width-of-table (+ (length header1) (length header2)
(length header3) (length header4) (* number-of-columns spacer 2)
(1+ number-of-columns)))
(space-to-left-of-table (/ (- (screen-width) width-of-table) 2))
(divider (concat
(make-string space-to-left-of-table ? ) "|"
(make-string (+ (length header1) (* spacer 2)) ?_) "|"
(make-string (+ (length header2) (* spacer 2)) ?_) "|"
(make-string (+ (length header3) (* spacer 2)) ?_) "|"
(make-string (+ (length header4) (* spacer 2)) ?_) "|\n"
(make-string space-to-left-of-table ? ) "|"
(make-string (+ (length header1) (* spacer 2)) ? ) "|"
(make-string (+ (length header2) (* spacer 2)) ? ) "|"
(make-string (+ (length header3) (* spacer 2)) ? ) "|"
(make-string (+ (length header4) (* spacer 2)) ? ) "|\n"))
(header (concat
(make-string (/ (- (screen-width) (length title)) 2) ? )
title "\n"
(make-string (1+ (/ (- (screen-width) width-of-table) 2)) ? )
(make-string (- width-of-table 2) ?_) "\n"
(make-string space-to-left-of-table ? ) "|"
(make-string (+ (length header1) (* spacer 2))? ) "|"
(make-string (+ (length header2) (length header3)
(length header4) (* 3 spacer 2) 2) ? ) "|\n"
(make-string space-to-left-of-table ? ) "|"
(make-string (+ (length header1) (* spacer 2)) ? ) "|"
(make-string (/ (- (+ (length header2) (length header3)
(length header4) (* 3 spacer 2) 2) (length spanner)) 2) ? )
spanner
(make-string (1- (- (- width-of-table (+ (length header1)
(* spacer 2) 2)) (+ (/ (- (+ (length header2) (length header3)
(length header4) (* 3 spacer 2) 2) (length spanner)) 2)
(length spanner)))) ? ) "|\n"
(make-string space-to-left-of-table ? ) "|"
(make-string (+ (length header1) (* spacer 2)) ? ) "|"
(make-string (1- (- width-of-table (+ (length header1)
(* spacer 2) 2))) ?_) "|\n"
(make-string space-to-left-of-table ? ) "|"
(make-string (+ (length header1) (* spacer 2)) ? ) "|"
(make-string (+ (length header2) (* spacer 2)) ? ) "|"
(make-string (+ (length header3) (* spacer 2)) ? ) "|"
(make-string (+ (length header4) (* spacer 2)) ? ) "|\n"
(make-string space-to-left-of-table ? ) "|"
(make-string spacer ? ) header1
(make-string spacer ? ) "|"
(make-string spacer ? ) header2
(make-string spacer ? ) "|"
(make-string spacer ? ) header3
(make-string spacer ? ) "|"
(make-string spacer ? ) header4
(make-string spacer ? ) "|\n"
(make-string space-to-left-of-table ? ) "|"
(make-string (+ (length header1) (* spacer 2)) ?_) "|"
(make-string (+ (length header2) (* spacer 2)) ?_) "|"
(make-string (+ (length header3) (* spacer 2)) ?_) "|"
(make-string (+ (length header4) (* spacer 2)) ?_) "|\n"
(make-string space-to-left-of-table ? ) "|"
(make-string (+ (length header1) (* spacer 2)) ? ) "|"
(make-string (+ (length header2) (* spacer 2)) ? ) "|"
(make-string (+ (length header3) (* spacer 2)) ? ) "|"
(make-string (+ (length header4) (* spacer 2)) ? ) "|\n"))
code
(code-begins)
(ctr 0)
(current-position 0)
done
file-no
line-in-table
(lines-in-code 0)
(lines-in-commentary 0)
(lines-in-macros 0)
macros
(macros-begin 0)
(next-module-begins 0)
(stat-buffer-name (concat "*STATISTICS for "
(buffer-name (current-buffer)) "*"))
)
(generate-new-buffer stat-buffer-name)
(save-excursion
(set-buffer stat-buffer-name)
(use-local-map web-mode-map)
(setq major-mode 'Web-mode
mode-name "Web")
(goto-char (point-min))
(kill-line (count-lines (point-min) (point-max)))
) ; end excursion
(save-excursion
(set-buffer (get-file-buffer (expand-file-name (nth 1 web-files)
web-default-directory)))
(setq file-no (cons (web-check-if-buffer-is-one-of-the-web-files)
file-no))
(web-determine-characteristics-for-buffer)
) ; end excursion
(switch-to-buffer stat-buffer-name)
(goto-char (point-min))
) ; end let
)
(defun web-determine-characteristics-for-buffer ()
"This is an internal support function used by
\\[web-determine-characteristics] to write the characteristics of each
individual buffer to the buffer where they are being recorded.
ARGUMENTS : None
GLOBAL Variables : web-default-directory and web-files
LOCAL Variables : code, code-begins, ctr, current-position, divider,
done, file-no, header, header1, header2, header3, header4,
include-file-name,
line-in-table, lines-in-code, lines-in-commentary,
lines-in-macros, macros, macros-begin, max-module,
module-no, next-module-begins, number-of-columns,
space-to-left-of-table, spacer, spanner, stat-buffer-name,
title, and width-of-table
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files and
web-eliminate-white-space"
(save-excursion
(goto-char (point-min))
(while (re-search-forward "^@\\(i\\| \\|\t\\|\n\\|\\*\\)" nil t)
(if (char-equal ?i
(string-to-char
(buffer-substring (match-beginning 1) (match-end 1))))
; then switch to include file and collect its characteristics
(save-excursion
(setq include-file-name (buffer-substring (point)
(save-excursion (end-of-line) (point))))
(setq include-file-name (substring include-file-name 0
(string-match " " include-file-name 1)))
(set-buffer (get-file-buffer (expand-file-name
(web-eliminate-white-space include-file-name)
web-default-directory)))
(setq file-no (cons (web-check-if-buffer-is-one-of-the-web-files)
file-no))
(web-determine-characteristics-for-buffer)
) ; end excursion
; else continue collecting in the same buffer
(setq current-position (count-lines (point-min) (point)))
(save-excursion
(if (re-search-forward "^@\\(i\\| \\|\t\\|\n\\|\\*\\)" nil t)
; then
(setq next-module-begins (point))
; else
(setq next-module-begins (point-max))
) ; end if
) ; end excursion
(save-excursion
(setq macros nil)
(if (re-search-forward "@\\(d\\|f\\)" next-module-begins t)
; then
(progn
(backward-char 2)
(setq done nil
ctr 0)
(while (null done)
(while (looking-at "@")
(backward-char 1)
(setq ctr (1+ ctr))
)
(forward-char (+ ctr 2))
(if (not (zerop (% ctr 2)))
; then
(setq macros t
done t
macros-begin (count-lines (point-min) (point)))
; else
(if (re-search-forward "@\\(d\\|f\\)" next-module-begins t)
; then
(backward-char 2)
; else
(setq done t)
) ; end if
) ; end if
) ; end while
) ; end then
) ; end if
) ; end excursion
(save-excursion
(setq code nil)
(if (re-search-forward "@\\(p\\|c\\|<\\)" next-module-begins t)
; then
(progn
(backward-char 2)
(setq done nil
ctr 0)
(while (null done)
(while (looking-at "@")
(backward-char 1)
(setq ctr (1+ ctr))
)
(forward-char (+ ctr 2))
(if (not (zerop (% ctr 2)))
; then
(setq code t
done t
code-begins (count-lines (point-min) (point)))
; else
(if (re-search-forward "@\\(<\\|p\\|c\\)"
next-module-begins t)
; then
(backward-char 2)
; else
(setq done t)
) ; end if
) ; end if
) ; end while
) ; end then
) ; end if
) ; end excursion
(setq next-module-begins (count-lines
(point-min) next-module-begins))
(cond
((and (null macros) (null code))
(setq lines-in-commentary
(- next-module-begins current-position))
(setq lines-in-macros 0)
(setq lines-in-code 0)
)
((and (null macros) (not (null code)))
(setq lines-in-commentary (- code-begins current-position))
(setq lines-in-macros 0)
(setq lines-in-code (- next-module-begins code-begins))
)
((and (not (null macros)) (null code))
(setq lines-in-commentary (- macros-begin current-position))
(setq lines-in-macros (- next-module-begins macros-begin))
(setq lines-in-code 0)
)
((and (not (null macros)) (not (null code)))
(setq lines-in-commentary (- macros-begin current-position))
(setq lines-in-macros (- code-begins macros-begin))
(setq lines-in-code (- next-module-begins code-begins))
)
) ; end cond
(setq line-in-table (concat
(make-string space-to-left-of-table ? ) "|"
(make-string spacer ? )
(make-string (- (length header1)
(length (int-to-string module-no))) ? )
(int-to-string module-no)
(make-string spacer ? ) "|"
(make-string spacer ? )
(make-string (- (length header2)
(length (int-to-string lines-in-commentary))) ? )
(int-to-string lines-in-commentary)
(make-string spacer ? ) "|"
(make-string spacer ? )
(make-string (- (length header3)
(length (int-to-string lines-in-macros))) ? )
(int-to-string lines-in-macros)
(make-string spacer ? ) "|"
(make-string spacer ? )
(make-string (- (length header4)
(length (int-to-string lines-in-code))) ? )
(int-to-string lines-in-code)
(make-string spacer ? ) "|\n"
) ; ends concat
) ; ends setq
(message "Module %d" module-no)
(set-buffer stat-buffer-name)
(if (= module-no 1)
; then
(progn
(goto-char (point-min))
(kill-line (count-lines (point-min) (point-max)))
(insert-string header)
) ; end then
) ; end if
(insert-string line-in-table)
(cond
((= module-no max-module)
(setq divider (concat
(make-string space-to-left-of-table ? ) "|"
(make-string (+ (length header1) (* spacer 2)) ?_) "|"
(make-string (+ (length header2) (* spacer 2)) ?_) "|"
(make-string (+ (length header3) (* spacer 2)) ?_) "|"
(make-string (+ (length header4) (* spacer 2)) ?_) "|\n"
) ; end concat
) ; end setq
(insert-string divider)
) ; end case
((zerop (% module-no 3))
(insert-string divider)
) ; end case
) ; end cond
(setq module-no (1+ module-no))
(set-buffer (get-file-buffer (expand-file-name
(nth (car file-no) web-files) web-default-directory)))
) ; end if
) ; end while
(setq file-no (cdr file-no))
) ; end excursion
)
(defun web-determine-module-name-ending ()
"This function determines if the appropriate ending to a module name is @> or
@>=.
ARGUMENTS : None
GLOBAL Variable : web-module-begins
LOCAL Variables : at-greater-than-equal, at-p, module-name-ending,
next-module-begins, and this-module-begins
RETURNS : module-name-ending
USES : Nothing"
(let (at-greater-than-equal
at-p
module-name-ending
(next-module-begins 0)
(this-module-begins 0)
)
(save-excursion
(re-search-backward web-module-begins nil t)
(setq this-module-begins (point))
) ; end excursion
(save-excursion
(if (re-search-forward web-module-begins nil t)
; then
(progn
(goto-char (match-beginning 0))
(setq next-module-begins (point))
) ; end then
; else
(setq next-module-begins (point-max))
) ; end if
) ; end excursion
(save-excursion
(goto-char this-module-begins)
(while (and (re-search-forward "\\(@@\\)*@\\(p\\|c\\|r\\|a\\|n\\)"
next-module-begins t)
(null at-p))
(if (not (char-equal ?@
(string-to-char (buffer-substring
(1- (match-beginning 0)) (match-beginning 0)))))
; then it's valid
(setq at-p t)
) ; end if
) ; end while
(if at-p
; then do nothing
()
; else check for a valid @>=
(while (and (re-search-forward "\\(@@\\)*@>="
next-module-begins t)
(null at-greater-than-equal))
(if (not (char-equal ?@
(string-to-char (buffer-substring
(1- (match-beginning 0)) (match-beginning 0)))))
; then it's valid
(setq at-greater-than-equal t)
) ; end if
) ; end while
) ; end if
) ; end excursion
(if (and (null at-greater-than-equal)
(null at-p))
; then
(setq module-name-ending "@>=")
; else
(setq module-name-ending "@>")
) ; end if
module-name-ending ; return the proper ending for the module name
) ; end let
)
(defun web-display-module-names (top bottom &optional arg)
"This function is used to display a list of module names. This function is
invoked by \\[web-options-for-module-name-insertion]. It displays the module
name of the TOP-th car of web-module-names through the BOTTOM-th car of
web-module-names. An optional argument ARG is used to choose between one of
two messages displayed at the bottom of the window.
ARGUMENTS : top (required), bottom (required), and arg (optional)
GLOBAL Variables : web-module-names, web-number-of-lines-in-window, and
web-number-of-module-names
LOCAL Variables : available-lines, ctr, module-name, phrase, and space-on-left
RETURNS : Nothing
USES : Nothing"
(let ((available-lines (- web-number-of-lines-in-window 11))
(ctr top)
module-name
phrase
(space-on-left
(/ (- 6 (length (int-to-string web-number-of-module-names))) 2))
)
(if (null arg)
; then
(setq phrase (format "Displaying %d Module Names of %d"
(1+ (- bottom top)) web-number-of-module-names))
; else
(setq phrase (format "Displaying %d of %d Matches"
(1+ (- bottom top)) arg))
)
(goto-char (point-min))
(forward-line 9)
(kill-line (count-lines (point) (point-max)))
(insert-string "Number Name\n")
(while (<= ctr bottom)
(setq module-name (substring (nth (1- ctr) web-module-names) 0
(string-match " " (nth (1- ctr) web-module-names))))
(if (> (length module-name) 71)
; then
(setq module-name (concat (substring module-name 0 68) "..."))
)
(insert-string (concat (make-string (+ space-on-left
(- (length (int-to-string web-number-of-module-names))
(length (int-to-string ctr)))) ? ) (int-to-string ctr)
(make-string (- 8 (+ space-on-left
(length (int-to-string web-number-of-module-names)))) ? )
module-name "\n"))
(setq ctr (1+ ctr))
) ; end while
(insert-string (make-string (- available-lines (1+ (- bottom top))) ?\012))
(insert-string (concat (make-string (/ (- 79 (length phrase)) 2) ? )
phrase))
) ; end let
)
(defun web-edit-module ()
"This function can only be invoked from the buffer containing the Web
document. Whatever module point is positioned in is the module that is to be
changed. If the module to be changed already appears in the CHange file, the
user is warned but is switched to the buffer containing the CHange file so that
further changes can be made. If the module to be changed does not appear in
the CHange file, the module to be changed from the Web buffer is copied
verbatim at its proper position in the CHange file twice--once between @x and
@y and once between @y and @z. Point is then positioned at the beginning of
the line following @y so that changes can be made.
ARGUMENTS : None
GLOBAL Variables : web-change-buffer-name and web-buffer-name
LOCAL Variables : comment-string, ctr, module-to-be-changed,
module-to-be-changed-begins-at,
and module-to-be-changed-ends-at
RETURNS : Nothing
USES : web-count-changes, web-count-modules,
web-goto-change-corresponding-to-module, web-goto-module, web-journal,
web-what-change, and web-what-module"
(interactive)
(web-journal "web-edit-module")
(if (not (string-equal web-buffer-name (buffer-name (current-buffer))))
; then
(error "Not in the Web buffer that web-mode was used on most recently.")
; else
(let* ((ctr 0)
done
(module-to-be-changed (web-what-module))
(module-to-be-changed-begins-at 0)
(module-to-be-changed-ends-at 0)
(comment-string (concat " Module "
(int-to-string module-to-be-changed) " "
(current-time-string) "\n"))
(total-number-of-modules (web-count-modules))
)
(if (= (aref (aref web-location-of-module module-to-be-changed) 3) 1)
; then the module has already been changed
(progn
(web-goto-change-corresponding-to-module module-to-be-changed)
(message "Module %d has already been CHanged." module-to-be-changed)
) ; end then
; else
(if (zerop module-to-be-changed)
; then the limbo portion of the Web is to be changed
(setq module-to-be-changed-begins-at 1)
; else
(save-excursion
(web-goto-module module-to-be-changed)
(setq module-to-be-changed-begins-at (point))
) ; end excursion
) ; end if
(if (= module-to-be-changed (web-count-modules))
; then the last module is being changed
(setq module-to-be-changed-ends-at (1- (point-max)))
; else
(save-excursion
(web-goto-module (1+ module-to-be-changed))
(backward-char 1)
(while (looking-at "\n") (backward-char 1))
(setq module-to-be-changed-ends-at (1+ (point)))
) ; end excursion
) ; end if
(setq ctr (1+ module-to-be-changed))
(while (not done)
(cond
((or (> ctr total-number-of-modules)
(= (aref (aref web-location-of-module ctr) 3) 1))
(setq done t)
) ; end case
(t
(setq ctr (1+ ctr)
done nil)
) ; end case
) ; end cond
) ; end while
(switch-to-buffer web-change-buffer-name)
(goto-char (point-min))
; position point in the CHange file for the insertion of the
; contents of the module that is to be changed. Update the
; web-location-of-module vector.
(cond
((zerop (web-count-changes))
(goto-char (point-max))
(aset (aref web-location-of-module module-to-be-changed) 3 1)
(aset (aref web-location-of-module module-to-be-changed) 4 1)
) ; end case
((= ctr (1+ total-number-of-modules))
; then the new change goes at the bottom of the CHange file
(goto-char (point-max))
; update the web-location-of-module vector
(aset (aref web-location-of-module module-to-be-changed) 3 1)
(save-excursion
(re-search-backward "^@z" nil t)
(aset (aref web-location-of-module module-to-be-changed) 4
(1+ (aref (aref web-location-of-module (web-what-change)) 4)))
) ; end excursion
) ; end case
(t
(re-search-forward "^@x" nil t ctr)
(goto-char (match-beginning 0))
(recenter 0)
(aset (aref web-location-of-module module-to-be-changed) 3 1)
(aset (aref web-location-of-module module-to-be-changed) 4
(aref (aref web-location-of-module ctr) 4))
(while (<= ctr total-number-of-modules)
(if (not (zerop (aref (aref web-location-of-module ctr) 3)))
; then increment the relative position in the CHange file
(aset (aref web-location-of-module ctr) 4
(1+ (aref (aref web-location-of-module ctr) 4)))
) ; end if
(setq ctr (1+ ctr))
) ; end while
) ; end case
) ; end cond
(if (re-search-backward "^@z" nil t)
; then
(progn
(forward-line 1)
(if (not (looking-at "\n"))
; then
(newline)
; else
(forward-line)
) ; end if
) ; end then
) ; end if
(insert "@x" comment-string)
(insert-buffer-substring web-buffer-name
module-to-be-changed-begins-at (1+ module-to-be-changed-ends-at))
(insert "@y" comment-string)
(insert-buffer-substring web-buffer-name
module-to-be-changed-begins-at (1+ module-to-be-changed-ends-at))
(insert "@z" comment-string "\n")
(re-search-backward "^@y" nil t)
(recenter 0)
(message "Module %d is ready to be changed." module-to-be-changed)
) ; end if
) ; end let
) ; end if
)
(defun web-eliminate-control-sequences (search-string
&optional replacement-string)
"This is an internal support function used to eliminate delimited control
sequences. The function searches for SEARCH-STRING replaces these delimited
control sequences with their argument. An optional REPLACEMENT-STRING will be
appended to the argument of the control sequence if present. This function is
used when the index is being reformatted. For example, the index contains
entries such as \[#] (where # represents a module number where the index entry
was referenced) which are to be underlined in the final output. This function
replaces the sequence with #.
ARGUMENTS : search-string (required) and replacement-string (optional)
GLOBAL Variables : None
LOCAL Variables : None
RETURNS : Nothing
USES : Nothing"
(save-excursion
(goto-char (point-min))
(while (re-search-forward search-string nil t)
(backward-char (length (buffer-substring (match-beginning 0)
(match-end 0))))
(insert-string (concat (buffer-substring (match-beginning 1)
(match-end 1)) replacement-string))
(delete-char (length (buffer-substring (match-beginning 0)
(match-end 0))))
) ; end while
) ; end excursion
)
(defun web-eliminate-white-space (string)
"This is an internal function used to eliminate all leading, trailing, and
multiple inner occurrences of white space (tabs, carriage returns, and spaces)
in STRING. The resulting string will always have a leading space, and hence,
must be deleted before returning. If the last character in the input string is
white space, a trailing space will also be present, and it, too, must be
deleted before returning. This code adapted from Knuth (see Module 153 in
tangle.web).
ARGUMENT : string (required)
GLOBAL Variables : None
LOCAL Variables : d, k, loc, new-string
RETURNS : new-string
USES : Nothing"
(let (d
(k 1)
(loc 1)
(new-string " ")
)
(while (<= loc (length string))
(setq d (substring string (1- loc) loc)
loc (1+ loc)
k (1+ k))
(if (or (string-equal d " ")
(string-equal d "\n")
(string-equal d "\t"))
; then
(progn
(setq d " ")
(if (string-equal (substring new-string (- k 2) (1- k)) " ")
; then
(setq k (1- k))
) ; end if
) ; end then
) ; end if
(setq new-string (concat (substring new-string 0 (1- k)) d))
); end while
(if (string-equal (substring new-string (1- k) k) " ")
; then
(setq new-string (substring new-string 0 (1- k)))
) ; end if
(substring new-string 1 (length new-string)) ; return the new string
) ; end let
)
(defun web-file ()
"Makes the buffer that contains the Web document the current buffer.
ARGUMENTS : None
LOCAL Variables : None
GLOBAL Variables : web-buffer-name
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files and web-journal"
(interactive)
(web-journal "web-file")
(web-check-if-buffer-is-one-of-the-web-files)
(switch-to-buffer web-buffer-name)
)
(defun web-goto-change-corresponding-to-module (goto-change-number)
"This function positions point at the beginning of the change that
corresponds to module GOTO-CHANGE-NUMBER. If no prefix argument is provided,
the function prompts for one.
ARGUMENT : goto-change-number (required)
GLOBAL Variables : None
LOCAL Variables : None
RETURNS : Nothing
USES : web-change-file, web-count-modules, and web-journal"
(interactive "NGoto change corresponding to module: ")
(web-journal "web-goto-change-corresponding-to-module")
(cond
((or (< goto-change-number 0)
(> goto-change-number (web-count-modules)))
(error "There is no change that corresponds to %d." goto-change-number)
) ; end case
((zerop (aref (aref web-location-of-module goto-change-number) 3))
(error "Module %d has not been CHanged." goto-change-number)
) ; end case
(t
(web-change-file)
(goto-char (point-min))
(re-search-forward "^@y" nil t
(aref (aref web-location-of-module goto-change-number) 4))
(goto-char (match-beginning 0))
(recenter 0)
(message "CHange for module %d" goto-change-number)
) ; end case
) ; end cond
)
(defun web-goto-module (goto-module-number)
"This function positions point at the beginning of the GOTO-MODULE-NUMBER
module in the Web document. If no argument is provided, the user is prompted
for one. The function will not permit a user to go to a module labelled 0 or
less; nor will it permit a user to go to a module that exceeds the total number
of modules.
ARGUMENT : goto-module-number (required)
GLOBAL Variables : web-location-of-module, web-files, web-default-directory,
web-module-begins, and web-module-changed-then-goto-change
LOCAL Variable : tot-num-modules
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-count-modules,
and web-journal"
(interactive "NGoto module: ")
(web-journal "web-goto-module")
(web-check-if-buffer-is-one-of-the-web-files)
(let ((tot-num-modules (web-count-modules)))
(cond
((< goto-module-number 1)
(error "There is no module %d." goto-module-number)
) ; end case
((> goto-module-number tot-num-modules)
(error "Can't go to module %d. There are only %d modules."
goto-module-number tot-num-modules)
) ; end case
(t
(if web-module-changed-then-goto-change
; then
(progn
(web-change-file)
(goto-char (point-min))
(re-search-forward "^@y" nil t
(aref (aref web-location-of-module goto-module-number) 4))
(goto-char (match-beginning 0))
(recenter 0)
) ; end then
; else
(switch-to-buffer (get-file-buffer (expand-file-name
(nth (aref (aref web-location-of-module goto-module-number) 0)
web-files) web-default-directory)))
(goto-char (point-min))
(re-search-forward web-module-begins nil t
(aref (aref web-location-of-module goto-module-number) 1))
(goto-char (match-beginning 0))
(recenter 0)
) ; end if
(message "Module %d in %s. %s" goto-module-number (nth 1 web-files)
(if (= (aref (aref web-location-of-module goto-module-number) 3) 1)
"This module has been CHanged." " "))
) ; end case
) ; end cond
) ; end let
)
(defun web-goto-section (goto-section-number)
"This function positions point at the beginning of the GOTO-SECTION-NUMBER
section in the Web document. If no argument is provided, the user is prompted
for one. The function will not permit a user to go to a section labelled 0 or
less; nor will it permit a user to go to a section that exceeds the total
number of sections. If the current buffer is not the buffer containing the Web
document, the buffer containing the Web document is made the current buffer.
ARGUMENT : goto-section-number (required)
GLOBAL Variables : web-location-of-module and web-files
LOCAL Variable : ctr and tot-num-sections
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-count-sections,
web-goto-module, and web-journal"
(interactive "NGoto Section Number: ")
(web-journal "web-goto-section")
(web-check-if-buffer-is-one-of-the-web-files)
(let ((tot-num-sections (web-count-sections))
(ctr 1)
)
(cond
((< goto-section-number 1)
(error "There is no section %d." goto-section-number)
)
((> goto-section-number tot-num-sections)
(error "Can't go to section %d. There are only %d sections."
goto-section-number tot-num-sections)
)
(t
(while (/= (aref (aref web-location-of-module ctr) 2)
goto-section-number)
(setq ctr (1+ ctr))
) ; end while
(web-goto-module ctr)
(message "Section %d in %s" goto-section-number
(upcase (nth 1 web-files)))
) ; end case
) ; end cond
) ; end let
)
(defun web-include-file (include-file-number)
"This function switches to the buffer containing the contents of include file
INCLUDE-FILE-NUMBER.
ARGUMENTS include-file-number (required)
GLOBAL Variables : web-default-directory and web-files
LOCAL Variables : None
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files and web-journal"
(interactive "NInclude File to be switch to: ")
(web-journal "web-include-file")
(web-check-if-buffer-is-one-of-the-web-files)
(if (or (< include-file-number 1)
(> include-file-number (- (length web-files) 2)))
; then
(error "There is no include file numbered %d" include-file-number)
; else
(switch-to-buffer (get-file-buffer (expand-file-name
(nth (1+ include-file-number) web-files) web-default-directory)))
(goto-char (point-min))
) ; end if
)
(defun web-initialize-location-of-module-vector ()
"This is an internal support function used to initialize the
web-location-of-module vector.
ARGUMENTS : NONE
GLOBAL Variables : web-change-buffer-name, web-location-of-module,
web-number-of-modules-in-file, web-buffer-name
web-files, and web-max-number-of-modules
LOCAL Variables : file-number, module-number, and section-number
RETURNS : Nothing
USES : web-collect-location-of-modules"
(let ((file-number '(1))
(module-number 1)
(section-number 0)
)
(setq web-location-of-module (make-vector (1+ web-max-number-of-modules)
(make-vector 5 0))
web-number-of-modules-in-file (make-vector 20 0)
web-files ()
) ; end setq
(aset web-location-of-module 0 (vector 1 0 0 0 0))
(setq web-files (append web-files (list web-change-buffer-name)
(list web-buffer-name)))
(set-buffer (nth (car file-number) web-files))
(message "Collecting the vector web-location-of-module...")
(web-collect-location-of-modules)
(message "Collecting the vector web-location-of-module...done")
) ; end let
)
(defun web-initialize-module-names-list ()
"This function is invoked by \\[web-mode] if 1) filename.mods exists and
2) filename.mods is newer than filename.web. If these two conditions are
true, then \\[web-mode] does not need to collect the web-module-names list from
scratch. It can read this information from the file filename.mods.
ARGUMENTS : None
GLOBAL Variable : web-module-name-defined-in-used-in, web-module-names,
web-number-of-module-names, web-buffer-name,
and web-default-directory
LOCAL Variables : defined-in-list, module-name, module-name-begins,
and used-in-list
RETURNS : Nothing
USES : web-eliminate-white-space"
(let (defined-in-list
module-name
(module-name-begins 0)
used-in-list
)
(find-file-noselect (expand-file-name
(concat (substring web-buffer-name 0
(string-match "\\." web-buffer-name)) ".mods") web-default-directory))
(set-buffer (concat (substring web-buffer-name 0
(string-match "\\." web-buffer-name)) ".mods"))
(goto-char (point-min))
(while (not (eobp))
(setq module-name-begins (point))
(forward-line 1)
(while (and (not (eobp))
(char-equal
(string-to-char (buffer-substring (point) (1+ (point))))
? )
) ; end condition
(forward-line 1)
) ; end while
(save-excursion
(re-search-backward "(" nil t 2)
(setq module-name (web-eliminate-white-space
(buffer-substring module-name-begins (point))))
) ; end excursion
(save-excursion
(setq defined-in-list ())
(re-search-backward "(" nil t 2)
(while (not (looking-at ")"))
(re-search-forward "[0-9]+" nil t)
(setq defined-in-list (append defined-in-list (list (string-to-int
(buffer-substring (match-beginning 0) (match-end 0))))))
) ; end while
) ; end excursion
(save-excursion
(setq used-in-list ())
(re-search-backward "(" nil t)
(while (not (looking-at ")"))
(re-search-forward "[0-9]+" nil t)
(setq used-in-list (append used-in-list (list (string-to-int
(buffer-substring (match-beginning 0) (match-end 0))))))
) ; end while
) ; end excursion
(setq web-module-name-defined-in-used-in
(append web-module-name-defined-in-used-in (list
(list module-name defined-in-list used-in-list))))
(setq web-module-names (append web-module-names (list
(concat module-name " " (int-to-string web-number-of-module-names)))))
(setq web-number-of-module-names (1+ web-number-of-module-names))
) ; end while
) ; end let
)
(defun web-insert-index-entry (&optional type-style phrase)
"This function inserts the necessary constructs so that an entry is placed in
the index by Weave. Web supports three types of index entries. They differ in
the type of type style used in the index itself. This function asks the user
which TYPE-STYLE he prefers. Once a valid selection has been made, it asks for
the PHRASE to be inserted in the index.
ARGUMENTS : type-style and phrase (both required)
GLOBAL Variables : None
LOCAL Variables : first-part and prompt
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files and web-journal"
(interactive)
(web-journal "web-insert-index-entry")
(web-check-if-buffer-is-one-of-the-web-files)
(let (first-part
(prompt "rm(R/r), tt(T/t), or User-Defined(U/u): ")
)
(if type-style
; then an explicit argument has been provided
()
; else prompt for the type-style
(setq type-style (read-string (concat "Type Style: " prompt)))
(while (and (not (string-equal (upcase type-style) "R"))
(not (string-equal (upcase type-style) "U"))
(not (string-equal (upcase type-style) "T"))
)
(ding)
(setq type-style (read-string (concat "Try again. " prompt)))
) ; end while
) ; end if
(cond
((string-equal (upcase type-style) "U")
(setq first-part "@:")
) ; end case
((string-equal (upcase type-style) "T")
(setq first-part "@.")
) ; end case
(t ; default
(setq first-part "@^")
) ; end case
) ; end cond
(if (null phrase)
(setq phrase (read-string "Phrase to be placed in index: "))
)
(end-of-line)
(newline)
(insert first-part phrase "@>")
(newline)
) ; end let
)
(defun web-insert-limbo-material ()
"This function is only invoked by \\[web-mode] when the edit buffer is empty,
i.e., one is beginning a new Web document. The user is prompted for the title
of the Web.
ARGUMENTS : None
GLOBAL Variables : None
LOCAL Variables : limbo-file-name, line1, line2, line3, position-of-colon,
title, and width
RETURNS : Nothing
USES : Nothing"
(let (limbo-file-name
(line1 (concat "PROGRAM : " (buffer-name (current-buffer))))
(line2 (concat "CREATOR : " (user-full-name) " [" (user-login-name)
"@" (system-name) "]"))
(line3 (concat "CREATION DATE : " (current-time-string)))
(position-of-colon 0)
title
(width 0)
)
(cond
((and (>= (length line1) (length line2))
(>= (length line1) (length line3)))
(setq width (length line1)
position-of-colon (+ (/ (- 77 width) 2) 9))
) ; end case
((and (>= (length line2) (length line1))
(>= (length line2) (length line3)))
(setq width (length line2)
position-of-colon (+ (/ (- 77 width) 2) 9))
) ; end case
((and (>= (length line3) (length line1))
(>= (length line3) (length line2)))
(setq width (length line3)
position-of-colon (+ (/ (- 77 width) 2) 15))
) ; end case
(t
(error
"In web-insert-limbo-material. Shouldn't have reached this code.")
) ; end case
) ; end cond
; insert a nice header
(insert (make-string 79 ?%) "\n"
?% (make-string 77 ? ) ?% "\n"
?% (make-string (- position-of-colon 9) ? ) line1
(make-string (- 77 (+ (length line1) (- position-of-colon 9))) ? )
"%\n"
?% (make-string (- position-of-colon 9) ? ) line2
(make-string (- 77 (+ (length line2) (- position-of-colon 9))) ? )
"%\n"
?% (make-string (- position-of-colon 15) ? ) line3
(make-string (- 77 (+ (length line3) (- position-of-colon 15))) ? )
"%\n"
?% (make-string 77 ? ) "%\n"
(make-string 79 ?%) "\n")
(let ((insert-default-directory t))
(while (null (file-readable-p (setq limbo-file-name
(read-file-name "File containing limbo material "
(expand-file-name "limbo.material")
(expand-file-name "limbo.material")))))
(ding)
(message "%s does not exist or is non-readable" limbo-file-name)
(sit-for 2)
) ; end while
) ; end let
(insert-file-contents limbo-file-name)
(setq title (read-string "Title of Web: "))
(goto-char (point-min))
(if (re-search-forward "\\\\def\\\\title{{\\\\tt " nil t)
; then
(insert-string title)
) ; end if
(goto-char (point-max))
) ; end let
)
(defun web-insert-module-name ()
"This function is invoked when the user presses <. This function must look
at the preceding characters to determine if this represents the beginning of a
module name or not. If the < is preceded by an odd number of @'s, then it
represents the beginning of a module name; otherwise, it doesn't.
ARGUMENTS : None
GLOBAL Variables : None
LOCAL Variable : ctr
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files,
web-options-for-module-name-insertion, web-journal, and web-what-module"
(interactive)
(web-journal "web-insert-module-name")
(let ((ctr 0)
(file-no (web-check-if-buffer-is-one-of-the-web-files))
)
(backward-char 1)
(while (and (not (bobp)) (looking-at "@"))
(backward-char 1)
(setq ctr (1+ ctr))
) ; end while
(forward-char (1+ ctr))
(insert-char ?< 1)
(cond
((and (not (zerop (% ctr 2))) (>= (web-what-module) 1))
; then the preceding @< marks the beginning of a module name
(web-options-for-module-name-insertion)
) ; end case
((and (not (zerop (% ctr 2))) (< (web-what-module) 1))
; then we have a valid module beginning but are in the limbo portion
(delete-backward-char (1+ ctr))
(error "You can't insert a module name in the limbo portion")
) ; end case
) ; end cond
) ; end let
)
(defun web-is-this-a-new-module-beginning ()
"This function is invoked whenever the user enters the character @. The
function then reads the next character. If this next character is in the set
{ (space),*,\\t(tab),\\n(newline)}, then it begins a new module and the vector
web-location-of-module must be updated to reflect this addition. The @ must be
at the beginning of a new line to be a valid module beginning.
ARGUMENTS : None
GLOBAL Variables : None
LOCAL Variable : next-char
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-insert-module-name,
web-update-the-location-of-module-vector, and web-journal"
(interactive)
(web-journal "web-is-this-a-new-module-beginning")
(web-check-if-buffer-is-one-of-the-web-files)
(if (not (bolp))
; then insert an @ -- it's not the beginning of a new module
(insert-char ?@ 1)
; else get the next character
(let ((next-char (read-char)))
(if (not (or (char-equal next-char ? )
(char-equal next-char ?<)
(char-equal next-char ?*)
(char-equal next-char ?\t)
(char-equal next-char ?\015))) ; RET = ^M = \015 (octal)
; then insert an @ and the last input char -- it's not the beginning
; of a new module
(progn
(insert-char ?@ 1)
(insert-char next-char 1)
) ; end then
; else this does begin a new module, major section, or code section
(insert-char ?@ 1)
(if (char-equal next-char ?<)
; then
(web-insert-module-name)
; else
(if (char-equal next-char ?\015)
; then
(insert-char ?\012 1)
; else
(insert-char next-char 1)
) ; end if
(web-update-the-location-of-module-vector next-char)
) ; end if
) ; end if
) ; end let
) ; end if
)
(defun web-journal (function-name)
"This function keeps track of the number of times FUNCTION-NAME has been
invoked. Only the interactive functions in web-mode are kept track of.
ARGUMENTS : function-name (required)
GLOBAL Variables : web-interactive-function-usage, web-buffer-name, and
web-interactive-functions
LOCAL Variables : ctr, start-time-in-seconds, stop-time,
stop-time-in-seconds, time-in-web-mode, and
time-in-web-mode-as-string
RETURNS : Nothing
USES : web-binary-search-of-names"
(let ((ctr 0)
(start-time-in-seconds 0)
stop-time
(stop-time-in-seconds 0)
(time-in-web-mode 0)
time-in-web-mode-as-string
)
(cond
((string-equal function-name "web-mode")
; web-mode is the first function invoked
; thus, do initialization
(get-buffer-create "web-mode.jou")
(setq web-interactive-function-usage
(make-vector (length web-interactive-functions) 0)
start-time (current-time-string))
(save-excursion
(set-buffer "web-mode.jou")
(goto-char (point-min))
(kill-line (count-lines (point-min) (point-max)))
(insert (make-string 79 ?\045)
"\nUSER : " (user-full-name) " [" (user-login-name)
"@" (system-name) "]\nFILE : " web-buffer-name "\nSTART TIME : "
start-time "\n")
) ; end excursion
) ; end case
((string-equal function-name "web-mode-save-buffers-kill-emacs")
; this is the last function invoked by the user when he wants to quit
; get the stop time, calculate the total time in web-mode, and
; write the usage of the functions to the file web-mode.jou
(setq ctr (web-binary-search-of-names web-interactive-functions
(length web-interactive-functions)
function-name
(length function-name)))
(aset web-interactive-function-usage ctr
(1+ (aref web-interactive-function-usage ctr)))
(save-excursion
(set-buffer "web-mode.jou")
(setq stop-time (current-time-string))
(setq start-time-in-seconds (+
(* 3600 (string-to-int (substring start-time 11 13)))
(* 60 (string-to-int (substring start-time 14 16)))
(string-to-int (substring start-time 17 19))))
(setq stop-time-in-seconds (+
(* 3600 (string-to-int (substring stop-time 11 13)))
(* 60 (string-to-int (substring stop-time 14 16)))
(string-to-int (substring stop-time 17 19))))
(if (not (natnump (- stop-time-in-seconds start-time-in-seconds)))
; then add the equivalent of a day to the stop time
(setq stop-time-in-seconds (+ stop-time-in-seconds 86400))
) ; end if
(setq time-in-web-mode
(- stop-time-in-seconds start-time-in-seconds))
(if (< (/ time-in-web-mode 3600) 10)
; then
(setq time-in-web-mode-as-string (concat "0"
(int-to-string (/ time-in-web-mode 3600)) ":"))
; else
(setq time-in-web-mode-as-string (concat
(int-to-string (/ time-in-web-mode 3600)) ":"))
) ; end if
(if (< (% (/ time-in-web-mode 60) 60) 10)
; then
(setq time-in-web-mode-as-string
(concat time-in-web-mode-as-string "0"
(int-to-string (% (/ time-in-web-mode 60) 60)) ":"))
; else
(setq time-in-web-mode-as-string
(concat time-in-web-mode-as-string
(int-to-string (% (/ time-in-web-mode 60) 60)) ":"))
) ; end if
(if (< (% (% time-in-web-mode 3600) 60) 10)
; then
(setq time-in-web-mode-as-string
(concat time-in-web-mode-as-string "0"
(int-to-string (% (% time-in-web-mode 3600) 60))))
; else
(setq time-in-web-mode-as-string
(concat time-in-web-mode-as-string
(int-to-string (% (% time-in-web-mode 3600) 60))))
) ; end if
(insert "FINISH TIME : " stop-time "\n"
"TOTAL TIME IN web-mode : " time-in-web-mode-as-string "\n"
(make-string 79 ?\055)
"\nINTERACTIVE FUNCTION USAGE\n")
(while (< ctr (length web-interactive-functions))
(if (not (zerop (aref web-interactive-function-usage ctr)))
(insert (make-string (- 4 (length (int-to-string
(aref web-interactive-function-usage ctr)))) ? )
(int-to-string (aref web-interactive-function-usage ctr))
" " (nth ctr web-interactive-functions) "\n")
) ; end if
(setq ctr (1+ ctr))
) ; end while
(write-region (point-min) (point-max) "web-mode.jou" t)
) ; end excursion
) ; end case
) ; end cond
(setq ctr (web-binary-search-of-names web-interactive-functions
(length web-interactive-functions)
function-name
(length function-name)))
(if (>= ctr 0)
; then the function-name was interactive
(aset web-interactive-function-usage ctr
(1+ (aref web-interactive-function-usage ctr)))
; else the function was not found in the web-interactive-functions list
(error "Function %s wasn't found" function-name)
) ; end if
) ; end let
)
(defun web-mode ()
"This is the definition of the mode for manipulating Web documents. When
invoked the function checks to see if the file that is being edited is new. If
it is, limbo material is inserted. If the file is not new, the program checks
for any undefined module names. If any modules are found to be undefined,
stubs are appended.
ARGUMENTS : None
GLOBAL Variables : web-change-buffer-name, web-defined-in-used-in-location,
web-location-of-module, web-module-names,
web-number-of-lines-in-window, web-number-of-module-names,
web-selected-index-entry-occurrences, web-buffer-name,
web-default-directory, web-files, web-mode-map, and
web-module-changed-then-goto-change
LOCAL Variables : None
RETURNS : Nothing
USES : web-any-modules-undefined-initially,
web-collect-list-of-changed-module-numbers, web-collect-module-names,
web-initialize-location-of-module-vector,
web-initialize-module-names-list, web-insert-limbo-material,
and web-journal"
(interactive)
(kill-all-local-variables)
(use-local-map web-mode-map)
(setq major-mode 'Web-mode
mode-name "Web")
(auto-fill-mode 1)
(setq web-change-buffer-name
(concat (substring (buffer-name (current-buffer))
0 (string-match "\\." (buffer-name (current-buffer)))) ".ch")
web-defined-in-used-in-location -1
fill-column 70
web-location-of-module nil
web-module-names nil
web-number-of-lines-in-window (- (screen-height) 2)
web-number-of-module-names 0
web-selected-index-entry-occurrences nil
web-buffer-name (buffer-name (current-buffer))
web-default-directory default-directory
web-files nil
web-module-changed-then-goto-change nil
) ; end setq
(web-journal "web-mode")
(if (= (length (buffer-substring (point-min) (point-max))) 0)
; then
(web-insert-limbo-material)
; else initialize the web-module-names list and
; check to see if any modules are undefined
(save-excursion
(goto-char (point-min))
(while (search-forward "\f" nil t)
(replace-match "\n" t t)
) ; end while
) ; end excursion
(web-initialize-location-of-module-vector)
(if (and (file-readable-p
(expand-file-name (concat (substring web-buffer-name 0
(string-match "\\." web-buffer-name)) ".mods")))
(file-newer-than-file-p
(expand-file-name (concat (substring web-buffer-name 0
(string-match "\\." web-buffer-name)) ".mods"))
(expand-file-name web-buffer-name))
) ; end condition
; then
(progn
(message "Initializing the Module Names List...")
(web-initialize-module-names-list)
(message "Initializing the Module Names List...done")
(sit-for 1)
) ; end then
; else
(web-collect-module-names)
) ; end if
(message "Checking to see if any modules are undefined...")
(web-any-modules-undefined-initially)
(message "Checking to see if any modules are undefined...done")
(find-file-noselect web-change-buffer-name)
(save-excursion
(set-buffer web-change-buffer-name)
(web-collect-list-of-changed-module-numbers)
(setq major-mode 'Web-mode
mode-name "Web")
(use-local-map web-mode-map)
) ; end excursion
) ; end if
)
(define-key (current-global-map) "\C-x\C-c" 'web-mode-save-buffers-kill-emacs)
(defun web-mode-save-buffers-kill-emacs ()
"This function is used to replace Emacs' save-buffers-kill-emacs so that
the journal file can be written.
ARGUMENTS : None
GLOBAL Variables : None
LOCAL Variables : None
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-journal, and
web-write-module-names-to-a-file"
(interactive)
(web-check-if-buffer-is-one-of-the-web-files)
(web-journal "web-mode-save-buffers-kill-emacs")
(web-write-module-names-to-a-file)
(save-buffers-kill-emacs)
)
(defun web-newline ()
"This function redefines the newline character so that the following line
is indented like the previous one.
ARGUMENTS : None
GLOBAL Variables : None
LOCAL Variable : ctr
RETURNS : Nothing
USES : web-journal"
(interactive)
(web-journal "web-newline")
(let ((ctr 0))
(save-excursion
(beginning-of-line)
(while (looking-at " ")
(setq ctr (1+ ctr))
(forward-char 1)
) ; end while
) ; end excursion
(newline)
(insert (make-string ctr ?\040))
) ; end let
)
(defun web-next-change ()
"Advances point to the beginning of the next change.
ARGUMENTS : None
GLOBAL Variable : web-change-buffer-name
LOCAL Variable : start-position
RETURNS : Nothing
USES : goto-change and web-journal"
(interactive)
(web-journal "web-next-change")
(if (not (string= web-change-buffer-name (buffer-name (current-buffer))))
; then
(error "Not in the CHange buffer.")
; else
(let ((start-position (point)))
(if (looking-at "^@x") (forward-char 2))
(if (re-search-forward "^@x" nil t)
; then
(progn
(re-search-forward "^@y" nil t)
(goto-char (match-beginning 0))
(recenter 0)
) ; end then
; else there is no next change
(goto-char start-position)
(error "No next CHange.")
) ; end if
) ; end let
) ; end if
)
(defun web-next-define ()
"This function is used to traverse the list of Defined In occurrences of the
most recently selected module name in the forward direction. A module name is
selected by issuing the command \\[web-view-module-names-list] and positioning
the cursor on the line that contains the module name of interest.
ARGUMENTS : None
GLOBAL Variables : web-defined-in-occurrence, web-defined-in-used-in-location,
and web-module-name-defined-in-used-in
LOCAL Variable : buffer-to-be-returned-to and current-module
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-goto-module,
web-next-or-previous-define-or-use, web-journal, and web-what-module"
(interactive)
(web-journal "web-next-define")
(web-check-if-buffer-is-one-of-the-web-files)
(cond
((string= (buffer-name (current-buffer))
"*Module Name (Defined In) (Used In)*")
; then the user needs to select an entry
(let ((buffer-to-be-returned-to
(web-next-or-previous-define-or-use "next" "defined-in")))
(if (>= web-defined-in-occurrence
(length (car (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
; then there is no next define
(progn
(switch-to-buffer buffer-to-be-returned-to)
(error "No next define of %s" (car (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
) ; end then
; else
(web-goto-module (nth web-defined-in-occurrence (car (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
(message "Define %d of %d of %s" (1+ web-defined-in-occurrence)
(length (car (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in))))
(car (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
) ; end if
) ; end let
) ; end case
(t ; we are in a valid Web buffer
(if (= web-defined-in-used-in-location -1)
(error (concat "No selected module. "
"Execute M-x web-view-module-names-list to select."))
; else
(let ((current-module (web-what-module)))
(setq web-defined-in-occurrence 0)
(while (and (nth web-defined-in-occurrence (car (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in))))
(<= (nth web-defined-in-occurrence (car (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in))))
current-module)
) ; end and
(setq web-defined-in-occurrence (1+ web-defined-in-occurrence))
) ; end while
(if (>= web-defined-in-occurrence
(length (car (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
; then there is no next define
(error "No next define of %s" (car (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
; else
(web-goto-module (nth web-defined-in-occurrence (car (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
(message "Define %d of %d of %s" (1+ web-defined-in-occurrence)
(length (car (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in))))
(car (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
) ; end if
) ; end let
) ; end if
) ; end case
) ; end cond
)
(defun web-next-index ()
"This function is used to traverse the list of occurrences of the most
recently selected index entry in the forward direction. An index entry is
selected by issuing the command \\[web-view-index] and positioning the cursor
on the line that contains the index entry of interest.
ARGUMENTS : None
GLOBAL Variables : web-location-in-selected-index-entry-occurrences,
web-selected-index-entry-occurrences,
web-index-buffer-name, and web-index-entry
LOCAL Variables : buffer-to-be-returned-to and current-module
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-goto-module,
web-journal, web-next-or-previous-index, and web-what-module"
(interactive)
(web-journal "web-next-index")
(web-check-if-buffer-is-one-of-the-web-files)
(cond
((string-equal web-index-buffer-name (buffer-name (current-buffer)))
; then we are in the index
(let ((buffer-to-be-returned-to (web-next-or-previous-index "next")))
(if (>= web-location-in-selected-index-entry-occurrences
(length web-selected-index-entry-occurrences))
; then there is no next use
(progn
(switch-to-buffer buffer-to-be-returned-to)
(error "No next index reference for %s" web-index-entry)
) ; end then
; else
(web-goto-module (nth
web-location-in-selected-index-entry-occurrences
web-selected-index-entry-occurrences))
(message "Index Reference %d of %d for entry %s"
(1+ web-location-in-selected-index-entry-occurrences)
(length web-selected-index-entry-occurrences)
web-index-entry)
) ; end if
) ; end let
) ; end case
(t ; else we are in a Web buffer
(if (null web-selected-index-entry-occurrences)
; then
(error
"Issue the command M-x web-view-index to select an index entry.")
; else
(let ((current-module (web-what-module)))
(setq web-location-in-selected-index-entry-occurrences 0)
(while (and (nth web-location-in-selected-index-entry-occurrences
web-selected-index-entry-occurrences)
(<= (nth web-location-in-selected-index-entry-occurrences
web-selected-index-entry-occurrences)
current-module)
) ; end and
(setq web-location-in-selected-index-entry-occurrences
(1+ web-location-in-selected-index-entry-occurrences))
) ; end while
(if (>= web-location-in-selected-index-entry-occurrences
(length web-selected-index-entry-occurrences))
; then
(error "No next index reference for %s" web-index-entry)
; else
(web-goto-module (nth
web-location-in-selected-index-entry-occurrences
web-selected-index-entry-occurrences))
(message "Index Reference %d of %d for entry %s"
(1+ web-location-in-selected-index-entry-occurrences)
(length web-selected-index-entry-occurrences)
web-index-entry)
) ; end if
) ; end let
) ; end if
) ; end case
) ; end cond
)
(defun web-next-module ()
"This function moves point to the beginning of the next module. If point is
currently in the last module of the Web, an appropriate message is sent to the
minibuffer; otherwise, point is positioned at the first line of the next
module.
ARGUMENTS : None
GLOBAL Variables : None
LOCAL Variable : current-module
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files,
web-count-modules, web-goto-module, web-journal, and web-what-module"
(interactive)
(web-journal "web-next-module")
(web-check-if-buffer-is-one-of-the-web-files)
(let ((current-module (web-what-module)))
(if (>= current-module (web-count-modules))
; then
(error "No next module")
; else
(web-goto-module (1+ current-module))
) ; end if
) ; end let
)
(defun web-next-or-previous-define-or-use (direction list)
"This is an internal support function that is called by both \\[web-next-use]
and \\[web-next-define]. It determines the module name that the cursor is
currently located at. After the name has been isolated, it is looked up in the
list of module names so that the traversal of the module name's Defined In and
Used In lists can be done.
ARGUMENTS : direction and list (both required)
GLOBAL Variables : web-defined-in-occurrence, web-defined-in-used-in-location,
web-module-names, web-number-of-module-names,
web-selected-module-name, and web-used-in-occurrence
LOCAL Variables : beginning-of-module-name, ctr, current-module,
current-position, end-of-module-name, ptr, and
web-buffer-list
RETURNS : buffer to be returned to on error
USES : web-binary-search-of-names, web-eliminate-white-space,
and web-what-module"
(let ((beginning-of-module-name 0)
(ctr 1)
(current-module 0)
(current-position (point))
(end-of-module-name 0)
(ptr 0)
web-buffer-list
)
(if (eobp)
; then
(error "No module name can be selected from point's current position.")
) ; end if
(save-excursion
(setq current-position (point))
(beginning-of-line)
(while (char-equal
(string-to-char (buffer-substring (point) (1+ (point)))) ? )
(forward-line -1)
) ; end while
(setq beginning-of-module-name (point))
(goto-char current-position)
(forward-line 1)
(while (and (not (eobp)) (char-equal
(string-to-char (buffer-substring (point) (1+ (point)))) ? ))
(forward-line 1)
) ; end while
(backward-char 1)
(setq end-of-module-name (point))
(goto-char end-of-module-name)
(re-search-backward "(" beginning-of-module-name t 2)
(setq web-selected-module-name (web-eliminate-white-space
(buffer-substring beginning-of-module-name (1- (point)))))
; Set the global variable search-last-string so that the user can
; do a C-s C-s to go immediately to the selected module name.
(setq search-last-string web-selected-module-name)
(setq ptr (web-binary-search-of-names web-module-names
web-number-of-module-names
web-selected-module-name (length web-selected-module-name)))
(setq web-defined-in-used-in-location
(string-to-int (substring (nth ptr web-module-names)
(+ (string-match " " (nth ptr web-module-names)) 2))))
(setq web-buffer-list (mapcar (function buffer-name) (buffer-list)))
(setq ctr 1)
(while (char-equal (string-to-char
(substring (nth ctr web-buffer-list) 0 1)) ? )
(setq ctr (1+ ctr))
) ; end while
(save-excursion
(set-buffer (nth ctr web-buffer-list))
(setq current-module (web-what-module))
) ; end excursion
(cond
((and (string= direction "next")
(string= list "defined-in"))
(setq web-defined-in-occurrence 0)
(while (and (nth web-defined-in-occurrence (car (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in))))
(<= (nth web-defined-in-occurrence (car (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in))))
current-module)
) ; end and
(setq web-defined-in-occurrence (1+ web-defined-in-occurrence))
) ; end while
) ; end case
((and (string= direction "next")
(string= list "used-in"))
(setq web-used-in-occurrence 0)
(while (and (nth web-used-in-occurrence (car (cdr (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
(<= (nth web-used-in-occurrence (car (cdr (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
current-module)
) ; end and
(setq web-used-in-occurrence (1+ web-used-in-occurrence))
) ; end while
) ; end case
((and (string= direction "previous")
(string= list "defined-in"))
(setq web-defined-in-occurrence (1- (length
(car (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in))))))
(while (and (>= web-defined-in-occurrence 0)
(>= (nth web-defined-in-occurrence (car (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in))))
current-module)
) ; end and
(setq web-defined-in-occurrence (1- web-defined-in-occurrence))
) ; end while
) ; end case
((and (string= direction "previous")
(string= list "used-in"))
(setq web-used-in-occurrence (1- (length (car (cdr (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))))
(while (and (>= web-used-in-occurrence 0)
(>= (nth web-used-in-occurrence (car (cdr (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
current-module)
) ; end and
(setq web-used-in-occurrence (1- web-used-in-occurrence))
) ; end while
) ; end case
(t
(error "This case should not be reached.")
) ; end case
) ; end cond
; return the name of the buffer to be returned to on error
(nth ctr web-buffer-list)
) ; end excursion
) ; end let
)
(defun web-next-or-previous-index (direction)
"This is an internal support function used by \\[web-next-index] and
\\[web-previous-index]. This is common code and is only invoked when the
user is viewing the index. This code determines the entry the user has
selected and builds a list of the referenced module numbers for the selected
index entry.
ARGUMENT : direction (required)
GLOBAL Variables : web-location-in-selected-index-entry-occurrences,
web-selected-index-entry-occurrences, and web-index-entry
LOCAL Variables : ctr, current-module, end-of-web-index-entry, and
web-buffer-list
RETURNS : the name of the buffer to return on an error
USES : web-what-module"
(let ((ctr 1)
(current-module 0)
(end-of-web-index-entry 0)
web-buffer-list
)
(if (eobp)
; then
(error "No index entry can be selected from this position.")
) ; end if
(save-excursion
(beginning-of-line)
(while (looking-at " ") (forward-line -1))
(setq web-index-entry (buffer-substring (point)
(save-excursion (re-search-forward ": ") (- (point) 2))))
; Set the global Emacs variable search-last-string to the index
; entry selected by the user so that the user can use C-s C-s to
; get to the entry much easier.
(setq search-last-string web-index-entry)
(save-excursion
(re-search-forward "\\.\n" nil t)
(setq end-of-web-index-entry (point))
) ; end excursion
(while (re-search-forward
"\\([0-9]+\\)\\*?\\(, \\|,\n\\|\\.\n\\)"
end-of-web-index-entry t)
(setq web-selected-index-entry-occurrences (append
web-selected-index-entry-occurrences
(list (string-to-int
(buffer-substring (match-beginning 1) (match-end 1))))))
) ; end while
) ; end excursion
(setq web-buffer-list (mapcar (function buffer-name) (buffer-list)))
(setq ctr 1)
(while (char-equal (string-to-char
(substring (nth ctr web-buffer-list) 0 1)) ? )
(setq ctr (1+ ctr))
) ; end while
(save-excursion
(set-buffer (nth ctr web-buffer-list))
(setq current-module (web-what-module))
) ; end excursion
(cond
((string= direction "next")
(setq web-location-in-selected-index-entry-occurrences 0)
(while (and (nth web-location-in-selected-index-entry-occurrences
web-selected-index-entry-occurrences)
(<= (nth web-location-in-selected-index-entry-occurrences
web-selected-index-entry-occurrences)
current-module)
) ; end and
(setq web-location-in-selected-index-entry-occurrences
(1+ web-location-in-selected-index-entry-occurrences))
) ; end while
) ; end case
((string= direction "previous")
(setq web-location-in-selected-index-entry-occurrences
(1- (length web-selected-index-entry-occurrences)))
(while (and (>= web-location-in-selected-index-entry-occurrences 0)
(>= (nth web-location-in-selected-index-entry-occurrences
web-selected-index-entry-occurrences)
current-module)
) ; end and
(setq web-location-in-selected-index-entry-occurrences
(1- web-location-in-selected-index-entry-occurrences))
) ; end while
) ; end case
(t
(error "This case should not be reached.")
) ; end case
) ; end cond
; return the name of the buffer to return to on an error
(nth ctr web-buffer-list)
) ; end let
)
(defun web-next-section ()
"This function moves point to the beginning of the next section. If point is
currently in the last section of the Web, an appropriate message is sent to the
minibuffer; otherwise, point is positioned at the first line of the next
section.
ARGUMENTS : None
GLOBAL Variables : None
LOCAL Variable : current-section
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files,
web-count-sections, web-goto-section, web-journal, and web-what-section"
(interactive)
(web-journal "web-next-section")
(web-check-if-buffer-is-one-of-the-web-files)
(let ((current-section (web-what-section)))
(if (>= current-section (web-count-sections))
; then
(error "No next section")
; else
(web-goto-section (1+ current-section))
) ; end if
) ; end let
)
(defun web-next-use ()
"This function is used to traverse the list of Used In occurrences of the
most recently selected module name in the forward direction. A module name is
selected by issuing the command \\[web-view-module-names-list] and positioning
the cursor on the line that contains the module name of interest.
ARGUMENTS : None
GLOBAL Variables : web-defined-in-used-in-location,
web-module-name-defined-in-used-in, and
web-used-in-occurrence
LOCAL Variables : buffer-to-be-returned-to and current-module
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-goto-module,
web-next-or-previous-define-or-use, web-journal, and web-what-module"
(interactive)
(web-journal "web-next-use")
(web-check-if-buffer-is-one-of-the-web-files)
(cond
((string= (buffer-name (current-buffer))
"*Module Name (Defined In) (Used In)*")
; then the user needs to select an entry
(let ((buffer-to-be-returned-to
(web-next-or-previous-define-or-use "next" "used-in")))
(if (>= web-used-in-occurrence
(length (car (cdr (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in))))))
; then there is no next use
(progn
(switch-to-buffer buffer-to-be-returned-to)
(error "No next use of %s"
(car (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
) ; end then
; else
(web-goto-module (nth web-used-in-occurrence (car (cdr (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in))))))
(message "Use %d of %d of %s" (1+ web-used-in-occurrence)
(length (car (cdr (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
(car (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
) ; end if
) ; end let
) ; end case
(t ; we are in a valid Web buffer
(if (= web-defined-in-used-in-location -1)
(error (concat "No selected module. "
"Execute M-x web-view-module-names-list to select."))
; else
(let ((current-module (web-what-module)))
(setq web-used-in-occurrence 0)
(while (and (nth web-used-in-occurrence (car (cdr (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
(<= (nth web-used-in-occurrence (car (cdr (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
current-module)
) ; end and
(setq web-used-in-occurrence (1+ web-used-in-occurrence))
) ; end while
(if (>= web-used-in-occurrence
(length (car (cdr (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in))))))
; then there is no next define
(error "No next use of %s"
(car (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
; else
(web-goto-module (nth web-used-in-occurrence (car (cdr (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in))))))
(message "Use %d of %d of %s" (1+ web-used-in-occurrence)
(length (car (cdr (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
(car (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
) ; end if
) ; end let
) ; end if
) ; end case
) ; end cond
)
(defun web-options-for-module-name-insertion ()
"This function is invoked by \\[web-insert-module-name] if the @< just
encountered represents a valid module beginning. This function then presents
the user with various options for choosing or creating a module name.
ARGUMENTS : None
GLOBAL Variables : web-module-names, web-number-of-lines-in-window, and
web-number-of-module-names
LOCAL Variables : available-lines, char-after-at-greater, ctr, defined-in-list,
done, element-to-be-inserted, found, len, location, menu,
menu-choice, module-name, module-number, screen-bottom,
screen-top, search-letter, sub-menu, and used-in-list
RETURNS : Nothing
USES : web-append-a-stub-module, web-binary-search-of-names,
web-determine-module-name-ending, web-display-module-names,
web-eliminate-white-space, and web-what-module"
(let ((available-lines (- web-number-of-lines-in-window 11))
char-after-at-greater,
(ctr 0)
done
element-to-be-inserted
found
(len 0)
(location 0)
(menu (concat "Option Action\n------ " (make-string 43 ?-)
"\n A Abort\n"
" C Create a New Module Name\n"
" L List all Module Names Beginning with Letter\n"
" N Next Screen\n"
" P Previous Screen\n"
" S Select Existing Module Name\n"
(make-string 79 ?-) "\n"))
(menu-choice 0)
module-name
(module-number 0)
(screen-bottom 0)
(screen-top 0)
search-letter
used-in-list
)
(switch-to-buffer "*Module Names*")
(use-local-map web-mode-map)
(setq major-mode 'Web-mode
mode-name "Web")
(goto-char (point-min))
(kill-line (count-lines (point-min) (point-max)))
(insert-string menu)
(setq screen-top 1)
(if (>= web-number-of-module-names available-lines)
; then
(setq screen-bottom available-lines)
; else
(setq screen-bottom web-number-of-module-names)
) ; end if
(web-display-module-names screen-top screen-bottom)
(setq menu-choice (read-string
"(A)bort, (C)reate, (L)ist, (N)ext, (P)revious, or (S)elect: "))
(while (not (string-match (upcase (substring menu-choice 0 1)) "ACLNPS"))
(ding)
(setq menu-choice (read-string
"(A)bort, (C)reate, (L)ist, (N)ext, (P)revious, or (S)elect: "))
) ; end while
(setq done nil)
(while (not done)
(cond
((char-equal (string-to-char (upcase (substring menu-choice 0 1))) ?A)
; this is the Abort option
(switch-to-buffer (get-file-buffer (expand-file-name
(nth file-no web-files) web-default-directory)))
(delete-backward-char 2)
(setq done t)
) ; end case
((char-equal (string-to-char (upcase (substring menu-choice 0 1))) ?N)
; show the Next screen of module names
(setq screen-bottom (+ screen-bottom available-lines))
(if (> screen-bottom web-number-of-module-names)
; then
(setq screen-bottom web-number-of-module-names)
) ; end if
(setq screen-top (1+ (- screen-bottom available-lines)))
(if (< screen-top 0)
; then
(setq screen-top 1)
) ; end if
(web-display-module-names screen-top screen-bottom)
(setq done nil)
) ; end case
((char-equal (string-to-char (upcase (substring menu-choice 0 1))) ?P)
; show the Previous screen of module names
(setq screen-top (- screen-top available-lines))
(if (<= screen-top 0)
; then
(setq screen-top 1)
) ; end if
(setq screen-bottom (1- (+ screen-top available-lines)))
(if (>= screen-bottom web-number-of-module-names)
; then
(setq screen-bottom web-number-of-module-names)
) ; end if
(web-display-module-names screen-top screen-bottom)
(setq done nil)
) ; end case
((char-equal (string-to-char (upcase (substring menu-choice 0 1))) ?L)
; list all module names beginning with a particular letter
(setq search-letter (read-string "Letter: ")
found nil
ctr 1)
(while (and (<= ctr web-number-of-module-names)
(<= (string-to-char
(substring (nth (1- ctr) web-module-names) 0 1))
(string-to-char search-letter)))
(if (and (null found) (string-equal
(substring (nth (1- ctr) web-module-names) 0 1)
(substring search-letter 0 1)))
; then
(setq found t
screen-top ctr)
) ; end if
(setq ctr (1+ ctr))
) ; end while
(if (null found)
; then
(progn
(ding)
(message "No module names begin with %s"
(substring search-letter 0 1))
(sit-for 3)
) ; end then
; else
(setq screen-bottom (min (1- ctr)
(1- (+ screen-top available-lines))))
(web-display-module-names screen-top screen-bottom
(- ctr screen-top))
) ; end if
(setq done nil)
) ; end case
((char-equal (string-to-char (upcase (substring menu-choice 0 1))) ?S)
; choose module name
(if (zerop web-number-of-module-names)
; then this is an invalid choice
(progn
(ding)
(message
"Invalid since there are no module names to select from.")
(setq done nil)
) ; end then
; else select one of the existing names
(setq module-number (read-string
(format "Module Number [1..%d]: " web-number-of-module-names)))
(while (or (< (string-to-int module-number) 1)
(> (string-to-int module-number)
web-number-of-module-names))
(ding)
(setq module-number (read-string
(format "Module Number [1..%d]: " web-number-of-module-names)))
) ; end while
(setq module-name (substring
(nth (1- (string-to-int module-number)) web-module-names)
0 (string-match " "
(nth (1- (string-to-int module-number)) web-module-names))))
(switch-to-buffer (get-file-buffer (expand-file-name
(nth file-no web-files) web-default-directory)))
(insert-string module-name)
(insert-string (web-determine-module-name-ending))
(setq location (string-to-int (substring
(nth (1- (string-to-int module-number)) web-module-names)
(+ (string-match " " (nth (1- (string-to-int module-number))
web-module-names)) 2))))
(if (char-equal (preceding-char) ?=)
; then an existing module name has been defined again
(progn
(setq new-module-number (web-what-module))
(web-update-the-module-name-defined-in-used-in-list
new-module-number)
(setq defined-in-list (sort (append (car (cdr (nth
location web-module-name-defined-in-used-in)))
(list new-module-number)) '<))
(setcdr (nth location web-module-name-defined-in-used-in)
(append (list defined-in-list)
(list (car (cdr (cdr
(nth location web-module-name-defined-in-used-in)))))))
) ; end then
; else update the used in list in the module names
(if (null (car (car (cdr (cdr
(nth location web-module-name-defined-in-used-in))))))
; then
(setq used-in-list (list (web-what-module)))
; else
(setq used-in-list (sort (append (car (cdr (cdr
(nth location web-module-name-defined-in-used-in))))
(list (web-what-module))) '<))
) ; end if
(setcdr (nth location web-module-name-defined-in-used-in)
(append (list (car (cdr (nth location
web-module-name-defined-in-used-in))))
(list used-in-list)))
) ; end if
(if (char-equal (preceding-char) ?=) (insert-char ?\012 1))
(setq done t)
) ; end if
) ; end case
((char-equal (string-to-char (upcase (substring menu-choice 0 1))) ?C)
; Create a new module name
(setq module-name (read-string "New Module Name: "))
(switch-to-buffer (get-file-buffer (expand-file-name
(nth file-no web-files) web-default-directory)))
(setq module-name (web-eliminate-white-space module-name))
(insert-string module-name)
(insert-string (web-determine-module-name-ending))
(if (char-equal (preceding-char) ?=)
; then
(setq char-after-at-greater ?=)
; else
(setq char-after-at-greater ? )
) ; end if
(setq len (length module-name))
(if (and (> len 3) (string-equal "..."
(substring module-name (- len 3) len)))
; then
(setq len (- len 3))
) ; end if
(setq location (web-binary-search-of-names web-module-names
web-number-of-module-names module-name len))
(if (= location -1)
; then it is indeed a new module name
(progn
(setq web-module-names (sort
(append web-module-names (list (concat
module-name " " (int-to-string web-number-of-module-names))))
'string<))
(setq web-number-of-module-names (1+ web-number-of-module-names))
(setq new-module-number (web-what-module))
(if (char-equal ?= char-after-at-greater)
; then this new module was defined (i.e., @<...@>=)
(progn
(web-update-the-module-name-defined-in-used-in-list
new-module-number)
(setq web-module-name-defined-in-used-in (append
web-module-name-defined-in-used-in (list (list module-name
(list new-module-number) (list ())))))
) ; end then
; else this new module was used before defined (insert a stub)
(ding)
(message "Appending a module for %s" module-name)
(sit-for 2)
(setq module-number-of-stub
(web-append-a-stub-module module-name))
(setq web-module-name-defined-in-used-in (append
web-module-name-defined-in-used-in (list (list module-name
(list module-number-of-stub) (list new-module-number)))))
) ; end if
) ; end then
; else the user entered a supposedly new name that already exists
(setq location (string-to-int (substring
(nth location web-module-names)
(+ (string-match " " (nth location web-module-names)) 2))))
(if (char-equal (preceding-char) ?=)
; then an existing module name has been defined again
(progn
(setq new-module-number (web-what-module))
(web-update-the-module-name-defined-in-used-in-list
new-module-number)
(setq defined-in-list (sort (append (car (cdr (nth
location web-module-name-defined-in-used-in)))
(list new-module-number)) '<))
(setcdr (nth location web-module-name-defined-in-used-in)
(append (list defined-in-list)
(list (car (cdr (cdr
(nth location web-module-name-defined-in-used-in)))))))
) ; end then
; else update the used in list in the module names
(if (null (car (car (cdr (cdr
(nth location web-module-name-defined-in-used-in))))))
; then
(setq used-in-list (list (web-what-module)))
; else
(setq used-in-list (sort (append (car (cdr (cdr
(nth location web-module-name-defined-in-used-in))))
(list (web-what-module))) '<))
) ; end if
(setcdr (nth location web-module-name-defined-in-used-in)
(append (list (car (cdr (nth location
web-module-name-defined-in-used-in))))
(list used-in-list)))
) ; end if
(if (char-equal (preceding-char) ?=) (insert-char ?\012 1))
) ; end if
(setq done t)
) ; end case
) ; end cond
(if (not done)
; then
(progn
(setq menu-choice (read-string
"(A)bort, (C)reate, (L)ist, (N)ext, (P)revious, or (S)elect: "))
(while (not
(string-match (upcase (substring menu-choice 0 1)) "ACLNPS"))
(ding)
(setq menu-choice (read-string
"(A)bort, (C)reate, (L)ist, (N)ext, (P)revious, or (S)elect: "))
) ; end while
) ; end then
) ; end if
) ; end while
) ; end let
)
(defun web-previous-change ()
"Advances point to the beginning of the previous change.
ARGUMENTS : None
GLOBAL Variable : web-change-buffer-name
LOCAL Variable : start-position
RETURNS : Nothing
USES : web-journal"
(interactive)
(web-journal "web-previous-change")
(if (not (string= web-change-buffer-name (buffer-name (current-buffer))))
; then
(error "Not in the CHange buffer.")
; else
(let ((start-position (point)))
(end-of-line)
(if (not (re-search-backward "^@x" nil t 2))
; then
(progn
(goto-char start-position)
(error "No previous CHange.")
) ; end then
; else
(re-search-forward "^@y" nil t)
(goto-char (match-beginning 0))
(recenter 0)
) ; end if
) ; end let
) ; end if
)
(defun web-previous-define ()
"This function can only be invoked in the buffer containing the Web document.
It is used to traverse the list of Defined In occurrences of the most recently
selected module name in the backward direction. A module name is selected by
issuing the command \\[web-view-module-names-list] and positioning the cursor
on the line that contains the module name of interest.
ARGUMENTS : None
GLOBAL Variables : web-defined-in-occurrence, web-defined-in-used-in-location,
and web-module-name-defined-in-used-in
LOCAL Variable : buffer-to-be-returned-to and current-module
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-goto-module,
web-next-or-previous-define-or-use, web-journal, and web-what-module"
(interactive)
(web-journal "web-previous-define")
(web-check-if-buffer-is-one-of-the-web-files)
(cond
((string= (buffer-name (current-buffer))
"*Module Name (Defined In) (Used In)*")
; then the user needs to select an entry
(let ((buffer-to-be-returned-to
(web-next-or-previous-define-or-use "previous" "defined-in")))
(if (< web-defined-in-occurrence 0)
; then there is no previous define
(progn
(switch-to-buffer buffer-to-be-returned-to)
(error "No previous define of %s" (car (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
) ; end then
; else
(web-goto-module (nth web-defined-in-occurrence (car (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
(message "Define %d of %d of %s" (1+ web-defined-in-occurrence)
(length (car (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in))))
(car (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
) ; end if
) ; end let
) ; end case
(t ; we are in a valid Web buffer
(if (= web-defined-in-used-in-location -1)
(error (concat "No selected module. "
"Execute M-x web-view-module-names-list to select."))
; else
(let ((current-module (web-what-module)))
(setq web-defined-in-occurrence (1- (length
(car (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in))))))
(while (and (>= web-defined-in-occurrence 0)
(>= (nth web-defined-in-occurrence (car (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in))))
current-module)
) ; end and
(setq web-defined-in-occurrence (1- web-defined-in-occurrence))
) ; end while
(if (< web-defined-in-occurrence 0)
; then there is no next define
(error "No previous define of %s" (car (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
; else
(web-goto-module (nth web-defined-in-occurrence (car (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
(message "Define %d of %d of %s" (1+ web-defined-in-occurrence)
(length (car (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in))))
(car (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
) ; end if
) ; end let
) ; end if
) ; end case
) ; end cond
)
(defun web-previous-index ()
"This function is used to traverse the list of occurrences of the most
recently selected index entry in the backward direction. An index entry is
selected by issuing the command \\[web-view-index] and positioning the cursor
on the line that contains the index entry of interest.
ARGUMENTS : None
GLOBAL Variables : web-location-in-selected-index-entry-occurrences,
web-selected-index-entry-occurrences,
web-index-buffer-name, and web-index-entry
LOCAL Variables : buffer-to-be-returned-to and current-module
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-goto-module,
web-journal, web-next-or-previous-index, and web-what-module"
(interactive)
(web-journal "web-previous-index")
(web-check-if-buffer-is-one-of-the-web-files)
(cond
((string-equal web-index-buffer-name (buffer-name (current-buffer)))
; then we are in the index
(let ((buffer-to-be-returned-to (web-next-or-previous-index "previous")))
(if (< web-location-in-selected-index-entry-occurrences 0)
; then there is no previous use
(progn
(switch-to-buffer buffer-to-be-returned-to)
(error "No previous index reference for %s" web-index-entry)
) ; end then
; else
(web-goto-module (nth
web-location-in-selected-index-entry-occurrences
web-selected-index-entry-occurrences))
(message "Index Reference %d of %d for entry %s"
(1+ web-location-in-selected-index-entry-occurrences)
(length web-selected-index-entry-occurrences)
web-index-entry)
) ; end if
) ; end let
) ; end case
(t ; else we are in a Web buffer
(if (null web-selected-index-entry-occurrences)
; then
(error
"Issue the command M-x web-view-index to select an index entry.")
; else
(let ((current-module (web-what-module)))
(setq web-location-in-selected-index-entry-occurrences
(1- (length web-selected-index-entry-occurrences)))
(while (and (>= web-location-in-selected-index-entry-occurrences 0)
(>= (nth web-location-in-selected-index-entry-occurrences
web-selected-index-entry-occurrences)
current-module)
) ; end and
(setq web-location-in-selected-index-entry-occurrences
(1- web-location-in-selected-index-entry-occurrences))
) ; end while
(if (< web-location-in-selected-index-entry-occurrences 0)
; then
(error "No previous index reference for %s" web-index-entry)
; else
(web-goto-module (nth
web-location-in-selected-index-entry-occurrences
web-selected-index-entry-occurrences))
(message "Index Reference %d of %d for entry %s"
(1+ web-location-in-selected-index-entry-occurrences)
(length web-selected-index-entry-occurrences)
web-index-entry)
) ; end if
) ; end let
) ; end if
) ; end case
) ; end cond
)
(defun web-previous-module ()
"This function moves point to the beginning of the previous module. If point
is currently in the limbo section of the Web or in module 1, an appropriate
message is sent to the minibuffer; otherwise, point is positioned at the first
line of the previous module.
ARGUMENTS : None
GLOBAL Variables : None
LOCAL Variable : current-module
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files,
web-goto-module, web-journal, and web-what-module"
(interactive)
(web-journal "web-previous-module")
(web-check-if-buffer-is-one-of-the-web-files)
(let ((current-module (web-what-module)))
(if (<= current-module 1)
; then
(error "No previous module")
; else
(web-goto-module (1- current-module))
) ; end if
) ; end let
)
(defun web-previous-section ()
"This function moves point to the beginning of the previous section. If
point is currently in the limbo section of the Web or in the first section, an
appropriate message is sent to the minibuffer; otherwise, point is positioned
at the first line of the previous section.
ARGUMENTS : None
GLOBAL Variables : None
LOCAL Variable : current-section
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files,
web-goto-section, web-journal, and web-what-section"
(interactive)
(web-journal "web-previous-section")
(web-check-if-buffer-is-one-of-the-web-files)
(let ((current-section (web-what-section)))
(if (<= current-section 1)
; then
(error "No previous section")
; else
(web-goto-section (1- current-section))
) ; end if
) ; end let
)
(defun web-previous-use ()
"This function can only be invoked in the buffer containing the Web document.
It is used to traverse the list of Used In occurrences of the most recently
selected module name in the backward direction. A module name is selected by
issuing the command \\[web-view-module-names-list] and positioning the cursor
on the line that contains the module name of interest.
ARGUMENTS : None
GLOBAL Variables : web-defined-in-used-in-location,
web-module-name-defined-in-used-in, and
web-used-in-occurrence
LOCAL Variables : buffer-to-be-returned-to and current-module
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-goto-module,
web-next-or-previous-define-or-use, web-journal, and web-what-module"
(interactive)
(web-journal "web-previous-use")
(web-check-if-buffer-is-one-of-the-web-files)
(cond
((string= (buffer-name (current-buffer))
"*Module Name (Defined In) (Used In)*")
; then the user needs to select an entry
(let ((buffer-to-be-returned-to
(web-next-or-previous-define-or-use "previous" "used-in")))
(if (< web-used-in-occurrence 0)
; then there is no previous use
(progn
(switch-to-buffer buffer-to-be-returned-to)
(error "No previous use of %s"
(car (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
) ; end then
; else
(web-goto-module (nth web-used-in-occurrence (car (cdr (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in))))))
(message "Use %d of %d of %s" (1+ web-used-in-occurrence)
(length (car (cdr (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
(car (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
) ; end if
) ; end let
) ; end case
(t ; we are in a valid Web buffer
(if (= web-defined-in-used-in-location -1)
(error (concat "No selected module. "
"Execute M-x web-view-module-names-list to select."))
; else
(let ((current-module (web-what-module)))
(setq web-used-in-occurrence (1- (length (car (cdr (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))))
(while (and (>= web-used-in-occurrence 0)
(>= (nth web-used-in-occurrence (car (cdr (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
current-module)
) ; end and
(setq web-used-in-occurrence (1- web-used-in-occurrence))
) ; end while
(if (< web-used-in-occurrence 0)
; then there is no next define
(error "No previous use of %s"
(car (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
; else
(web-goto-module (nth web-used-in-occurrence (car (cdr (cdr (nth
web-defined-in-used-in-location
web-module-name-defined-in-used-in))))))
(message "Use %d of %d of %s" (1+ web-used-in-occurrence)
(length (car (cdr (cdr (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))))
(car (nth web-defined-in-used-in-location
web-module-name-defined-in-used-in)))
) ; end if
) ; end let
) ; end if
) ; end case
) ; end cond
)
(defun web-reformat-the-index ()
"This is an internal support function used to reformat the raw index produced
by Weave. Control sequences must be removed and some reformatting is necessary
to clearly distinguish index entries (e.g., if an index entry occupies multiple
lines, the second and succeeding lines are indented two spaces).
ARGUMENTS : None
GLOBAL Variables : web-default-directory, web-index-buffer-name, and
web-mode-map
LOCAL Variables : ctr and line-to-be-inserted
RETURNS : Nothing
USES : web-eliminate-control-sequences and web-eliminate-white-space"
(let ((ctr 0)
line-to-be-inserted
)
(message "Reformatting the index...")
(switch-to-buffer web-index-buffer-name)
(use-local-map web-mode-map)
(goto-char (point-min))
(kill-line (count-lines (point-min) (point-max)))
(insert-file (expand-file-name "INDEX.tex" web-default-directory))
(save-excursion
(re-search-forward "\\\\W?inx" nil t)
(setq ctr (count-lines (point-min) (point)))
(goto-char (point-min))
(kill-line ctr)
) ; end excursion
(save-excursion
(goto-char (point-min))
(re-search-forward "\\\\W?fin" nil t)
(beginning-of-line)
(kill-line (count-lines (point) (point-max)))
) ; end excursion
(goto-char (point-min))
; indent index entries that occupy multiple lines
; index entries look like \:entry, occurrence-1, occurrence-2, ...,
; occurrence-n.
;
; WEAVE sometimes puts a %\n at the end of lines in the index. See
; module 67 in the source for CWEAVE or module 122 in the source for
; the Pascal WEAVE. Temporarily, make one long line out of these.
(save-excursion
(goto-char (point-min))
(while (re-search-forward "%\n" nil t)
(delete-char -2)
) ; end while
) ; end excursion
; Eliminate \: and the , followoing the index entry.
(web-eliminate-control-sequences "\\\\:\\(.*\\)}," "}:")
(web-eliminate-control-sequences "\\\\:\\\\|\\(.\\)," ":")
; FWEAVE sets built-in functions in the index as \:\@{function},
; Two lines above changes this to \@{function}:
; Now get rid of the \@{ and }
(web-eliminate-control-sequences "\\\\@{\\(.*\\)}:" ":")
; Now entries to be set in roman type look like {...}: ... Now eliminate
; the braces.
(web-eliminate-control-sequences "^{\\(.*\\)}:" ":")
; Eliminate \\{ and } from \\{...} (used for italicizing index entries
; of length greater than one
(web-eliminate-control-sequences "\\\\\\\\{\\(.*\\)}")
; Eliminate \|{ and } from \|{...} (used for italicizing index entries
; of length one
(web-eliminate-control-sequences "\\\\|{\\(.*\\)}")
; Eliminate \&{ and } from \&{...} (used for boldfacing index entries
(web-eliminate-control-sequences "\\\\&{\\(.*\\)}")
; Eliminate \9{, }, and {...} from \9{...}{...} (used for placing entry
; in a special way. See p. 204 #11 in WEB User Manual.
(web-eliminate-control-sequences "\\\\9{\\(.*\\)}{.*}")
; eliminate \.{ and } from \.{...} (used for placing index entries in a
; typewriter font
(web-eliminate-control-sequences "\\\\\\.{\\(.*\\)}")
; Eliminate \[ and ] from \[...] which is used to underline an index
; occurrence entry. The only characters that can be inside the brackets
; are digits and \* (the latter meaning that the module was changed).
(web-eliminate-control-sequences "\\\\\\[\\([0-9*\\]*\\)\\]")
(web-eliminate-control-sequences
"\\\\\\(\\\\\\|'\\|`\\|{\\|}\\|~\\| \\|_\\|&\\|#\\|\\$\\|%\\|\\^\\|\\*\\)"
)
; FWEAVE places a control sequence \Windexspace before every group of
; index entries beginning with a particular letter. Eliminate these lines.
(save-excursion
(goto-char (point-min))
(while (re-search-forward "\\\\Windexspace" nil t)
(beginning-of-line)
(kill-line 1)
) ; end while
) ; end excursion
(save-excursion (goto-char (point-min)) (replace-regexp "{\\\\AT}" "@"))
; Some index entries occupy multiple lines. Indent the second and
; succeeding lines.
(save-excursion
(while (re-search-forward ".+: \\(.+,\n\\)*.+\\.\n" nil t)
(if (/= (count-lines (point-min) (match-beginning 0))
(count-lines (point-min) (match-end 0)))
; then
(progn
(setq line-to-be-inserted (web-eliminate-white-space
(buffer-substring
(match-beginning 0) (match-end 0))))
(delete-char (- 0 (length (buffer-substring (match-beginning 0)
(match-end 0)))))
(while (> (length line-to-be-inserted) 79)
(setq ctr 79)
(while (not (char-equal ?
(string-to-char
(substring line-to-be-inserted (1- ctr) ctr))))
(setq ctr (1- ctr))
) ; end while
(insert-string (concat
(substring line-to-be-inserted 0 (1- ctr)) "\n"))
(setq line-to-be-inserted (concat " "
(substring line-to-be-inserted ctr)))
) ; end while
(insert-string (concat line-to-be-inserted "\n"))
) ; end then
) ; end if
) ; end while
) ; end excursion
) ; end let
(message "Reformatting the index...done")
)
(defun web-rename-module ()
"This function allows a user to rename a module. The user positions point
within the module that is to be changed. The user can then change all, one,
or some occurrences of this module name.
ARGUMENTS : None
GLOBAL Variables : web-module-name-defined-in-used-in, web-module-names, and
web-module-name
LOCAL Variables : case, ctr, current-position, defined, data, done, len,
len-old-module-name, module-name, module-name-begins-at,
module-name-ends-at, module-number-of-replacement,
modules-where-name-is-to-be-replaced, new-define,
new-module-name, new-use, next-module-begins, old-define,
old-module-name, old-use,
position-in-web-module-name-defined-in-used-in-list,
position-in-module-names, replace-module-name, and
temp-list
RETURNS : Nothing
USES : web-append-a-stub-module, web-binary-search-of-names,
web-check-if-buffer-is-one-of-the-web-files, web-eliminate-white-space,
web-goto-module, web-view-module-names-list, web-journal and
web-what-module"
(interactive)
(web-journal "web-rename-module")
(web-check-if-buffer-is-one-of-the-web-files)
; isolate the module name that point is in
(let (case
(ctr 0)
(current-position (point))
defined
done
(len 0)
(len-old-module-name 0)
module-name
(module-name-begins-at 0)
(module-name-ends-at 0)
(module-number-of-replacement 0)
modules-where-name-is-to-be-replaced
new-define
new-module-name
new-use
(next-module-begins 0)
old-define
old-module-name
old-use
(position-in-web-module-name-defined-in-used-in-list 0)
(position-in-module-names 0)
replace-module-name
temp-list
)
(save-excursion
(cond
((looking-at "<")
(forward-char 1)
) ; end case
((looking-at "@<")
(forward-char 2)
) ; end case
) ; end cond
; find the beginning of the module name, if possible
(while (not done)
(if (not (re-search-backward "\\(@@\\)*\\(@<\\)" nil t))
; then
(progn
(goto-char current-position)
(setq done nil)
(error "Point not positioned within a module name.")
) ; end then
; else
(goto-char (match-beginning 0))
(if (and (> (point) 1)
(char-equal (preceding-char) ?\@))
; then point is not positioned at the beginning of a module name
(setq done nil)
; else point is positioned at a valid module name beginning
(goto-char (match-beginning 2))
(setq done t)
) ; end if
) ; end if
) ; end while
(setq module-name-begins-at (point)
done nil)
; find the ending of the module name, if possible
(while (not done)
(if (not (re-search-forward "\\(@@\\)*\\(@>\\)" nil t))
; then
(progn
(goto-char current-position)
(setq done nil)
(error "Point not positioned within a module name.")
) ; end then
; else
(goto-char (match-beginning 0))
(if (char-equal (preceding-char) ?\@)
; then point is not positioned at the ending of a module name
(progn
(setq done nil)
(goto-char (match-end 2))
) ; end then
; else point is positioned at a valid module name ending
(goto-char (match-end 2))
(setq done t)
) ; end if
) ; end if
) ; end while
(setq module-name-ends-at (point))
(if (< (point) current-position)
; then
(error "Point not positioned within a module name.")
) ; end if
(if (looking-at "=") (setq defined t))
(setq old-module-name (web-eliminate-white-space
(buffer-substring (+ module-name-begins-at 2)
(- module-name-ends-at 2))))
(setq len-old-module-name (length old-module-name))
(if (and (> len-old-module-name 3)
(string-equal "..."
(substring old-module-name
(- len-old-module-name 3) len-old-module-name)))
; then
(setq len-old-module-name (- len-old-module-name 3))
) ; end if
(setq position-in-module-names (web-binary-search-of-names
web-module-names
(length web-module-names) old-module-name len-old-module-name))
(setq position-in-web-module-name-defined-in-used-in-list
(string-to-int (substring
(nth position-in-module-names web-module-names)
(+ (string-match " "
(nth position-in-module-names web-module-names)) 2))))
(setq replace-module-name (web-eliminate-white-space
(read-string (format "Replacement Module Name: "))))
(if (> (web-binary-search-of-names web-module-names
(length web-module-names)
replace-module-name (length replace-module-name)) -1)
; then the replace-module-name is already in list of web-module-names
(error "Replace module name has already been used.")
) ; end if
; ask the user if this is a global replacement, only one replacement,
; or replace some
(setq case (read-string "Replace (a)ll, (o)ne, or (s)ome: "))
(while (not (string-match (downcase (substring case 0 1)) "aos"))
(ding)
(setq case (read-string "Replace (a)ll, (o)ne, or (s)ome: "))
) ; end while
(cond
((char-equal (string-to-char (downcase case)) ?a)
(while (nth ctr (car (cdr (nth
position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in))))
(setq modules-where-name-is-to-be-replaced (append
modules-where-name-is-to-be-replaced
(list (nth ctr (car (cdr
(nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)))))))
(setq ctr (1+ ctr))
) ; end while
(setq ctr 0)
(while (nth ctr (car (cdr (cdr (nth
position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)))))
(setq modules-where-name-is-to-be-replaced (append
modules-where-name-is-to-be-replaced
(list (nth ctr (car (cdr (cdr
(nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in))))))))
(setq ctr (1+ ctr))
) ; end while
(setq modules-where-name-is-to-be-replaced (sort
modules-where-name-is-to-be-replaced '<))
(while (car modules-where-name-is-to-be-replaced)
(web-goto-module (car modules-where-name-is-to-be-replaced))
(forward-char 2) ; get past the module beginning
(save-excursion
(if (re-search-forward "^@\\(i\\| \\|\n\\|\t\\|\\*\\)" nil t)
; then
(setq next-module-begins (point))
; else
(setq next-module-begins (point-max))
) ; end if
) ; end excursion
(message "Replacing name in Module %d"
(car modules-where-name-is-to-be-replaced))
(while (re-search-forward web-module-name next-module-begins t)
(setq module-name (web-eliminate-white-space
(buffer-substring (match-beginning 2) (match-end 2))))
(setq len (length module-name))
(if (and (> len 3) (string-equal "..."
(substring module-name (- len 3) len)))
; then
(setq len (- len 3))
) ; end if
(if (string-equal (substring module-name 0
(min len len-old-module-name))
(substring old-module-name 0
(min len len-old-module-name)))
; then do the replacement
(progn
(backward-char (+ (length (buffer-substring
(match-beginning 2) (match-end 2))) 2))
(delete-char (length (buffer-substring
(match-beginning 2) (match-end 2))))
(insert replace-module-name)
) ; end then
) ; end if
) ; end while
(setq modules-where-name-is-to-be-replaced
(cdr modules-where-name-is-to-be-replaced))
) ; end while
; update the web-module-names and
; web-module-name-defined-in-used-in lists
(setcar (nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in) replace-module-name)
(setq ctr 0
temp-list nil)
(while (< ctr (length web-module-names))
(if (/= ctr position-in-module-names)
; then
(setq temp-list (append temp-list
(list (nth ctr web-module-names))))
) ; end if
(setq ctr (1+ ctr))
) ; end while
(setq temp-list (append temp-list (list (concat
replace-module-name " "
(int-to-string
position-in-web-module-name-defined-in-used-in-list)))))
(setq web-module-names (sort temp-list 'string<))
(web-view-module-names-list)
) ; end case
((char-equal (string-to-char (downcase case)) ?o)
; rename only one occurrence
(setq module-number-of-replacement (web-what-module)
temp-list nil
ctr 0)
(if defined
; then
(progn
(if (= 1 (length (car (cdr
(nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)))))
; then
(error (concat "Use the A option. "
"Attempt to rename module that was defined only once."))
; else
(setq web-number-of-module-names
(1+ web-number-of-module-names))
(while (nth ctr (car (cdr
(nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in))))
(if (/= module-number-of-replacement
(nth ctr (car (cdr
(nth
position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)))))
; then
(setq temp-list (append temp-list (list (nth ctr (car (cdr
(nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)))))))
) ; end if
(setq ctr (1+ ctr))
) ; end while
(setcdr (nth
position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)
(append (list temp-list)
(list (car (cdr (cdr
(nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)))))))
(setq web-module-name-defined-in-used-in (append
web-module-name-defined-in-used-in (list
(list replace-module-name
(list module-number-of-replacement) (list ())))))
(setq web-module-names (sort
(append web-module-names (list (concat
replace-module-name " "
(int-to-string (1- web-number-of-module-names)))))
'string<))
) ; end if
) ; end then
; else
(setq web-number-of-module-names (1+ web-number-of-module-names))
(while (nth ctr (car (cdr (cdr
(nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)))))
(if (/= module-number-of-replacement
(nth ctr (car (cdr (cdr
(nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in))))))
; then
(setq temp-list (append temp-list (list (nth ctr (car (cdr (cdr
(nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in))))))))
) ; end if
(setq ctr (1+ ctr))
) ; end while
(setcdr (nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)
(append (list (car (cdr (nth
position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in))))
(list temp-list)))
(setq web-module-name-defined-in-used-in (append
web-module-name-defined-in-used-in (list
(list replace-module-name
(list (web-append-a-stub-module replace-module-name))
(list ())))))
(setq web-module-names (sort (append web-module-names (list (concat
replace-module-name " "
(int-to-string (1- web-number-of-module-names)))))
'string<))
) ; end if
(goto-char (+ module-name-begins-at 2))
(delete-char (1- (- module-name-ends-at (point))))
(insert replace-module-name)
(web-view-module-names-list)
) ; end case
((char-equal (string-to-char (downcase case)) ?s)
(setq old-define nil
new-define nil
old-use nil
new-use nil
defined nil)
(while (nth ctr (car (cdr (nth
position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in))))
(setq modules-where-name-is-to-be-replaced (append
modules-where-name-is-to-be-replaced
(list (nth ctr (car (cdr
(nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)))))))
(setq ctr (1+ ctr))
) ; end while
(setq ctr 0)
(while (nth ctr (car (cdr (cdr (nth
position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)))))
(setq modules-where-name-is-to-be-replaced (append
modules-where-name-is-to-be-replaced
(list (nth ctr (car (cdr (cdr
(nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in))))))))
(setq ctr (1+ ctr))
) ; end while
(setq modules-where-name-is-to-be-replaced (sort
modules-where-name-is-to-be-replaced '<))
(while (car modules-where-name-is-to-be-replaced)
(web-goto-module (car modules-where-name-is-to-be-replaced))
(forward-char 2) ; get past the module beginning
(save-excursion
(if (re-search-forward "^@\\(i\\| \\|\n\\|\t\\|\\*\\)" nil t)
; then
(setq next-module-begins (point))
; else
(setq next-module-begins (point-max))
) ; end if
) ; end excursion
(while (re-search-forward web-module-name next-module-begins t)
(setq module-name (web-eliminate-white-space
(buffer-substring (match-beginning 2) (match-end 2))))
(setq len (length module-name))
(if (and (> len 3) (string-equal "..."
(substring module-name (- len 3) len)))
; then
(setq len (- len 3))
) ; end if
(if (string-equal (substring module-name 0
(min len len-old-module-name))
(substring old-module-name 0
(min len len-old-module-name)))
; then ask if it is to be replaced
(progn
(let ((data (match-data)))
(unwind-protect
(if (looking-at "=") (setq defined t))
(store-match-data data)
) ; end protect
) ; end let
(recenter 0)
(if (y-or-n-p (format
"Replace this %s occurrence in Module %d? "
(if defined "defined in" "used in")
(car modules-where-name-is-to-be-replaced)))
; then
(progn
(if defined
; then
(setq new-define (append new-define
(list (car modules-where-name-is-to-be-replaced))))
; else
(setq new-use (append new-use
(list (car modules-where-name-is-to-be-replaced))))
) ; end if
(backward-char (+ (length (buffer-substring
(match-beginning 2) (match-end 2))) 2))
(delete-char (length (buffer-substring
(match-beginning 2) (match-end 2))))
(insert replace-module-name)
) ; end then
; else
(if defined
; then
(setq old-define (append old-define
(list (car modules-where-name-is-to-be-replaced))))
; else
(setq old-use (append old-use
(list (car modules-where-name-is-to-be-replaced))))
) ; end if
) ; end if
) ; end then
) ; end if
) ; end while
(setq modules-where-name-is-to-be-replaced
(cdr modules-where-name-is-to-be-replaced))
) ; end while
(cond
((and (null old-define) (null old-use))
; similar to replace all -- the old name must be removed
(setcar (nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in) replace-module-name)
(setq ctr 0
temp-list nil)
(while (< ctr (length web-module-names))
(if (/= ctr position-in-module-names)
; then
(setq temp-list (append temp-list
(list (nth ctr web-module-names))))
) ; end if
(setq ctr (1+ ctr))
) ; end while
(setq temp-list (append temp-list (list (concat
replace-module-name " " (int-to-string
position-in-web-module-name-defined-in-used-in-list)))))
(setq web-module-names (sort temp-list 'string<))
(web-view-module-names-list)
) ; end case
((null old-define)
; append a stub for the old
(setq web-number-of-module-names (1+ web-number-of-module-names))
(setcdr (nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in) (append
(list (list (web-append-a-stub-module (car
(nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)))))
(list old-use)))
(setq web-module-name-defined-in-used-in (append
web-module-name-defined-in-used-in
(list (list replace-module-name
new-define new-use))))
(setq web-module-names (sort
(append web-module-names (list (concat
replace-module-name " "
(int-to-string (1- web-number-of-module-names)))))
'string<))
(web-view-module-names-list)
) ; end case
((and (null new-define) (null new-use))
; do nothing -- no name has been replaced
) ; end case
((null new-define)
; append a stub for the replace module name
(setq web-number-of-module-names (1+ web-number-of-module-names))
(setcdr (nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)
(append (list old-define) (list old-use)))
(setq web-module-name-defined-in-used-in (append
web-module-name-defined-in-used-in
(list (list replace-module-name
(list (web-append-a-stub-module replace-module-name))
new-use))))
(setq web-module-names (sort
(append web-module-names (list (concat
replace-module-name " "
(int-to-string (1- web-number-of-module-names)))))
'string<))
(web-view-module-names-list)
) ; end case
(t
; update both lists
(setq web-number-of-module-names (1+ web-number-of-module-names))
(setcdr (nth position-in-web-module-name-defined-in-used-in-list
web-module-name-defined-in-used-in)
(append (list old-define) (list old-use)))
(setq web-module-name-defined-in-used-in (append
web-module-name-defined-in-used-in
(list (list replace-module-name
new-define new-use))))
(setq web-module-names (sort
(append web-module-names (list (concat
replace-module-name " "
(int-to-string (1- web-number-of-module-names)))))
'string<))
(web-view-module-names-list)
) ; end case
) ; end cond
) ; end case
) ; end cond
) ; end excursion
) ; end let
)
(defun web-update-the-location-of-module-vector (next-char)
"This function is invoked by \\[web-is-this-a-new-module-beginning] whenever
a new module is started. The vector web-location-of-module must be updated to
reflect the addition of the new module.
ARGUMENTS : next-char (required)
GLOBAL Variables : web-location-of-module, web-number-of-modules-in-file, and
web-max-number-of-modules
LOCAL Variables : ctr, file-number, number-of-module-to-be-inserted,
relative-position, and section-number
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-count-modules,
and web-what-module"
(let ((ctr (web-count-modules))
(file-number (web-check-if-buffer-is-one-of-the-web-files))
(number-of-module-to-be-inserted (web-what-module))
(relative-position 0)
(section-number 0)
)
(if (>= ctr web-max-number-of-modules)
; then
(error "Increase the constant web-max-number-of-modules.")
; else
(message "Updating the web-location-of-module vector...")
(while (>= ctr number-of-module-to-be-inserted)
(if (= file-number (aref (aref web-location-of-module ctr) 0))
; then increment its relative position in the file
(progn
(setq relative-position (aref (aref web-location-of-module ctr) 1))
(aset (aref web-location-of-module ctr) 1
(1+ (aref (aref web-location-of-module ctr) 1)))
) ; end then
) ; end if
(if (char-equal next-char ?*)
; then increment the section number
(aset (aref web-location-of-module ctr) 2
(1+ (aref (aref web-location-of-module ctr) 2)))
) ; end if
(aset web-location-of-module (1+ ctr)
(aref web-location-of-module ctr))
(setq ctr (1- ctr))
) ; end while
(if (char-equal next-char ?*)
; then
(setq section-number (1+ (aref
(aref web-location-of-module
(1- number-of-module-to-be-inserted)) 2)))
; else
(setq section-number (aref
(aref web-location-of-module
(1- number-of-module-to-be-inserted)) 2))
) ; end if
(aset web-location-of-module number-of-module-to-be-inserted
(vector file-number
(if (not (zerop relative-position))
; then
relative-position
; else
(1+ (aref web-number-of-modules-in-file file-number))
) ; end if
section-number
0
) ; end vector
) ; end aset
(aset web-number-of-modules-in-file file-number
(1+ (aref web-number-of-modules-in-file file-number)))
(message "Updating the web-location-of-module vector...done")
) ; end if
) ; end let
)
(defun web-update-the-module-name-defined-in-used-in-list (new-module-number)
"This function is invoked when NEW-MODULE-NUMBER is inserted. All module
numbers in the list web-module-name-defined-in-used-in must be updated to
reflect the insertion of this new module.
ARGUMENTS : new-module-number
GLOBAL Variable : web-module-name-defined-in-used-in
LOCAL Variables : ctr, defined-in-list, i, and used-in-list
RETURNS : Nothing
USES : Nothing"
(let ((ctr 0)
defined-in-list
(i 0)
used-in-list
)
(while (nth ctr web-module-name-defined-in-used-in)
(setq defined-in-list ()
used-in-list ()
i 0
) ; end setq
(while (nth i (car (cdr (nth ctr web-module-name-defined-in-used-in))))
(if (<= new-module-number
(nth i (car (cdr
(nth ctr web-module-name-defined-in-used-in)))))
; then add 1 to the number and append to the list
(setq defined-in-list (append defined-in-list (list (1+
(nth i (car (cdr
(nth ctr web-module-name-defined-in-used-in))))))))
; else
(setq defined-in-list (append defined-in-list (list
(nth i (car (cdr (nth ctr web-module-name-defined-in-used-in)))))))
) ; end if
(setq i (1+ i))
) ; end while
(setq i 0)
(while (nth i
(car (cdr (cdr (nth ctr web-module-name-defined-in-used-in)))))
(if (<= new-module-number
(nth i
(car (cdr (cdr (nth ctr web-module-name-defined-in-used-in))))))
; then add 1 to the number and append to the list
(setq used-in-list (append used-in-list (list (1+
(nth i (car (cdr (cdr (nth ctr
web-module-name-defined-in-used-in)))))))))
; else
(setq used-in-list (append used-in-list (list
(nth i (car (cdr (cdr (nth ctr
web-module-name-defined-in-used-in))))))))
) ; end if
(setq i (1+ i))
) ; end while
(setcdr (nth ctr web-module-name-defined-in-used-in)
(append (list defined-in-list) (list used-in-list)))
(setq ctr (1+ ctr))
) ; end while
) ; end let
)
(defun web-view-changed-modules-list ()
"This function can be invoked from either the buffer containing the Web
document or the buffer containing the associated CHange file. It displays in
the minibuffer a list of the modules in the Web document that have been changed
in the CHange file.
ARGUMENTS : None
GLOBAL Variable : web-location-of-module
LOCAL Variables : changed-modules
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-convert-list-to-string,
web-count-modules and web-journal"
(interactive)
(web-journal "web-view-changed-modules-list")
(web-check-if-buffer-is-one-of-the-web-files)
(let (changed-modules
(ctr 0)
(index 0)
line-to-be-inserted
(number-of-modules (web-count-modules))
)
(while (< ctr number-of-modules)
(if (not (zerop (aref (aref web-location-of-module ctr) 3)))
; then
(setq changed-modules (append changed-modules
(list ctr)))
) ; end if
(setq ctr (1+ ctr))
) ; end while
(get-buffer-create "*CHanged Modules*")
(save-excursion
(set-buffer "*CHanged Modules*")
(goto-char (point-min))
(kill-line (count-lines (point-min) (point-max)))
(if (zerop (length changed-modules))
; then
(setq line-to-be-inserted "No modules have been changed.")
; else
(setq line-to-be-inserted
(concat
(if (= (length changed-modules) 1) "Module " "Modules ")
(web-convert-list-to-string changed-modules) " "
(if (= (length changed-modules) 1) "has " "have ")
"been changed."
) ; end concat
) ; end setq
) ; end if
(if (> (length line-to-be-inserted) 79)
; then
(progn
(while (> (length line-to-be-inserted) 79)
(setq index 79)
(while (not (char-equal ?
(string-to-char
(substring line-to-be-inserted (1- index) index))))
(setq index (1- index))
) ; end while
(insert-string (concat
(substring line-to-be-inserted 0 (1- index)) "\n"))
(setq line-to-be-inserted
(substring line-to-be-inserted index))
) ; end while
(insert-string (concat line-to-be-inserted "\n"))
) ; end then
; else
(insert-string (concat line-to-be-inserted "\n"))
) ; end if
) ; end excursion
(split-window-vertically
(save-excursion
(set-buffer "*CHanged Modules*")
(goto-char (point-min))
(- (screen-height) (max 3 (count-lines (point-min) (point-max))) 2)
) ; end excursion
) ; end split-window-vertically
(other-window 1)
(switch-to-buffer "*CHanged Modules*")
(use-local-map web-mode-map)
(setq major-mode 'Web-mode
mode-name "Web")
(other-window 1)
(message "Type C-x 1 to remove the bottom window")
) ; end let
)
(defun web-view-index ()
"This function is used when the user wishes to see an index for the Web as
produced by Weave. The Web document is Weaved if there have been changes or if
no INDEX.tex file exists for the Web document. The index is then reformatted
slightly to accommodate presentation by Emacs.
ARGUMENTS : None
GLOBAL Variable : web-change-buffer-name, web-selected-index-entry-occurrences,
web-buffer-name, and web-index-buffer-name
LOCAL Variables : message-string, size-of-buffer, and web-type
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-reformat-the-index, and
web-journal"
(interactive)
(web-journal "web-view-index")
(web-check-if-buffer-is-one-of-the-web-files)
(let (message-string
(size-of-buffer 0)
web-type
)
(setq web-selected-index-entry-occurrences nil)
(setq web-index-buffer-name
(concat "*INDEX for " (buffer-name (current-buffer)) "*"))
(get-buffer-create web-index-buffer-name)
(save-excursion
(set-buffer web-index-buffer-name)
(setq size-of-buffer (buffer-size))
(use-local-map web-mode-map)
(setq major-mode 'Web-mode
mode-name "Web")
) ; end excursion
(if (and (not (buffer-modified-p
(get-file-buffer (expand-file-name web-change-buffer-name))))
(not (buffer-modified-p
(get-file-buffer (expand-file-name web-buffer-name))))
(not (zerop size-of-buffer))
)
; then
(switch-to-buffer web-index-buffer-name)
; else
(save-some-buffers)
(setq web-type (read-string
"Is this WEB, Pascal, C, or Fortran? (P, p, C, c, F, f) => "))
(while (and (not (char-equal (upcase (string-to-char web-type)) ?C))
(not (char-equal (upcase (string-to-char web-type)) ?P))
(not (char-equal (upcase (string-to-char web-type)) ?F)))
(ding)
(setq web-type (read-string
"Is this WEB, Pascal, C, or Fortran? (P, p, C, c, F, f) => "))
) ; end while
(save-excursion ; determine if CHange file is empty
(set-buffer web-change-buffer-name)
(setq size-of-buffer (buffer-size))
) ; end excursion
(if (not (zerop size-of-buffer))
; then a CHange file exists
(cond
((char-equal (upcase (string-to-char web-type)) ?C)
; then CWEAVE the file
(setq message-string (concat "CWEAVEing "
web-buffer-name " and " web-change-buffer-name "..."))
(message "%s" message-string)
(call-process "/usr/local/lib/tex/web/cweave" nil
(get-buffer-create "WEAVE-Output") nil
web-buffer-name
web-change-buffer-name)
) ; end case
((char-equal (upcase (string-to-char web-type)) ?F)
; then FWEAVE the file
(setq message-string (concat "FWEAVEing "
web-buffer-name " and " web-change-buffer-name "..."))
(message "%s" message-string)
(call-process "/usr/local/lib/tex/web/fweave" nil
(get-buffer-create "WEAVE-Output") nil
web-buffer-name
web-change-buffer-name)
) ; end case
(t
; else WEAVE the file (it's a Pascal Web)
(setq message-string (concat "WEAVEing "
web-buffer-name " and " web-change-buffer-name "..."))
(message "%s" message-string)
(call-process "/usr/local/lib/tex/web/weave" nil
(get-buffer-create "WEAVE-Output") nil
web-buffer-name
web-change-buffer-name)
) ; end case
) ; end cond
; else no Change file exists
(cond
((char-equal (upcase (string-to-char web-type)) ?C)
; then CWEAVE the file
(setq message-string (concat
"CWEAVEing " (buffer-name (current-buffer)) "..."))
(message "%s" message-string)
(call-process "/usr/local/lib/tex/web/cweave" nil
(get-buffer-create "WEAVE-Output") nil
web-buffer-name)
) ; end case
((char-equal (upcase (string-to-char web-type)) ?F)
; then FWEAVE the file
(setq message-string (concat
"FWEAVEing " (buffer-name (current-buffer)) "..."))
(message "%s" message-string)
(call-process "/usr/local/lib/tex/web/fweave" nil
(get-buffer-create "WEAVE-Output") nil
web-buffer-name)
) ; end case
(t
; else WEAVE the file (it's a Pascal Web)
(setq message-string
(concat "Pascal WEAVEing " (buffer-name (current-buffer)) "..."))
(message "%s" message-string)
(call-process "/usr/local/lib/tex/web/weave" nil
(get-buffer-create "WEAVE-Output") nil
web-buffer-name)
) ; end case
) ; end cond
) ; end if
(message "%sdone" message-string)
(sit-for 1)
(web-reformat-the-index)
) ; end if
) ; end let
)
(defun web-view-module-names-list ()
"This function can be invoked by the user to display a list of the module
names used in the Web. A list of the modules in which the module name is
Defined In and Used In is also displayed.
ARGUMENTS : None
GLOBAL Variables : web-module-name-defined-in-used-in, web-module-names,
and web-mode-map
LOCAL Variables : ctr, index, and ptr
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files,
web-convert-list-to-string, and web-journal"
(interactive)
(web-journal "web-view-module-names-list")
(web-check-if-buffer-is-one-of-the-web-files)
(let ((ctr 0)
(index 0)
(ptr 0)
)
(switch-to-buffer "*Module Name (Defined In) (Used In)*")
(use-local-map web-mode-map)
(setq major-mode 'Web-mode
mode-name "Web")
(goto-char (point-min))
(kill-line (count-lines (point-min) (point-max)))
(while (nth ctr web-module-names)
(setq ptr (string-to-int (substring (nth ctr web-module-names)
(+ (string-match " " (nth ctr web-module-names)) 2))))
(setq line-to-be-inserted (concat
(car (nth ptr web-module-name-defined-in-used-in))
" ("
(web-convert-list-to-string
(car (cdr (nth ptr web-module-name-defined-in-used-in))))
") ("
(web-convert-list-to-string
(car (cdr (cdr (nth ptr web-module-name-defined-in-used-in)))))
")")
) ; end setq
(if (> (length line-to-be-inserted) 79)
; then
(progn
(while (> (length line-to-be-inserted) 79)
(setq index 79)
(while (not (char-equal ?
(string-to-char
(substring line-to-be-inserted (1- index) index))))
(setq index (1- index))
) ; end while
(insert-string (concat
(substring line-to-be-inserted 0 (1- index)) "\n"))
(setq line-to-be-inserted (concat " "
(substring line-to-be-inserted index)))
) ; end while
(insert-string (concat line-to-be-inserted "\n"))
) ; end then
; else
(insert-string (concat line-to-be-inserted "\n"))
) ; end if
(setq ctr (1+ ctr))
) ; end while
(goto-char (point-min))
) ; end let
)
(defun web-view-section-names-list ()
"This function prints a list of the major section names in the Web document.
It also shows the module number where each major section begins. The list is
displayed in another buffer, *Section Names*.
ARGUMENTS : None
GLOBAL Variable : web-mode-map
LOCAL Variables : ctr, number-of-modules, section-name, section-names,
size-of-buffer, and space-on-left
RETURNS : Nothing
USES : web-check-if-buffer-is-one-of-the-web-files, web-collect-section-names,
web-count-modules and web-journal"
(interactive)
(web-journal "web-view-section-names-list")
(web-check-if-buffer-is-one-of-the-web-files)
(get-buffer-create "*Section Names*")
(save-excursion
(set-buffer "*Section Names*")
(setq size-of-buffer (buffer-size))
) ; end excursion
(let* ((ctr 0)
(number-of-modules (web-count-modules))
section-name
(section-names (web-collect-section-names))
(space-on-left
(/ (- 7 (length (int-to-string number-of-modules))) 2))
)
(switch-to-buffer "*Section Names*")
(use-local-map web-mode-map)
(setq major-mode 'Web-mode
mode-name "Web")
(goto-char (point-min))
(kill-line (count-lines (point) (point-max)))
(insert-string "Module# Section Name\n")
(while (nth ctr section-names)
(setq section-name (car (nth ctr section-names)))
(if (> (length section-name) 71)
; then
(setq section-name (concat (substring section-name 0 68) "..."))
) ; end if
(insert-string (concat (make-string (+ space-on-left
(- (length (int-to-string number-of-modules))
(length (int-to-string (car (cdr (nth ctr section-names))))))) ? )
(int-to-string (car (cdr (nth ctr section-names))))
(make-string (- 9 (+ space-on-left
(length (int-to-string number-of-modules)))) ? )
section-name "\n"))
(setq ctr (1+ ctr))
) ; end while
(goto-char (point-min))
) ; end let
)
(defun web-what-change ()
"This function can only be invoked in the buffer containing the CHange file
associated with the Web document that \\[web-mode] was used on most recently.
Based on point's position in the CHange file buffer, this function displays a
descriptive message indicating what module is being changed.
ARGUMENTS : None
GLOBAL Variables : web-change-buffer-name, web-location-of-module,
and web-buffer-name
LOCAL Variables : bound-for-search, index, module-number,
next-change-begins-at, number-of-changes,
and number-of-preceding-@x
RETURNS : module-number
USES : web-journal"
(interactive)
(web-journal "web-what-change")
(if (not (string= (buffer-name (current-buffer)) web-change-buffer-name))
; then
(error "Not in CHange buffer associated with %s" web-buffer-name)
; else
(if (zerop (buffer-size))
; then
(error "CHange buffer is empty")
; else
(let ((bound-for-search 0)
(module-number 0)
(next-change-begins-at 0)
(number-of-preceding-@x 0)
)
(save-excursion
(end-of-line)
(setq bound-for-search (point))
(if (not (re-search-backward "^@x" nil t))
; then
(error "Point not positioned between an @x @z")
) ; end if
(forward-char (length
(buffer-substring (match-beginning 0) (match-end 0))))
(save-excursion
(if (re-search-forward "^@x" nil t)
; then
(setq next-change-begins-at (- (point)
(length (buffer-substring (match-beginning 0) (match-end 0)))))
; else
(setq next-change-begins-at (point-max))
) ; end if
) ; end excursion
(if (not (re-search-forward "^@z" next-change-begins-at t))
; then
(error "This CHange has no matching @z")
) ; end if
(if (> bound-for-search (save-excursion (end-of-line) (point)))
; then
(error "Point not positioned between an @x @z")
; else
(goto-char (point-min))
(while (re-search-forward "^@x" bound-for-search t)
(setq number-of-preceding-@x (1+ number-of-preceding-@x))
) ; end while
) ; end if
) ; end excursion
(while (< (aref (aref web-location-of-module module-number) 4)
number-of-preceding-@x)
(setq module-number (1+ module-number))
) ; end while
(if (> (aref (aref web-location-of-module module-number) 4)
number-of-preceding-@x)
; then search back to the previous change
(progn
(setq module-number (1- module-number))
(while (/= (aref (aref web-location-of-module module-number) 3) 1)
(setq module-number (1- module-number))
) ; end while
) ; end then
) ; end if
(message "CHange corresponds to Module %d" module-number)
module-number ; return the module number of the CHange
) ; end let
) ; end if
) ; end if
)
(defun web-what-module ()
"This function tells the user what module point is currently positioned in.
ARGUMENTS : None
GLOBAL Variables : web-default-directory, web-files, and web-module-begins
LOCAL Variables : ctr, done, file-number, module-count, and stopping-point
RETURNS : the module # that point is currently positioned in
USES : web-check-if-buffer-is-one-of-the-web-files, web-count-the-matches and
web-journal"
(interactive)
(web-journal "web-what-module")
(save-excursion
(let ((ctr 1)
done
(file-number (web-check-if-buffer-is-one-of-the-web-files))
(module-count 0)
(stopping-point (make-vector (length web-files) 0))
)
(while (nth ctr web-files)
(save-excursion
(set-buffer (get-file-buffer (expand-file-name (nth ctr web-files)
web-default-directory)))
(goto-char (point-max))
(aset stopping-point ctr (point))
) ; end escursion
(setq ctr (1+ ctr))
) ; end while
(aset stopping-point file-number
(save-excursion (beginning-of-line) (point)))
(save-excursion
(set-buffer (get-file-buffer (expand-file-name (nth 1 web-files)
web-default-directory)))
(web-count-the-matches "^@\\(i\\| \\|\t\\|\n\\|\\*\\)")
) ; end excursion
(beginning-of-line)
(if (looking-at web-module-begins)
; then
(setq module-count (1+ module-count))
) ; end if
(message "Module %d" module-count)
module-count ; return the module #
) ; end let
) ; end excursion
)
(defun web-what-section ()
"This function tells the user what section the cursor is currently positioned
in.
ARGUMENTS : None
GLOBAL Variables : web-location-of-module and web-files
LOCAL Variables : current-module
RETURNS : the section number that point is positioned in
USES : web-check-if-buffer-is-one-of-the-web-files, web-journal,
and web-what-module"
(interactive)
(web-journal "web-what-section")
(web-check-if-buffer-is-one-of-the-web-files)
(let ((current-module (web-what-module)))
(message "Section %d in %s"
(aref (aref web-location-of-module current-module) 2)
(upcase (nth 1 web-files)))
; return the section #
(aref (aref web-location-of-module current-module) 2)
) ; end let
)
(defun web-write-module-names-to-a-file ()
"This is an internal support function that writes the module names,
defined-in lists, and Used In lists to a file. This is done so that initial
startup can be speeded up.
ARGUMENTS : None
GLOBAL Variable : web-buffer-name
LOCAL Variables : None
RETURNS : Nothing
USES : web-view-module-names-list"
(save-excursion
(web-view-module-names-list)
(write-region 1 (point-max) (concat (substring web-buffer-name 0
(string-match "\\." web-buffer-name)) ".mods") nil 1)
) ; end excursion
)
|