Source

python emacs / anything.el

Full commit
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
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
;;;; anything.el --- open anything / QuickSilver-like candidate-selection framework
;; $Id: anything.el,v 1.282 2010-04-01 02:22:22 rubikitch Exp $

;; Copyright (C) 2007              Tamas Patrovics
;;               2008, 2009, 2010  rubikitch <rubikitch@ruby-lang.org>

;; Author: Tamas Patrovics
;; Maintainer: rubikitch <rubikitch@ruby-lang.org>
;; Keywords: files, frames, help, matching, outlines, processes, tools, convenience, anything
;; URL: http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
;; Site: http://www.emacswiki.org/cgi-bin/emacs/Anything

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This file 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.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;;
;; Start with M-x anything, narrow the list by typing some pattern,
;; select with up/down/pgup/pgdown/C-p/C-n/C-v/M-v, choose with enter,
;; left/right moves between sources. With TAB actions can be selected
;; if the selected candidate has more than one possible action.
;;
;; Note that anything.el provides only the framework and some example
;; configurations for demonstration purposes. See anything-config.el
;; for practical, polished, easy to use configurations which can be
;; used to assemble a custom personalized configuration. And many
;; other configurations are in the EmacsWiki.
;; 
;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-config.el
;; http://www.emacswiki.org/cgi-bin/emacs/AnythingSources
;;
;; Maintainer's configuration is in the EmacsWiki. It would tell you
;; many tips to write smart sources!
;;
;; http://www.emacswiki.org/cgi-bin/emacs/RubikitchAnythingConfiguration
;;
;; Here is Japanese translation of `anything-sources' attributes. Thanks.
;; http://d.hatena.ne.jp/sirocco634/20091012/1255336649

;;; Bug Report:
;;
;; If you have problems, send a bug report via C-c C-x C-b in anything session (best)
;; or M-x anything-send-bug-report outside anything session.
;; I implemented bug report feature because I want to know your current state.
;; It helps me to solve problems easily.
;; The step is:
;;  0) Setup mail in Emacs, the easiest way is:
;;       (setq user-mail-address "your@mail.address")
;;       (setq user-full-name "Your Full Name")
;;       (setq smtpmail-smtp-server "your.smtp.server.jp")
;;       (setq mail-user-agent 'message-user-agent)
;;       (setq message-send-mail-function 'message-smtpmail-send-it)
;;  1) Be sure to use the LATEST version of anything.el.
;;  2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
;;  3) Use Lisp version instead of compiled one: (load "anything.el")
;;  4) Do it!
;;  5) If you got an error, please do not close *Backtrace* buffer.
;;  6) Type C-c C-x C-b (anything session, best!) 
;;     or M-x anything-send-bug-report (outside)
;;     then M-x insert-buffer *Backtrace* (if you got error)
;;  7) Describe the bug using a precise recipe.
;;  8) Type C-c C-c to send.
;;  # If you are a Japanese, please write in Japanese:-)


;;; Commands:
;;
;; Below are complete command list:
;;
;;  `anything'
;;    Select anything. In Lisp program, some optional arguments can be used.
;;  `anything-resume'
;;    Resurrect previously invoked `anything'.
;;  `anything-at-point'
;;    Same as `anything' except when C-u is pressed, the initial input is the symbol at point.
;;  `anything-force-update'
;;    Recalculate and update candidates.
;;  `anything-select-action'
;;    Select an action for the currently selected candidate.
;;  `anything-previous-line'
;;    Move selection to the previous line.
;;  `anything-next-line'
;;    Move selection to the next line.
;;  `anything-previous-page'
;;    Move selection back with a pageful.
;;  `anything-next-page'
;;    Move selection forward with a pageful.
;;  `anything-beginning-of-buffer'
;;    Move selection at the top.
;;  `anything-end-of-buffer'
;;    Move selection at the bottom.
;;  `anything-previous-source'
;;    Move selection to the previous source.
;;  `anything-next-source'
;;    Move selection to the next source.
;;  `anything-exit-minibuffer'
;;    Select the current candidate by exiting the minibuffer.
;;  `anything-help'
;;    Help of `anything'.
;;  `anything-debug-output'
;;    Show all anything-related variables at this time.
;;  `anything-delete-current-selection'
;;    Delete the currently selected item.
;;  `anything-delete-minibuffer-content'
;;    Same as `delete-minibuffer-contents' but this is a command.
;;  `anything-toggle-resplit-window'
;;    Toggle resplit anything window, vertically or horizontally.
;;  `anything-select-2nd-action'
;;    Select the 2nd action for the currently selected candidate.
;;  `anything-select-3rd-action'
;;    Select the 3rd action for the currently selected candidate.
;;  `anything-select-4th-action'
;;    Select the 4th action for the currently selected candidate.
;;  `anything-select-2nd-action-or-end-of-line'
;;    Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
;;  `anything-execute-persistent-action'
;;    If a candidate is selected then perform the associated action without quitting anything.
;;  `anything-scroll-other-window'
;;    Scroll other window (not *Anything* window) upward.
;;  `anything-scroll-other-window-down'
;;    Scroll other window (not *Anything* window) downward.
;;  `anything-display-all-visible-marks'
;;    Show all `anything' visible marks strings.
;;  `anything-quit-and-find-file'
;;    Drop into `find-file' from `anything' like `iswitchb-find-file'.
;;  `anything-yank-selection'
;;    Set minibuffer contents to current selection.
;;  `anything-kill-selection-and-quit'
;;    Store current selection to kill ring.
;;  `anything-follow-mode'
;;    If this mode is on, persistent action is executed everytime the cursor is moved.
;;  `anything-migrate-sources'
;;    Help to migrate to new `anything' way.
;;  `anything-isearch'
;;    Start incremental search within results. (UNMAINTAINED)
;;  `anything-isearch-printing-char'
;;    Add printing char to the pattern.
;;  `anything-isearch-again'
;;    Search again for the current pattern
;;  `anything-isearch-delete'
;;    Undo last event.
;;  `anything-isearch-default-action'
;;    Execute the default action for the selected candidate.
;;  `anything-isearch-select-action'
;;    Choose an action for the selected candidate.
;;  `anything-isearch-cancel'
;;    Cancel Anything isearch.
;;  `anything-iswitchb-setup'
;;    Integrate anything completion into iswitchb (UNMAINTAINED).
;;  `anything-iswitchb-cancel-anything'
;;    Cancel anything completion and return to standard iswitchb.
;;  `anything-describe-anything-attribute'
;;    Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
;;  `anything-send-bug-report'
;;    Send a bug report of anything.el.
;;  `anything-send-bug-report-from-anything'
;;    Send a bug report of anything.el in anything session.
;;
;;; Customizable Options:
;;
;; Below are customizable option list:
;;

;; You can extend `anything' by writing plug-ins. As soon as
;; `anything' is invoked, `anything-sources' is compiled into basic
;; attributes, then compiled one is used during invocation.
;;
;; The oldest built-in plug-in is `type' attribute: appends
;; appropriate element of `anything-type-attributes'. Second built-in
;; plug-in is `candidates-in-buffer': selecting a line from candidates
;; buffer.
;;
;; To write a plug-in:
;; 1. Define a compiler: anything-compile-source--*
;; 2. Add compier function to `anything-compile-source-functions'.
;; 3. (optional) Write helper functions.
;;
;; Anything plug-ins are found in the EmacsWiki.
;;
;; http://www.emacswiki.org/cgi-bin/emacs/AnythingPlugins

;; Tested on Emacs 22/23.
;;
;;
;; Thanks to Vagn Johansen for ideas.
;; Thanks to Stefan Kamphausen for fixes and XEmacs support.
;; Thanks to Tassilo Horn for fixes.
;; Thanks to Drew Adams for various fixes (frame, isearch, customization, etc.)
;; Thanks to IMAKADO for candidates-in-buffer idea.
;; Thanks to Tomohiro MATSUYAMA for multiline patch.
;;

;;; (@* "Index")

;;  If you have library `linkd.el', load
;;  `linkd.el' and turn on `linkd-mode' now.  It lets you easily
;;  navigate around the sections  Linkd mode will
;;  highlight this Index.  You can get `linkd.el' here:
;;  http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el
;;


;;; (@* "INCOMPATIBLE CHANGES")

;; v1.277
;; 
;;   Default setting of `anything-save-configuration-functions' is changed.
;;   Anything saves/restores window configuration instead of frame configuration now.
;;   The default is changed because flickering is occurred in some environment.
;;   
;;   If you want to save and restore frame configuration, set this variable to
;;    '(set-frame-configuration . current-frame-configuration)
;;
;; v1.276
;;
;;   Fitting frame is disabled by default, because some flickering occurred
;;   in some environment.  To enable fitting, set both
;;   `anything-inhibit-fit-frame-flag' and `fit-frame-inhibit-fitting' to
;;   nil.
;;
;; v1.114
;;
;;   `anything-attr' returns nil when the source attribute is defined
;;   but the value of attribute is nil, eg. (volatile) cell. Use
;;   `anything-attr-defined' when testing whether the attribute is
;;   defined.

;;; (@* "Tips")

;; 
;; `anything-enable-shortcuts' enables us to select candidate easily.
;; If 'prefix then they can be selected using <prefix-key> <alnum>. 
;; The prefix key is `anything-select-with-prefix-shortcut'.
;; If the <prefix-key> is a letter, pressing twice inputs the letter itself.
;; e.g.
;;  (setq anything-enable-shortcuts 'prefix)
;;  (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)

;;
;; You can edit current selection using `anything-edit-current-selection'.
;; It is useful after persistent-action.

;;
;; For `anything' users, setting `anything-sources' directly and
;; invoke M-x anything is obsolete way for now. Try M-x
;; `anything-migrate-sources'!

;;
;; If you want to create anything sources, yasnippet would help you.
;; http://yasnippet.googlecode.com/
;;
;; Then get the snippet from
;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-source.yasnippet
;;
;; Put it in ~/.emacs.d/plugins/yasnippet/snippets/text-mode/emacs-lisp-mode/


;;
;; `anything-interpret-value' is useful function to interpret value
;; like `candidates' attribute.
;;
;; (anything-interpret-value "literal")            ; => "literal"
;; (anything-interpret-value (lambda () "lambda")) ; => "lambda"
;; (let ((source '((name . "lambda with source name"))))
;;   (anything-interpret-value
;;    (lambda () anything-source-name)
;;    source))                             ; => "lambda with source name"
;; (flet ((f () "function symbol"))
;;   (anything-interpret-value 'f))        ; => "function symbol"
;; (let ((v "variable symbol"))
;;   (anything-interpret-value 'v))        ; => "variable symbol"
;; (anything-interpret-value 'unbounded-1) ; error

;;
;; Now symbols are acceptable as candidates. So you do not have to use
;; `symbol-name' function. The source is much simpler. For example,
;; `apropos-internal' returns a list of symbols.
;; 
;;   (anything
;;    '(((name . "Commands")
;;       (candidates . (lambda () (apropos-internal anything-pattern 'commandp)))
;;       (volatile)
;;       (action . describe-function))))

;;
;; To mark a candidate, press C-SPC as normal Emacs marking. To go to
;; marked candidate, press M-[ or M-].

;;
;; `anything-map' is now Emacs-standard key bindings by default. If
;; you are using `iswitchb', execute `anything-iswitchb-setup'. Then
;; some key bindings are adjusted to `iswitchb'. Note that
;; anything-iswitchb is not maintained.

;;
;; There are many `anything' applications, using `anything' for
;; selecting candidate. In this case, if there is one candidate or no
;; candidate, popping up *anything* buffer is irritating. If one
;; candidate, you want to select it at once. If no candidate, you want
;; to quit `anything'. Set `anything-execute-action-at-once-if-one'
;; and `anything-quit-if-no-candidate' to non-nil to remedy it. Note
;; that setting these variables GLOBALLY is bad idea because of
;; delayed sources. These are meant to be let-binded.
;; See anything-etags.el for example.
;;
;; [EVAL IT] (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/anything-etags.el")
;;
;; ex.
;; (let ((anything-execute-action-at-once-if-one t)
;;       (anything-quit-if-no-candidate (lambda () (message "No candidate"))))
;;    (anything temporary-sources input))

;;
;; `set-frame-configuration' arises flickering. If you hate
;; flickering, eval:
;; (setq anything-save-configuration-functions
;;    '(set-window-configuration . current-window-configuration))
;; at the cost of restoring frame configuration (only window configuration).

;;
;; `anything-delete-current-selection' deletes the current line.
;; It is useful when deleting a candidate in persistent action.
;; eg. `kill-buffer'.
;;
;; [EVAL IT] (describe-function 'anything-delete-current-selection)

;;
;; `anything-attr' gets the attribute. `anything-attrset' sets the
;; attribute. `anything-attr-defined' tests whether the attribute is
;; defined. They handles source-local variables.
;;
;; [EVAL IT] (describe-function 'anything-attr)
;; [EVAL IT] (describe-function 'anything-attrset)
;; [EVAL IT] (describe-function 'anything-attr-defined)

;;
;; `anything-sources' accepts many attributes to make your life easier.
;; Now `anything-sources' accepts a list of symbols.
;;
;; [EVAL IT] (describe-variable 'anything-sources)

;;
;; `anything' has optional arguments. Now you do not have to let-bind
;; `anything-sources'.
;;
;; [EVAL IT] (describe-function 'anything)

;;
;; `anything-resume' resumes last `anything' session. Now you do not
;; have to retype pattern.
;;
;; [EVAL IT] (describe-function 'anything-resume)

;;
;; `anything-execute-persistent-action' executes action without
;; quitting `anything'. When popping up a buffer in other window by
;; persistent action, you can scroll with `anything-scroll-other-window' and
;; `anything-scroll-other-window-down'. See also `anything-sources' docstring.
;;
;; [EVAL IT] (describe-function 'anything-execute-persistent-action)
;; [EVAL IT] (describe-variable 'anything-sources)

;;
;; `anything-select-2nd-action', `anything-select-3rd-action' and
;; `anything-select-4th-action' select other than default action
;; without pressing Tab.

;;
;; Using `anything-candidate-buffer' and the candidates-in-buffer
;; attribute is much faster than traditional "candidates and match"
;; way. And `anything-current-buffer-is-modified' avoids to
;; recalculate candidates for unmodified buffer. See docstring of
;; them.
;;
;; [EVAL IT] (describe-function 'anything-candidate-buffer)
;; [EVAL IT] (describe-function 'anything-candidates-in-buffer)
;; [EVAL IT] (describe-function 'anything-current-buffer-is-modified)

;;
;; `anything-current-buffer' and `anything-buffer-file-name' stores
;; `(current-buffer)' and `buffer-file-name' in the buffer `anything'
;; is invoked. Use them freely.
;;
;; [EVAL IT] (describe-variable 'anything-current-buffer)
;; [EVAL IT] (describe-variable 'anything-buffer-file-name)

;;
;; `anything-completing-read' and `anything-read-file-name' are
;; experimental implementation. If you are curious, type M-x
;; anything-read-string-mode. It is a minor mode and toggles on/off.

;;
;; Use `anything-test-candidates' to test your handmade anything
;; sources. It simulates contents of *anything* buffer with pseudo
;; `anything-sources' and `anything-pattern', without side-effect. So
;; you can unit-test your anything sources! Let's TDD!
;;
;; [EVAL IT] (describe-function 'anything-test-candidates)
;;
;; There are many unit-testing framework in Emacs Lisp. See the EmacsWiki.
;; http://www.emacswiki.org/cgi-bin/emacs/UnitTesting
;;
;; There is an unit-test by Emacs Lisp Expectations at the tail of this file.
;; http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el
;; http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el

;;
;; If you want to create anything sources, see anything-config.el.
;; It is huge collection of sources. You can learn from examples.


;; (@* "TODO")
;;
;;   - process status indication
;;
;;   - async sources doesn't honor digit-shortcut-count
;;
;;   - anything-candidate-number-limit can't be nil everywhere

;; (@* "HISTORY")
;; $Log: anything.el,v $
;; Revision 1.280  2010-04-01 02:22:22  rubikitch
;; `anything': new argument ANY-KEYMAP
;;
;; Revision 1.279  2010/03/31 09:22:58  rubikitch
;; Add tips of yasnippet for source creators (no code change)
;;
;; Revision 1.278  2010/03/31 09:01:08  rubikitch
;; Added info to INCOMPATIBLE CHANGES
;;
;; Revision 1.277  2010/03/31 08:56:53  rubikitch
;; Anything saves/restores window configuration instead of frame configuration now.
;; The default is changed because flickering is occurred in some environment.
;;
;; If you want to save and restore frame configuration, set this variable to
;;  '(set-frame-configuration . current-frame-configuration)
;;
;; Revision 1.276  2010/03/31 08:52:50  rubikitch
;; Fitting frame is disabled by default, because some flickering occurred
;; in some environment.  To enable fitting, set both
;; `anything-inhibit-fit-frame-flag' and `fit-frame-inhibit-fitting' to
;; nil.
;;
;; Revision 1.275  2010/03/31 02:46:09  rubikitch
;; (defvaralias 'anything-attributes 'anything-additional-attributes)
;;
;; Revision 1.274  2010/03/31 02:43:35  rubikitch
;; New command: `anything-describe-anything-attribute'
;;
;; Revision 1.273  2010/03/31 02:37:18  rubikitch
;; Document all attributes by `anything-document-attribute' instead of `anything-sources' docstring
;;
;; Revision 1.272  2010/03/29 21:05:47  rubikitch
;; `anything-mode-line-string': use `make-local-variable' instead
;;
;; Revision 1.271  2010/03/29 09:59:17  rubikitch
;; stupid bug
;;
;; Revision 1.270  2010/03/29 09:56:12  rubikitch
;; Call `filtered-candidate-transformer' functions even if process sources
;;
;; Revision 1.269  2010/03/29 08:42:23  rubikitch
;; * New attribute `resume'
;; * Fix a bug of `disable-shortcuts' plug-in
;;
;; Revision 1.268  2010/03/28 21:42:01  rubikitch
;; Add some keys in `anything-help'
;;
;; Revision 1.267  2010/03/28 20:11:30  rubikitch
;; Modify `anything-mode-line-string'
;;
;; Revision 1.266  2010/03/28 06:12:43  rubikitch
;; process source and multiline: in the making (not usable)
;;
;; Revision 1.265  2010/03/28 05:07:00  rubikitch
;; Change default `anything-sources'. It is only a sample, no problem.
;;
;; Revision 1.264  2010/03/27 19:02:52  rubikitch
;; New attributes: `mode-line' and `header-line'
;;
;; Revision 1.263  2010/03/27 02:34:40  rubikitch
;; doc
;;
;; Revision 1.262  2010/03/27 02:31:55  rubikitch
;; New command: `anything-force-update' C-c C-u
;;
;; Revision 1.261  2010/03/27 02:29:39  rubikitch
;; New function `anything-goto-source'
;;
;; Revision 1.260  2010/03/27 02:01:28  rubikitch
;; reimplement move selection commands
;;
;; Revision 1.259  2010/03/26 22:52:15  rubikitch
;; `anything-quit-and-find-file':
;;   If current selection is a buffer or a file, `find-file' from its directory.
;;   Idea from http://i-yt.info/?date=20090826#p01 with some modification. Thanks.
;;
;; Revision 1.258  2010/03/26 12:10:55  rubikitch
;; * modify `anything-mode-line-string'
;; * New command `anything-help'
;;
;; Revision 1.257  2010/03/24 11:08:19  rubikitch
;; revert to 1.255
;;
;; Revision 1.256  2010/03/24 08:29:43  rubikitch
;; `anything-check-minibuffer-input' set repeat timer.
;;
;; Revision 1.255  2010/03/24 02:35:47  rubikitch
;; `anything-candidate-number-limit':
;; When (candidate-number-limit) is specified in SOURCE,
;; cancel the effect of `anything-candidate-number-limit'.
;;
;; Revision 1.254  2010/03/23 00:33:18  rubikitch
;; New API: `anything-interpret-value'
;;
;; Revision 1.253  2010/03/22 07:04:03  rubikitch
;; `anything-get-current-source': return nil when no candidates rather than error
;;
;; Revision 1.252  2010/03/21 06:08:44  rubikitch
;; Mark bug fix. thx hchbaw!
;; http://d.hatena.ne.jp/hchbaw/20100226/1267200447
;;
;; Revision 1.251  2010/03/21 02:39:34  rubikitch
;; Fix a wrong usage of `delq'. thx hchbaw.
;; http://d.hatena.ne.jp/hchbaw/20100226/1267200447
;;
;; Revision 1.250  2010/03/21 02:32:29  rubikitch
;; Fix `select deleted buffer' error message when calling `anything-resume'.
;;
;; It was occurred when killing `anything-current-buffer' and calling `anything-resume'.
;;
;; Revision 1.249  2010/02/23 20:43:35  rubikitch
;; `anything-update': Ensure to call `anything-next-line'
;;
;; Revision 1.248  2010/02/20 12:34:38  rubikitch
;; Mode-line help!! `anything-mode-line-string' is help string.
;;
;; Revision 1.247  2010/02/20 10:41:39  rubikitch
;; Automatically update `anything-version' when upgrading
;;
;; Revision 1.246  2010/02/20 10:38:58  rubikitch
;; update copyright
;;
;; Revision 1.245  2010/02/20 10:36:01  rubikitch
;; New API: `anything-require-at-least-version'
;;
;; Revision 1.244  2010/02/20 10:06:54  rubikitch
;; * New plug-in: `disable-shortcuts'
;; * `dummy' plug-in implies `disable-shortcuts' because it enables us to input capital letters.
;;
;; Revision 1.243  2010/02/20 09:54:16  rubikitch
;; `anything-compile-source--dummy': swap arguments of `append'
;;
;; Revision 1.242  2010/02/19 17:37:12  rubikitch
;; error check in `anything-set-source-filter'
;;
;; Revision 1.241  2010/01/29 18:53:17  rubikitch
;; Fix a bug of `candidate-number-limit' in process sources.
;;
;; Revision 1.240  2010/01/23 04:21:31  rubikitch
;; * `anything': Use `anything-display-buffer' as fallback
;; * `anything-select-with-digit-shortcut': `self-insert-command' if disabled
;;
;; Revision 1.239  2009/12/28 07:33:28  rubikitch
;; New command: `anything-toggle-resplit-window'  (C-t)
;;
;; Revision 1.238  2009/12/28 07:19:37  rubikitch
;; bugfix
;;
;; Revision 1.237  2009/12/28 07:15:30  rubikitch
;; `anything-window-configuration' stores window configuration only.
;;
;; Revision 1.236  2009/12/28 07:07:09  rubikitch
;; `anything-resume' resumes window configuration now.
;;
;; Revision 1.235  2009/12/28 04:12:33  rubikitch
;; Fix tiny bug
;;
;; Revision 1.234  2009/12/28 03:57:33  rubikitch
;; `anything-resume': New optional argument
;;
;; Revision 1.233  2009/12/28 03:43:12  rubikitch
;; remove warnings
;;
;; Revision 1.232  2009/12/28 03:37:25  rubikitch
;; refactoring
;;
;; Revision 1.231  2009/12/28 02:33:41  rubikitch
;; refactoring
;;
;; Revision 1.230  2009/12/27 09:28:06  rubikitch
;; `anything-window-configuration' save/restore anything window configuration (NOT YET)
;;
;; Revision 1.229  2009/12/26 21:41:33  rubikitch
;; revive `anything-input' when resuming
;;
;; Revision 1.228  2009/12/25 01:34:35  rubikitch
;; * `anything-resume' use anything interface to select anything buffers.
;; * Its candidates are sorted by most recently used order.
;; * 4th arg of `anything' accepts 'noresume not to resume this session.
;;
;; Revision 1.227  2009/12/19 20:30:12  rubikitch
;; add `pattern-transformer' doc
;;
;; Revision 1.226  2009/12/19 20:15:47  rubikitch
;; pattern-transformer can have multiple functions now
;;
;; Revision 1.225  2009/12/19 20:11:16  rubikitch
;; add `delayed-init' doc
;;
;; Revision 1.224  2009/12/19 12:26:00  rubikitch
;; New attribute `pattern-transformer'
;;
;; Revision 1.223  2009/12/19 11:57:41  rubikitch
;; New attribute `delayed-init'
;;
;; Revision 1.222  2009/12/14 20:55:23  rubikitch
;; Fix display bug: `anything-enable-digit-shortcuts' / multiline
;;
;; Revision 1.221  2009/12/14 20:29:49  rubikitch
;; fix an error when executing `anything-prev-visible-mark' with no visible marks.
;;
;; Revision 1.220  2009/12/14 20:19:05  rubikitch
;; Bugfix about anything-execute-action-at-once-if-one and multiline
;;
;; Revision 1.219  2009/12/14 03:21:11  rubikitch
;; Extend alphabet shortcuts to A-Z
;;
;; Revision 1.218  2009/12/13 01:03:34  rubikitch
;; Changed data structure of `anything-shortcut-keys-alist'
;;
;; Revision 1.217  2009/12/03 23:16:17  rubikitch
;; silence warning
;;
;; Revision 1.216  2009/12/03 20:43:51  rubikitch
;; Add keybindings for alphabet shortcuts
;;
;; Revision 1.215  2009/12/03 20:37:13  rubikitch
;; `anything-enable-shortcuts' is an alias of `anything-enable-digit-shortcuts'.
;; Alphabet shortcuts can be used now.
;;
;; Revision 1.214  2009/12/03 20:23:40  rubikitch
;; `anything-enable-digit-shortcuts' also accepts 'alphabet.
;;
;; Now alphabet shortcuts are usable.
;;
;; Revision 1.213  2009/12/03 09:59:58  rubikitch
;; refactoring
;;
;; Revision 1.212  2009/11/15 09:42:15  rubikitch
;; refactoring
;;
;; Revision 1.211  2009/11/06 21:42:58  rubikitch
;; New command: `anything-beginning-of-buffer', `anything-end-of-buffer'
;;
;; Revision 1.210  2009/10/22 13:30:06  rubikitch
;; `real-to-display' function is evaluated just after `candidate-transformer' function now.
;; This enables us to narrow candidates by display string by `real-to-display'.
;;
;; Revision 1.209  2009/10/21 20:25:10  rubikitch
;; Add a document. (no code change)
;;
;; Revision 1.208  2009/10/21 11:31:15  rubikitch
;; `anything': accept one source alist
;;
;; Revision 1.207  2009/10/16 19:47:39  rubikitch
;; Link to Japanese translation of `anything-sources' attributes. (No code change)
;;
;; Revision 1.206  2009/10/10 09:28:54  rubikitch
;; Remove an unnecessary test
;;
;; Revision 1.205  2009/10/10 06:21:28  rubikitch
;; obsolete: `anything-c-marked-candidate-list'
;; New function: `anything-marked-candidates'
;;
;; Revision 1.204  2009/10/06 21:01:12  rubikitch
;; Call `anything-process-delayed-sources' only if delayed-sources is available.
;;
;; Revision 1.203  2009/10/02 10:04:07  rubikitch
;; Tested on Emacs23 too. (no code change)
;;
;; Revision 1.202  2009/10/02 10:03:34  rubikitch
;; * Display "no candidates" rather than assertion
;; * Ensure to call `remove-hook' in `anything-current-buffer'
;;
;; Revision 1.201  2009/08/08 13:25:30  rubikitch
;; `anything-toggle-visible-mark': move next line after unmarking
;;
;; Revision 1.200  2009/08/08 13:23:46  rubikitch
;; `anything-toggle-visible-mark': Applied ThierryVolpiatto's patch. thx.
;;
;; Revision 1.199  2009/07/19 13:22:29  rubikitch
;; `anything-follow-execute-persistent-action-maybe': execute persistent action after `anything-input-idle-delay'
;;
;; Revision 1.198  2009/07/06 15:22:48  rubikitch
;; header modified (no code change)
;;
;; Revision 1.197  2009/06/29 15:10:13  rubikitch
;; OOPS! remove debug code
;;
;; Revision 1.196  2009/06/29 13:29:25  rubikitch
;; anything-follow-mode: automatical execution of persistent-action (C-c C-f)
;;
;; Revision 1.195  2009/06/19 14:42:57  rubikitch
;; silence byte compiler
;;
;; Revision 1.194  2009/06/14 15:12:34  rubikitch
;; typo
;;
;; Revision 1.193  2009/06/08 19:37:12  rubikitch
;; typo!
;;
;; Revision 1.192  2009/06/08 19:36:39  rubikitch
;; New keybind: C-e, C-j, C-k
;;
;; Revision 1.191  2009/06/08 19:30:27  rubikitch
;; New command: `anything-select-2nd-action-or-end-of-line'
;;
;; Revision 1.190  2009/06/07 17:09:50  rubikitch
;; add M-<next>, C-M-S-v, M-<prior> to `anything-map'.
;;
;; Revision 1.189  2009/06/01 21:36:31  rubikitch
;; New function: `anything-other-buffer'
;;
;; Revision 1.188  2009/05/29 18:33:07  rubikitch
;; avoid error when executing (anything-mark-current-line) in async process.
;;
;; Revision 1.187  2009/05/29 06:49:05  rubikitch
;; small refactoring
;;
;; Revision 1.186  2009/05/29 06:46:34  rubikitch
;; Prevent `anything-isearch-map' from overwriting `global-map'. With
;; `copy-keymap', the prefix command "M-s" in `global-map' ends up
;; getting clobbered by `anything-isearch-again', preventing `occur'
;; (among other things) from running. This change replaces overwriting a
;; copied map with writing to a sparse map whose parent is `global-map'.
;;
;; patched by DanielHackney. thanks!
;;
;; Revision 1.185  2009/05/25 19:07:42  rubikitch
;; `anything': set `case-fold-search' to t
;; Because users can assign commands to capital letter keys.
;;
;; Revision 1.184  2009/05/25 19:05:04  rubikitch
;; Added auto-document
;;
;; Revision 1.183  2009/05/15 01:50:46  rubikitch
;; typo
;;
;; Revision 1.182  2009/05/08 18:28:18  rubikitch
;; Bug fix: `anything-attr' is usable in `header-name' function.
;;
;; Revision 1.181  2009/05/04 19:05:03  rubikitch
;; * `anything-yank-selection' and `anything-kill-selection-and-quit' handles display string now.
;; * `anything-get-selection': Added optional arguments.
;;
;; Revision 1.180  2009/05/03 19:03:34  rubikitch
;; Add `anything-input' to `minibuffer-history' even if `anything' is quit.
;;
;; Revision 1.179  2009/04/20 16:35:44  rubikitch
;; New keybindings in anything-map:
;;   C-c C-d: `anything-delete-current-selection'
;;   C-c C-y: `anything-yank-selection'
;;   C-c C-k: `anything-kill-selection-and-quit'
;;
;; Revision 1.178  2009/04/20 16:18:58  rubikitch
;; New variable: `anything-display-function'
;;
;; Revision 1.177  2009/04/20 02:17:16  rubikitch
;; New commands: `anything-yank-selection', `anything-kill-selection-and-quit'
;;
;; Revision 1.176  2009/04/08 14:48:15  rubikitch
;; bug fix in `anything-candidate-buffer'
;;
;; Revision 1.175  2009/03/22 19:10:37  rubikitch
;; New Variable: `anything-scroll-amount' (thx. ThierryVolpiatto)
;;
;; Revision 1.174  2009/03/12 19:12:24  rubikitch
;; New API: `define-anything-type-attribute'
;;
;; Revision 1.173  2009/03/11 08:10:32  rubikitch
;; Update doc
;;
;; Revision 1.172  2009/03/10 17:11:58  rubikitch
;; `candidate-transformer', `filtered-candidate-transformer',
;; `action-transformer' attributes: accept a list of functions
;;
;; Revision 1.171  2009/03/09 18:49:44  rubikitch
;; New command: `anything-quit-and-find-file'
;;
;; Revision 1.170  2009/03/09 18:46:11  rubikitch
;; New API: `anything-run-after-quit'
;;
;; Revision 1.169  2009/03/09 10:02:49  rubikitch
;; Set candidate-number-limit attribute for actions.
;;
;; Revision 1.168  2009/03/07 21:01:10  rubikitch
;; Bug workaround
;;
;; Revision 1.167  2009/03/06 04:13:42  rubikitch
;; Fix doc
;;
;; Revision 1.166  2009/03/03 10:35:57  rubikitch
;; Set default `anything-input-idle-delay' to 0.1
;;
;; Revision 1.165  2009/03/03 07:14:42  rubikitch
;; Make sure to run `anything-update-hook' after processing delayed sources.
;;
;; Revision 1.164  2009/03/02 01:51:40  rubikitch
;; better error handling.
;;
;; Revision 1.163  2009/03/01 05:15:00  rubikitch
;; anything-iswitchb and anything-isearch are marked as unmaintained.
;; (document change only)
;;
;; Revision 1.162  2009/02/28 01:24:13  rubikitch
;; Symbols are now acceptable as candidate.
;;
;; Revision 1.161  2009/02/27 07:18:46  rubikitch
;; Fix bug of `anything-scroll-other-window' and `anything-scroll-other-window-down'.
;;
;; Revision 1.160  2009/02/27 01:05:06  rubikitch
;; * Make sure to restore point after running `anything-update-hook'.
;; * Make `anything-compute-matches' easy to find error.
;;
;; Revision 1.159  2009/02/26 23:45:48  rubikitch
;; * Check whether candidate is a string, otherwise ignore.
;;
;; Revision 1.158  2009/02/24 06:39:20  rubikitch
;; suppress compile warnings.
;;
;; Revision 1.157  2009/02/23 22:51:43  rubikitch
;; New function: `anything-document-attribute'
;;
;; Revision 1.156  2009/02/23 21:36:09  rubikitch
;; New Variable: `anything-display-source-at-screen-top'
;;
;; Revision 1.155  2009/02/23 21:30:52  rubikitch
;; New command: `anything-at-point'
;;
;; Revision 1.154  2009/02/23 08:57:54  rubikitch
;; Visible Mark
;;
;; Revision 1.153  2009/02/23 08:38:57  rubikitch
;; update doc
;;
;; Revision 1.152  2009/02/23 08:32:17  rubikitch
;; More key bindings.
;;
;; Revision 1.151  2009/02/23 08:21:24  rubikitch
;; `anything-map' is now Emacs-standard key bindings by default.
;; After evaluating `anything-iswitchb-setup'. some key bindings are adjusted to iswitchb.
;;
;; Revision 1.150  2009/02/20 22:58:18  rubikitch
;; Cancel timer in `anything-cleanup'.
;;
;; Revision 1.149  2009/02/20 12:23:44  rubikitch
;; `anything-header' face now inherits header-line (not a copy).
;;
;; Revision 1.148  2009/02/16 23:40:22  rubikitch
;; `real-to-display' attribute bug fix.
;;
;; Revision 1.147  2009/02/02 20:51:41  rubikitch
;; New `anything-sources' attribute: real-to-display
;;
;; Revision 1.146  2009/02/01 20:01:00  rubikitch
;; Update Tips
;;
;; Revision 1.145  2009/02/01 19:45:53  rubikitch
;; New variable: `anything-quit-if-no-candidate'
;;
;; Revision 1.144  2009/02/01 19:31:47  rubikitch
;; fixed a typo
;;
;; Revision 1.143  2009/02/01 19:23:32  rubikitch
;; New variable: `anything-execute-action-at-once-if-one'
;;
;; Revision 1.142  2009/02/01 19:12:34  rubikitch
;; `anything-persistent-action-display-buffer': bug fix
;;
;; Revision 1.141  2009/02/01 18:25:25  rubikitch
;; * fix docstring
;; * New variable: `anything-selection-face'
;;
;; Revision 1.140  2009/01/16 16:36:25  rubikitch
;; New variable: `anything-persistent-action-use-special-display'.
;;
;; Revision 1.139  2009/01/05 20:15:53  rubikitch
;; Fixed a bug of anything action buffer.
;; The action source should not be cached.
;;
;; Revision 1.138  2008/12/21 16:56:05  rubikitch
;; Fixed an error when action attribute is a function symbol and press TAB,
;;
;; Revision 1.137  2008/12/20 19:38:47  rubikitch
;; `anything-check-minibuffer-input-1': proper quit handling
;; `anything-process-delayed-sources': ditto
;;
;; Revision 1.136  2008/10/27 17:41:27  rubikitch
;; `anything-process-delayed-sources', `anything-check-minibuffer-input-1': quittable
;;
;; Revision 1.135  2008/10/27 17:04:25  rubikitch
;; arranged source, added more linkd tags (no code change)
;;
;; Revision 1.134  2008/10/27 15:02:25  rubikitch
;; New variable: `anything-save-configuration-functions'
;; Delete variable: `anything-save-configuration-type'
;;
;; Revision 1.133  2008/10/27 11:16:13  rubikitch
;; New variable: `anything-save-configuration-type'
;;
;; Revision 1.132  2008/10/26 22:34:59  rubikitch
;; `anything-delete-current-selection' with multiline
;;
;; Revision 1.131  2008/10/26 21:44:43  rubikitch
;; New command: `anything-delete-current-selection'
;;
;; Revision 1.130  2008/10/22 10:41:09  rubikitch
;; `anything-insert-match': do not override 'anything-realvalue property
;;
;; Revision 1.129  2008/10/21 17:01:37  rubikitch
;; `anything-resume' per buffer.
;; `anything-last-sources': obsolete
;;
;; Revision 1.128  2008/10/20 06:27:54  rubikitch
;; `anything-quick-update': new user option
;;
;; Revision 1.127  2008/10/20 05:47:49  rubikitch
;; refactoring
;;
;; Revision 1.126  2008/10/20 03:47:58  rubikitch
;; `anything-update': reversed order of delayed sources
;;
;; Revision 1.125  2008/10/19 00:29:54  rubikitch
;; kill buffer-local candidate buffers when creating global candidate buffers.
;;
;; Revision 1.124  2008/10/18 13:04:20  rubikitch
;; Remove tick entry from `anything-tick-hash' when killing a buffer.
;;
;; Revision 1.123  2008/10/18 10:23:36  rubikitch
;; multiline patch by Tomohiro MATSUYAMA.
;;
;; Revision 1.122  2008/10/13 03:10:07  rubikitch
;; `anything': do `anything-mark-current-line' when resuming
;;
;; Revision 1.121  2008/10/13 03:08:08  rubikitch
;; always set `anything-current-position'
;;
;; Revision 1.120  2008/10/07 14:12:02  rubikitch
;; `anything-execute-persistent-action': optional arg
;;
;; Revision 1.119  2008/10/06 06:43:29  rubikitch
;; `anything-candidate-buffer': return nil when the buffer is dead
;;
;; Revision 1.118  2008/09/30 22:21:28  rubikitch
;; New `anything-sources' attribute: accept-empty
;; dummy: include accept-empty
;;
;; Revision 1.117  2008/09/30 21:59:10  rubikitch
;; New function: `anything-buffer-is-modified'
;;
;; Revision 1.116  2008/09/22 11:27:29  rubikitch
;; *** empty log message ***
;;
;; Revision 1.115  2008/09/20 20:21:11  rubikitch
;; added linkd index. (no code change)
;;
;; Revision 1.114  2008/09/20 20:09:57  rubikitch
;; INCOMPATIBLE CHANGES: `anything-attr'
;; New functions: `anything-attrset', `anything-attr-defined'
;;
;; Revision 1.113  2008/09/14 15:15:32  rubikitch
;; bugfix: volatile and match attribute / process and match attribute
;;
;; Revision 1.112  2008/09/12 01:57:17  rubikitch
;; When resuming anything, reinitialize overlays.
;;
;; Revision 1.111  2008/09/10 22:53:11  rubikitch
;; anything: bug fix of `anything-buffer'
;; New macro: `anything-test-update'
;;
;; Revision 1.110  2008/09/10 22:17:11  rubikitch
;; New `anything-sources' attribute: header-name
;;
;; Revision 1.109  2008/09/10 21:12:26  rubikitch
;; New hook: `anything-after-action-hook'
;;
;; Revision 1.108  2008/09/06 06:07:56  rubikitch
;; Extended `anything-set-sources' optional arguments.
;;
;; Revision 1.107  2008/09/05 03:14:35  rubikitch
;; reimplement `anything-current-buffer-is-modified' in the right way
;;
;; Revision 1.106  2008/09/05 00:11:05  rubikitch
;; Moved `anything-read-string-mode' and read functions to anything-complete.el.
;;
;; Revision 1.105  2008/09/04 12:45:06  rubikitch
;; New hook: `anything-after-persistent-action-hook'
;;
;; Revision 1.104  2008/09/04 12:27:05  rubikitch
;; `anything': prefixed optional arguments
;;
;; Revision 1.103  2008/09/04 09:16:28  rubikitch
;; fixed a bug of `anything-read-file-name'.
;;
;; Revision 1.102  2008/09/03 11:25:19  rubikitch
;; Extended `anything' optional arguments: buffer
;;
;; Revision 1.101  2008/09/03 11:15:13  rubikitch
;; `anything': return nil when keybord-quitted
;;
;; Revision 1.100  2008/09/01 23:11:02  rubikitch
;; bug fix of search-from-end
;;
;; Revision 1.99  2008/09/01 13:45:55  rubikitch
;; bug fix of search-from-end
;;
;; Revision 1.98  2008/09/01 11:23:38  rubikitch
;; New `anything-sources' attribute: search-from-end
;;
;; Revision 1.97  2008/09/01 00:44:34  rubikitch
;; Make sure to display the other window when persistent action.
;;
;; Revision 1.96  2008/08/31 20:55:20  rubikitch
;; define `buffer-modified-tick' for older emacs.
;;
;; Revision 1.95  2008/08/30 04:55:51  rubikitch
;; fixed a bug of `anything-completing-read'
;;
;; Revision 1.94  2008/08/28 20:18:03  rubikitch
;; added some tests
;;
;; Revision 1.93  2008/08/25 20:18:46  rubikitch
;; `anything': set `anything-input' and `anything-pattern' before `anything-update'
;;
;; Revision 1.92  2008/08/24 22:38:46  rubikitch
;; *** empty log message ***
;;
;; Revision 1.91  2008/08/24 21:34:35  rubikitch
;; rewrite `with-anything-restore-variables'
;;
;; Revision 1.90  2008/08/24 20:33:02  rubikitch
;; prevent the unit test from byte-compiled.
;; macro bug fix.
;;
;; Revision 1.89  2008/08/24 08:35:27  rubikitch
;; *** empty log message ***
;;
;; Revision 1.88  2008/08/24 08:22:19  rubikitch
;; Rename `anything-candidates-buffer' -> `anything-candidate-buffer'
;;
;; Revision 1.87  2008/08/23 22:27:04  rubikitch
;; New hook: `anything-cleanup-hook'
;;
;; Revision 1.86  2008/08/23 22:05:42  rubikitch
;; `anything-original-source-filter' is removed.
;; Now use `anything-restored-variables' and `with-anything-restore-variables'.
;;
;; Revision 1.85  2008/08/23 21:23:21  rubikitch
;; inhibit-read-only = t in anything-buffer
;;
;; Revision 1.84  2008/08/23 21:18:33  rubikitch
;; *** empty log message ***
;;
;; Revision 1.83  2008/08/23 20:44:20  rubikitch
;; `anything-execute-persistent-action': display-to-real bug fix
;;
;; Revision 1.82  2008/08/23 20:19:12  rubikitch
;; New `anything-sources' attribute: get-line
;;
;; Revision 1.81  2008/08/23 19:32:14  rubikitch
;; `anything-attr': Return t in (attribute-name) case.
;;
;; Revision 1.80  2008/08/22 21:25:05  rubikitch
;; anything-candidates-in-buffer-1:
;; Open a line at the BOB to make use of `search-forward' for faster exact/prefix match.
;; Of course, restore the buffer contents after search.
;;
;; Revision 1.79  2008/08/22 17:11:00  rubikitch
;; New hook: `anything-before-initialize-hook', `anything-after-initialize-hook'
;;
;; Revision 1.78  2008/08/21 18:37:03  rubikitch
;; Implemented dummy sources as plug-in.
;;
;; Revision 1.77  2008/08/21 17:40:40  rubikitch
;; New function: `anything-set-sources'
;;
;; Revision 1.76  2008/08/21 12:25:02  rubikitch
;; New variable: `anything-version'
;;
;; Revision 1.75  2008/08/21 12:13:46  rubikitch
;; New variable: `anything-in-persistent-action'
;;
;; Revision 1.74  2008/08/21 10:34:22  rubikitch
;; New function `anything-mklist'
;;
;; Revision 1.73  2008/08/21 09:41:38  rubikitch
;; accept multiple init/cleanup functions so that plug-ins can add new function.
;;
;; Revision 1.72  2008/08/20 22:51:53  rubikitch
;; New `anything-sources' attribute: candidate-number-limit
;;
;; Revision 1.71  2008/08/20 21:45:42  rubikitch
;; added many tests.
;;
;; Revision 1.70  2008/08/20 18:51:45  rubikitch
;; `anything-preselect' bug fix.
;; refactoring.
;;
;; Revision 1.69  2008/08/20 17:57:51  rubikitch
;; Extended `anything' optional arguments: preselect
;;
;; Revision 1.68  2008/08/20 16:39:07  rubikitch
;; Nested `anything' invocation support, ie. `anything' can be invoked by anything action.
;;
;; (anything '(((name . "nested anything invocation test")
;;              (candidates "anything-c-source-buffers" "anything-c-source-man-pages")
;;              (display-to-real . intern)
;;              (action . anything))))
;;
;; Revision 1.67  2008/08/20 00:08:28  rubikitch
;; `anything-candidates-in-buffer-1': add code when pattern == ""
;;
;; Revision 1.66  2008/08/19 23:31:52  rubikitch
;; Removed `anything-show-exact-match-first' because it should be provided as a plug-in.
;;
;; Revision 1.65  2008/08/19 23:18:47  rubikitch
;; *** empty log message ***
;;
;; Revision 1.64  2008/08/19 23:15:43  rubikitch
;; `anything-compute-matches': short-cut when match == '(identity)
;;
;; Revision 1.63  2008/08/19 23:06:42  rubikitch
;; Use hash table to speed uniquify candidates.
;;
;; Revision 1.62  2008/08/19 22:40:57  rubikitch
;; `anything-test-candidates': additional optonal argument
;;
;; Revision 1.61  2008/08/19 18:13:39  rubikitch
;; search attribute: multiple search functions
;;
;; Revision 1.60  2008/08/19 15:07:39  rubikitch
;; New function: `anything-attr'
;;
;; Revision 1.59  2008/08/19 15:01:59  rubikitch
;; arranged code
;; added unit tests
;; update doc
;;
;; Revision 1.58  2008/08/19 13:40:52  rubikitch
;; `anything-get-current-source': This function can be used in
;;  init/candidates/action/candidate-transformer/filtered-candidate-transformer
;;  display-to-real/cleanup function.
;;
;; Revision 1.57  2008/08/19 03:43:57  rubikitch
;; `anything-process-delayed-sources': delay = anything-idle-delay - anything-input-idle-delay
;;
;; Revision 1.56  2008/08/18 06:37:51  rubikitch
;; Make `anything-input-idle-delay' ineffective when the action list is shown.
;;
;; Revision 1.55  2008/08/18 06:35:00  rubikitch
;; New variable: `anything-show-exact-match-first'
;;
;; Revision 1.54  2008/08/17 23:22:24  rubikitch
;; *** empty log message ***
;;
;; Revision 1.53  2008/08/17 23:15:38  rubikitch
;; bind `anything-source-name' when executing action to enable to use `anything-candidate-buffer' in action.
;;
;; Revision 1.52  2008/08/17 15:21:27  rubikitch
;; `anything-test-candidates': accept a symbol for source
;; New variable: `anything-input-idle-delay'
;;
;; Revision 1.51  2008/08/17 12:45:30  rubikitch
;; (buffer-disable-undo) in anything-buffer
;;
;; Revision 1.50  2008/08/16 22:21:37  rubikitch
;; `anything-saved-sources': removed
;; `anything-action-buffer': action selection buffer
;; `anything-select-action': toggle actions <=> candidates
;;
;; Revision 1.49  2008/08/16 19:46:11  rubikitch
;; New function: `anything-action-list-is-shown'
;;
;; Revision 1.48  2008/08/16 17:03:02  rubikitch
;; bugfix: cleanup
;;
;; Revision 1.47  2008/08/16 16:35:24  rubikitch
;; silence byte compiler
;;
;; Revision 1.46  2008/08/16 14:51:27  rubikitch
;; *** empty log message ***
;;
;; Revision 1.45  2008/08/16 11:27:59  rubikitch
;; refactoring
;;  `anything-aif': Anaphoric if.
;;  `anything-compile-source-functions': make `anything-get-sources' customizable.
;;
;; Revision 1.44  2008/08/16 09:38:15  rubikitch
;; *** empty log message ***
;;
;; Revision 1.43  2008/08/15 11:44:28  rubikitch
;; `anything-read-string-mode': minor mode for `anything' version of read functions. (experimental)
;;
;; Revision 1.42  2008/08/15 11:03:20  rubikitch
;; update docs
;;
;; Revision 1.41  2008/08/14 20:51:28  rubikitch
;; New `anything-sources' attribute: cleanup
;;
;; Revision 1.40  2008/08/14 10:34:04  rubikitch
;; `anything': SOURCES: accept symbols
;;
;; Revision 1.39  2008/08/10 22:46:01  rubikitch
;; `anything-move-selection': avoid infinite loop
;;
;; Revision 1.38  2008/08/09 21:38:25  rubikitch
;; `anything-read-file-name': experimental implementation.
;;
;; Revision 1.37  2008/08/09 17:54:25  rubikitch
;; action test
;;
;; Revision 1.36  2008/08/09 17:13:00  rubikitch
;; fixed test
;;
;; Revision 1.35  2008/08/09 10:43:08  rubikitch
;; New `anything-sources' attribute: display-to-real
;;
;; Revision 1.34  2008/08/07 13:15:44  rubikitch
;; New `anything-sources' attribute: search
;;
;; Revision 1.33  2008/08/05 23:14:20  rubikitch
;; `anything-candidate-buffer': bugfix
;;
;; Revision 1.32  2008/08/05 21:42:15  rubikitch
;; *** empty log message ***
;;
;; Revision 1.31  2008/08/05 21:06:23  rubikitch
;; `anything-candidate-buffer': candidates buffer registration
;;
;; Revision 1.30  2008/08/05 19:46:36  rubikitch
;; New `anything-sources' attribute: candidates-in-buffer
;;
;; Revision 1.29  2008/08/05 17:58:31  rubikitch
;; *** empty log message ***
;;
;; Revision 1.28  2008/08/05 17:46:04  rubikitch
;; memoized `anything-get-sources'
;;
;; Revision 1.27  2008/08/05 17:29:40  rubikitch
;; update doc
;;
;; Revision 1.26  2008/08/05 08:35:45  rubikitch
;; `anything-completing-read': accept obarray
;;
;; Revision 1.25  2008/08/05 07:26:17  rubikitch
;; `anything-completing-read': guard from non-string return value
;;
;; Revision 1.24  2008/08/04 12:05:41  rubikitch
;; Wrote Tips and some docstrings.
;; `anything-candidate-buffer': buffer-local by default
;;
;; Revision 1.23  2008/08/04 05:29:46  rubikitch
;; `anything-buffer-file-name': `buffer-file-name' when `anything' is invoked.
;;
;; Revision 1.22  2008/08/04 00:10:13  rubikitch
;; `anything-candidate-buffer': new API
;;
;; Revision 1.21  2008/08/03 22:05:08  rubikitch
;; `anything-candidate-buffer': Return a buffer containing candidates of current source.
;;
;; Revision 1.20  2008/08/03 20:47:56  rubikitch
;; `anything-current-buffer-is-modified': modify checker
;;
;; Revision 1.19  2008/08/03 19:06:18  rubikitch
;; `anything-candidates-in-buffer': use `with-current-buffer' instead.
;;
;; Revision 1.18  2008/08/03 05:55:01  rubikitch
;; `anything-candidates-in-buffer': extract candidates in a buffer for speed.
;;
;; Revision 1.17  2008/08/02 21:31:29  rubikitch
;; Extended `anything' optional arguments.
;; `anything-completing-read': experimental implementation.
;;
;; Revision 1.16  2008/08/02 20:32:54  rubikitch
;; Extended `anything' optional arguments.
;;
;; Revision 1.15  2008/08/02 16:53:40  rubikitch
;; Fixed a small bug of `anything-test-candidates'.
;;
;; Revision 1.14  2008/08/02 16:48:29  rubikitch
;; Refactored to testable code.
;; Added many candidate tests with `anything-test-candidates'.
;;
;; Revision 1.13  2008/08/02 15:08:14  rubikitch
;; *** empty log message ***
;;
;; Revision 1.12  2008/08/02 14:29:31  rubikitch
;; `anything-sources' accepts symbols. (patched by Sugawara)
;;
;; Revision 1.11  2008/08/02 10:20:36  rubikitch
;; `anything-resume' is usable with other (let-binded) `anything-sources'.
;;
;; Revision 1.10  2008/08/01 19:44:01  rubikitch
;; `anything-resume': resurrect previously invoked `anything'.
;;
;; Revision 1.9  2008/07/30 15:44:49  rubikitch
;; *** empty log message ***
;;
;; Revision 1.8  2008/07/30 15:38:51  rubikitch
;; *** empty log message ***
;;
;; Revision 1.7  2008/07/30 15:21:48  rubikitch
;; `anything-scroll-other-window', `anything-scroll-other-window-down':
;; Scroll other window (for persistent action).
;;
;; Revision 1.6  2008/07/30 15:12:36  rubikitch
;; *** empty log message ***
;;
;; Revision 1.5  2008/07/30 15:06:32  rubikitch
;; `anything-select-2nd-action', `anything-select-3rd-action', `anything-select-4th-action':
;; Select other than default action without pressing Tab.
;;
;; Revision 1.4  2008/07/30 14:58:27  rubikitch
;; `anything-current-buffer': Store current buffer when `anything' is invoked.
;; `anything-current-position': Restore position when keyboard-quitted.
;;
;; Revision 1.3  2008/07/30 14:38:04  rubikitch
;; Implemented persistent action.
;;
;; Revision 1.2  2008/07/30 13:37:16  rubikitch
;; Update doc.
;;
;; Revision 1.1  2008/07/30 13:22:06  rubikitch
;; New maintainer.
;;

;; ugly hack to auto-update version
(defvar anything-version nil)
(setq anything-version "$Id: anything.el,v 1.280 2010-04-01 02:22:22 rubikitch Exp $")
(require 'cl)
;; (require 'anything-match-plugin nil t)

;; (@* "User Configuration")

;; This is only an example. Customize it to your own taste!
(defvar anything-sources `(((name . "Buffers")
                            (candidates
                             . (lambda ()
                                 (remove-if (lambda (name)
                                              (or (equal name anything-buffer)
                                                  (eq ?\  (aref name 0))))
                                            (mapcar 'buffer-name (buffer-list)))))
			    (type . buffer))

                           ((name . "File Name History")
                            (candidates . file-name-history)
                            (match (lambda (candidate)
                                     ;; list basename matches first
                                     (string-match 
                                      anything-pattern 
                                      (file-name-nondirectory candidate)))

                                   (lambda (candidate)                                     
                                     ;; and then directory part matches
                                     (let ((dir (file-name-directory candidate)))
                                       (if dir
                                           (string-match anything-pattern dir)))))
                            (type . file))

                           ((name . "Files from Current Directory")
                            (init . (lambda ()
                                      (setq anything-default-directory
                                            default-directory)))
                            (candidates . (lambda ()
                                            (directory-files
                                             anything-default-directory)))
                            (type . file))

                           ((name . "Complex Command History")
                            (candidates . (lambda ()
                                            (mapcar 'prin1-to-string
                                                    command-history)))
                            (action . (("Repeat Complex Command" . 
                                        (lambda (c)
                                          (eval (read c))))))
                            (delayed)))
  "The source of candidates for anything.
It accepts symbols:
 (setq anything-sources (list anything-c-foo anything-c-bar))
can be written as
 (setq anything-sources '(anything-c-foo anything-c-bar))
The latter is recommended because if you change anything-c-* variable,
you do not have to update `anything-sources'.

You are STRONGLY recommended to define a command which calls
`anything' or `anything-other-buffer' with argument rather than
to set `anything-sources' externally.

If you want to change `anything-sources' during `anything' invocation,
use `anything-set-sources', never use `setq'.

Attributes:

")


;; This value is only provided as an example. Customize it to your own
;; taste!
(defvar anything-type-attributes
  '((file (action . (("Find File" . find-file)
                     ("Delete File" . (lambda (file)
                                        (if (y-or-n-p (format "Really delete file %s? "
                                                              file))
                                            (delete-file file)))))))
    (buffer (action . (("Switch to Buffer" . switch-to-buffer)
                       ("Pop to Buffer"    . pop-to-buffer)
                       ("Display Buffer"   . display-buffer)
                       ("Kill Buffer"      . kill-buffer)))))
  "It's a list of (TYPE ATTRIBUTES ...). ATTRIBUTES are the same
  as attributes for `anything-sources'. TYPE connects the value
  to the appropriate sources in `anything-sources'.

  This allows specifying common attributes for several
  sources. For example, sources which provide files can specify
  common attributes with a `file' type.")


(defvar anything-enable-shortcuts nil
  "*Whether to use digit/alphabet shortcut to select the first nine matches.
If t then they can be selected using Ctrl+<number>.

If 'prefix then they can be selected using <prefix-key> <alnum>. 
The prefix key is `anything-select-with-prefix-shortcut'.
If the <prefix-key> is a letter, pressing twice inputs the letter itself.
e.g.
 (setq anything-enable-shortcuts 'prefix)
 (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
 
If 'alphabet then they can be selected using Shift+<alphabet> (deprecated).
It is not recommended because you cannot input capital letters in pattern.

Keys (digit/alphabet) are listed in `anything-shortcut-keys-alist'.")

(defvaralias 'anything-enable-digit-shortcuts 'anything-enable-shortcuts
  "Alphabet shortcuts are usable now. Then `anything-enable-digit-shortcuts' should be renamed.
`anything-enable-digit-shortcuts' is retained for compatibility.")

(defvar anything-shortcut-keys-alist
  '((alphabet . "asdfghjklzxcvbnmqwertyuiop")
    (prefix   . "asdfghjklzxcvbnmqwertyuiop1234567890")
    (t        . "123456789")))

(defvar anything-display-source-at-screen-top t
  "*If t, `anything-next-source' and `anything-previous-source'
  display candidates at the top of screen.")

(defvar anything-candidate-number-limit 50
  "*Do not show more candidates than this limit from individual
  sources. It is usually pointless to show hundreds of matches
  when the pattern is empty, because it is much simpler to type a
  few characters to narrow down the list of potential candidates.

  Set it to nil if you don't want this limit.")


(defvar anything-idle-delay 0.5
  "*The user has to be idle for this many seconds, before
  candidates from delayed sources are collected. This is useful
  for sources involving heavy operations (like launching external
  programs), so that candidates from the source are not retrieved
  unnecessarily if the user keeps typing.

  It also can be used to declutter the results anything displays,
  so that results from certain sources are not shown with every
  character typed, only if the user hesitates a bit.")


(defvar anything-input-idle-delay 0.1
  "The user has to be idle for this many seconds, before ALL candidates are collected.
Unlink `anything-input-idle', it is also effective for non-delayed sources.
If nil, candidates are collected immediately. ")


(defvar anything-samewindow nil
  "If t then Anything doesn't pop up a new window, it uses the
current window to show the candidates.")


(defvar anything-source-filter nil
  "A list of source names to be displayed. Other sources won't
appear in the search results. If nil then there is no filtering.
See also `anything-set-source-filter'.")


(defvar anything-map
  (let ((map (copy-keymap minibuffer-local-map)))
    (define-key map (kbd "<down>") 'anything-next-line)
    (define-key map (kbd "<up>") 'anything-previous-line)
    (define-key map (kbd "C-n")     'anything-next-line)
    (define-key map (kbd "C-p")     'anything-previous-line)
    (define-key map (kbd "<prior>") 'anything-previous-page)
    (define-key map (kbd "<next>") 'anything-next-page)
    (define-key map (kbd "M-v")     'anything-previous-page)
    (define-key map (kbd "C-v")     'anything-next-page)
    (define-key map (kbd "M-<")     'anything-beginning-of-buffer)
    (define-key map (kbd "M->")     'anything-end-of-buffer)
    (define-key map (kbd "<right>") 'anything-next-source)
    (define-key map (kbd "<left>") 'anything-previous-source)
    (define-key map (kbd "<RET>") 'anything-exit-minibuffer)
    (define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
    (loop for c from ?A to ?Z do
          (define-key map (make-string 1 c) 'anything-select-with-digit-shortcut))
    (define-key map (kbd "C-i") 'anything-select-action)
    (define-key map (kbd "C-z") 'anything-execute-persistent-action)
    (define-key map (kbd "C-e") 'anything-select-2nd-action-or-end-of-line)
    (define-key map (kbd "C-j") 'anything-select-3rd-action)
    (define-key map (kbd "C-o") 'anything-next-source)
    (define-key map (kbd "C-M-v") 'anything-scroll-other-window)
    (define-key map (kbd "M-<next>") 'anything-scroll-other-window)
    (define-key map (kbd "C-M-y") 'anything-scroll-other-window-down)
    (define-key map (kbd "C-M-S-v") 'anything-scroll-other-window-down)
    (define-key map (kbd "M-<prior>") 'anything-scroll-other-window-down)
    (define-key map (kbd "C-SPC") 'anything-toggle-visible-mark)
    (define-key map (kbd "M-[") 'anything-prev-visible-mark)
    (define-key map (kbd "M-]") 'anything-next-visible-mark)
    (define-key map (kbd "C-k") 'anything-delete-minibuffer-content)

    (define-key map (kbd "C-s") 'anything-isearch)
    (define-key map (kbd "C-r") 'undefined)
    (define-key map (kbd "C-t") 'anything-toggle-resplit-window)
    (define-key map (kbd "C-x C-f") 'anything-quit-and-find-file)

    (define-key map (kbd "C-c C-d") 'anything-delete-current-selection)
    (define-key map (kbd "C-c C-y") 'anything-yank-selection)
    (define-key map (kbd "C-c C-k") 'anything-kill-selection-and-quit)
    (define-key map (kbd "C-c C-f") 'anything-follow-mode)
    (define-key map (kbd "C-c C-u") 'anything-force-update)

    ;; Debugging command
    (define-key map "\C-c\C-x\C-d" 'anything-debug-output)
    (define-key map "\C-c\C-x\C-m" 'anything-display-all-visible-marks)
    (define-key map "\C-c\C-x\C-b" 'anything-send-bug-report-from-anything)
    ;; Use `describe-mode' key in `global-map'
    (dolist (k (where-is-internal 'describe-mode global-map))
      (define-key map k 'anything-help))
    ;; the defalias is needed because commands are bound by name when
    ;; using iswitchb, so only commands having the prefix anything-
    ;; get rebound
    (defalias 'anything-previous-history-element 'previous-history-element)
    (defalias 'anything-next-history-element 'next-history-element)
    (define-key map (kbd "M-p") 'anything-previous-history-element)
    (define-key map (kbd "M-n") 'anything-next-history-element)
    map)
  "Keymap for anything.

If you execute `anything-iswitchb-setup', some keys are modified.
See `anything-iswitchb-setup-keys'.")

(defvar anything-isearch-map
  (let ((map (make-sparse-keymap)))
    (set-keymap-parent map (current-global-map))
    (define-key map (kbd "<return>") 'anything-isearch-default-action)
    (define-key map (kbd "<RET>") 'anything-isearch-default-action)
    (define-key map (kbd "C-i") 'anything-isearch-select-action)
    (define-key map (kbd "C-g") 'anything-isearch-cancel)
    (define-key map (kbd "M-s") 'anything-isearch-again)
    (define-key map (kbd "<backspace>") 'anything-isearch-delete)
    ;; add printing chars
    (loop for i from 32 below 256 do
          (define-key map (vector i) 'anything-isearch-printing-char))
    map)
  "Keymap for anything incremental search.")


(defgroup anything nil
  "Open anything." :prefix "anything-" :group 'convenience)

(defface anything-header 
  '((t (:inherit header-line))) 
  "Face for header lines in the anything buffer." :group 'anything)

(defvar anything-header-face 'anything-header
  "Face for header lines in the anything buffer.")

(defface anything-isearch-match '((t (:background "Yellow")))
  "Face for isearch in the anything buffer." :group 'anything)

(defvar anything-isearch-match-face 'anything-isearch-match
  "Face for matches during incremental search.")

(defvar anything-selection-face 'highlight
  "Face for currently selected item.")

(defvar anything-iswitchb-idle-delay 1
  "Show anything completions if the user is idle that many
  seconds after typing.")

(defvar anything-iswitchb-dont-touch-iswithcb-keys nil
  "If t then those commands are not bound from `anything-map'
  under iswitchb which would override standard iswithcb keys.

This allows an even more seamless integration with iswitchb for
those who prefer using iswitchb bindings even if the anything
completions buffer is popped up.

Note that you can bind alternative keys for the same command in
`anything-map', so that you can use different keys for anything
under iswitchb. For example, I bind the character \ to
`anything-exit-minibuffer' which key is just above Enter on my
keyboard. This way I can switch buffers with Enter and choose
anything completions with \.")

;;----------------------------------------------------------------------

(defvar anything-buffer "*anything*"
  "Buffer showing completions.")

(defvar anything-action-buffer "*anything action*"
  "Buffer showing actions.")

(defvar anything-selection-overlay nil
  "Overlay used to highlight the currently selected item.")

(defvar anything-isearch-overlay nil
  "Overlay used to highlight the current match during isearch.")

(defvar anything-digit-overlays nil
  "Overlays for digit shortcuts. See `anything-enable-shortcuts'.")

(defvar anything-candidate-cache nil
  "Holds the available candidate withing a single anything invocation.")

(defvar anything-pattern
  "The input pattern used to update the anything buffer.")

(defvar anything-input
  "The input typed in the candidates panel.")

(defvar anything-async-processes nil
  "List of information about asynchronous processes managed by anything.")

(defvar anything-digit-shortcut-count 0
  "Number of digit shortcuts shown in the anything buffer.")

(defvar anything-before-initialize-hook nil
  "Run before anything initialization.
This hook is run before init functions in `anything-sources'.")

(defvar anything-after-initialize-hook nil
  "Run after anything initialization.
Global variables are initialized and the anything buffer is created.
But the anything buffer has no contents. ")

(defvar anything-update-hook nil
  "Run after the anything buffer was updated according the new input pattern.
This hook is run at the beginning of buffer.
The first candidate is selected after running this hook.
See also `anything-after-update-hook'.")

(defvar anything-after-update-hook nil
  "Run after the anything buffer was updated according the new input pattern.
This is very similar to `anything-update-hook' but selection is not moved.
It is useful to select a particular object instead of the first one. ")

(defvar anything-cleanup-hook nil
  "Run after anything minibuffer is closed, IOW this hook is executed BEFORE performing action. ")

(defvar anything-after-action-hook nil
  "Run after executing action.")

(defvar anything-after-persistent-action-hook nil
  "Run after executing persistent action.")

(defvar anything-restored-variables
  '( anything-candidate-number-limit
     anything-source-filter
     anything-source-in-each-line-flag
     anything-sources)
  "Variables which are restored after `anything' invocation.")
;; `anything-saved-sources' is removed

(defvar anything-saved-selection nil
  "Saved value of the currently selected object when the action
  list is shown.")

;; `anything-original-source-filter' is removed

(defvar anything-candidate-separator
  "--------------------"
  "Candidates separator of `multiline' source.")

(defvar anything-current-buffer nil
  "Current buffer when `anything' is invoked.")

(defvar anything-buffer-file-name nil
  "`buffer-file-name' when `anything' is invoked.")

(defvar anything-saved-action nil
  "Saved value of the currently selected action by key.")

(defvar anything-last-sources nil
  "OBSOLETE!! Sources of previously invoked `anything'.")

(defvar anything-saved-current-source nil
  "Saved value of the original (anything-get-current-source) when the action
  list is shown.")

(defvar anything-compiled-sources nil
  "Compiled version of `anything-sources'. ")

(defvar anything-in-persistent-action nil
  "Flag whether in persistent-action or not.")

(defvar anything-quick-update nil
  "If non-nil, suppress displaying sources which are out of screen at first.
They are treated as delayed sources at this input.
This flag makes `anything' a bit faster with many sources.")

(defvar anything-last-sources-local nil
  "Buffer local value of `anything-sources'.")
(defvar anything-last-buffer nil
  "`anything-buffer' of previously `anything' session.")

(defvar anything-save-configuration-functions
  '(set-window-configuration . current-window-configuration)
  "If you want to save and restore frame configuration, set this variable to
 '(set-frame-configuration . current-frame-configuration)

Older version saves/restores frame configuration, but the default is changed now,
because flickering is occurred in some environment.
")

(defvar anything-persistent-action-use-special-display nil
  "If non-nil, use `special-display-function' in persistent action.")

(defvar anything-execute-action-at-once-if-one nil
  "If non-nil and there is one candidate, execute the first action without selection.
It is useful for `anything' applications.")

(defvar anything-quit-if-no-candidate nil
  "if non-nil and there is no candidate, do not display *anything* buffer and quit.
This variable accepts a function, which is executed if no candidate.

It is useful for `anything' applications.")

(defvar anything-scroll-amount nil
  "Scroll amount used by `anything-scroll-other-window' and `anything-scroll-other-window-down'.
If you prefer scrolling line by line, set this value to 1.")

(defvar anything-display-function 'anything-default-display-buffer
  "Function to display *anything* buffer.
It is `anything-default-display-buffer' by default, which affects `anything-samewindow'.")

(defvar anything-delayed-init-executed nil)

(defvar anything-mode-line-string "\\<anything-map>\\[anything-help]:help \\[anything-select-action]:Acts \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\\[anything-select-3rd-action]:NthAct \\[anything-send-bug-report-from-anything]:BugReport"
  "Help string displayed in mode-line in `anything'.
If nil, use default `mode-line-format'.")

(defvar anything-help-message
  "\\<anything-map>The keys that are defined for `anything' are:
       \\{anything-map}"
  "Detailed help message string for `anything'.
It also accepts function or variable symbol.")

(put 'anything 'timid-completion 'disabled)

(defvar anything-inhibit-fit-frame-flag t
  "If non-nil, inhibit fitting anything frame to its buffer.
It is nil by default because some flickering occurred in some environment.

To enable fitting, set both `anything-inhibit-fit-frame-flag' and
`fit-frame-inhibit-fitting' to nil.")

(defvar anything-source-in-each-line-flag nil
  "If non-nil, add anything-source text-property in each candidate.
experimental feature.")

(defvar anything-debug-forms nil
  "Forms to show in `anything-debug-output'.
Otherwise all variables started with `anything-' are shown.
It is useful for debug.")
(defvaralias 'anything-debug-variables 'anything-debug-forms)

;; (@* "Internal Variables")
(defvar anything-test-candidate-list nil)
(defvar anything-test-mode nil)
(defvar anything-source-name nil)
(defvar anything-candidate-buffer-alist nil)
(defvar anything-check-minibuffer-input-timer nil)
(defvar anything-match-hash (make-hash-table :test 'equal))
(defvar anything-cib-hash (make-hash-table :test 'equal))
(defvar anything-tick-hash (make-hash-table :test 'equal))
(defvar anything-issued-errors nil)
(defvar anything-shortcut-keys nil)
(defvar anything-once-called-functions nil)
(defvar anything-follow-mode nil)

;; (@* "Programming Tools")
(defmacro anything-aif (test-form then-form &rest else-forms)
  "Anaphoric if. Temporary variable `it' is the result of test-form."
  `(let ((it ,test-form))
     (if it ,then-form ,@else-forms)))  
(put 'anything-aif 'lisp-indent-function 2)

(defun anything-mklist (obj)
  "If OBJ is a list (but not lambda), return itself, otherwise make a list with one element."
  (if (and (listp obj) (not (functionp obj)))
      obj
    (list obj)))

;; (@* "Anything API")
(defun anything-buffer-get ()
  "If *anything action* buffer is shown, return `anything-action-buffer', otherwise `anything-buffer'."
  (if (anything-action-window)
      anything-action-buffer
    anything-buffer))

(defun anything-window ()
  "Window of `anything-buffer'."
  (get-buffer-window (anything-buffer-get) 'visible))

(defun anything-action-window ()
  "Window of `anything-action-buffer'."
  (get-buffer-window anything-action-buffer 'visible))

(defmacro with-anything-window (&rest body)
  `(let ((--tmpfunc-- (lambda () ,@body)))
     (if anything-test-mode
         (with-current-buffer (anything-buffer-get)
           (funcall --tmpfunc--))
       (with-selected-window (anything-window)
         (funcall --tmpfunc--)))))
(put 'with-anything-window 'lisp-indent-function 0)

(defmacro with-anything-restore-variables(&rest body)
  "Restore variables specified by `anything-restored-variables' after executing BODY .
`post-command-hook' is handled specially."
  `(let ((--orig-vars (mapcar (lambda (v) (cons v (symbol-value v))) anything-restored-variables))
         (--post-command-hook-pair (cons post-command-hook
                                         (default-value 'post-command-hook))))
     (setq post-command-hook '(t))
     (setq-default post-command-hook nil)
     (unwind-protect (progn ,@body)
       (loop for (var . value) in --orig-vars
             do (set var value))
       (setq post-command-hook (car --post-command-hook-pair))
       (setq-default post-command-hook (cdr --post-command-hook-pair)))))
(put 'with-anything-restore-variables 'lisp-indent-function 0)

(defun* anything-attr (attribute-name &optional (src (anything-get-current-source)))
  "Get the value of ATTRIBUTE-NAME of SRC (source).
if SRC is omitted, use current source.
It is useful to write your sources."
  (anything-aif (assq attribute-name src)
      (cdr it)))

(defun* anything-attr-defined (attribute-name &optional (src (anything-get-current-source)))
  "Return non-nil if ATTRIBUTE-NAME of SRC (source)  is defined.
if SRC is omitted, use current source.
It is useful to write your sources."
  (and (assq attribute-name src) t))

(defun* anything-attrset (attribute-name value &optional (src (anything-get-current-source)))
  "Set the value of ATTRIBUTE-NAME of SRC (source) to VALUE.
if SRC is omitted, use current source.
It is useful to write your sources."
  (anything-aif (assq attribute-name src)
      (setcdr it value)
    (setcdr src (cons (cons attribute-name value) (cdr src))))
  value)

;; anything-set-source-filter
;;
;;   This function sets a filter for anything sources and it may be
;;   called while anything is running. It can be used to toggle
;;   displaying of sources dinamically. For example, additional keys
;;   can be bound into `anything-map' to display only the file-related
;;   results if there are too many matches from other sources and
;;   you're after files only:
;;
;;   Shift+F shows only file results from some sources:
;;
;;     (define-key anything-map "F" 'anything-my-show-files-only)
;;     
;;     (defun anything-my-show-files-only ()
;;       (interactive)
;;       (anything-set-source-filter '("File Name History"
;;                                     "Files from Current Directory")))
;;
;;   Shift+A shows all results:
;;
;;     (define-key anything-map "A" 'anything-my-show-all)
;;     
;;     (defun anything-my-show-all ()
;;       (interactive)
;;       (anything-set-source-filter nil))
;;  
;;  
;;   Note that you have to prefix the functions with anything- prefix,
;;   otherwise they won't be bound when Anything is used under
;;   Iswitchb. The -my- part is added to avoid collisions with
;;   existing Anything function names.
;;  
(defun anything-set-source-filter (sources)
  "Sets the value of `anything-source-filter' and updates the list of results."
  (unless (and (listp sources)
               (loop for name in sources always (stringp name)))
    (error "invalid data in `anything-set-source-filter': %S" sources))
  (setq anything-source-filter sources)
  (anything-update))

(defun anything-set-sources (sources &optional no-init no-update)
  "Set `anything-sources' during `anything' invocation.
If NO-INIT is non-nil, skip executing init functions of SOURCES.
If NO-UPDATE is non-nil, skip executing `anything-update'."
  (setq anything-compiled-sources nil
        anything-sources sources)
  (unless no-init (anything-funcall-foreach 'init))
  (unless no-update (anything-update)))

(defvar anything-compile-source-functions
  '(anything-compile-source--type
    anything-compile-source--dummy
    anything-compile-source--disable-shortcuts
    anything-compile-source--candidates-in-buffer)
  "Functions to compile elements of `anything-sources' (plug-in).")

(defun anything-get-sources ()
  "Return compiled `anything-sources', which is memoized.

Attributes:

- type
  `anything-type-attributes' are merged in.
- candidates-buffer
  candidates, volatile and match attrubute are created.
"
  (cond
   ;; action
   ((anything-action-window)
    anything-sources)
   ;; memoized
   (anything-compiled-sources)
   ;; first time
   (t
    (setq anything-compiled-sources
          (anything-compile-sources anything-sources anything-compile-source-functions)))))

(defun* anything-get-selection (&optional (buffer nil buffer-s) (force-display-part))
  "Return the currently selected item or nil.
if BUFFER is nil or unspecified, use anything-buffer as default value.
If FORCE-DISPLAY-PART is non-nil, return the display string."
  (setq buffer (if (and buffer buffer-s) buffer anything-buffer))
  (unless (zerop (buffer-size (get-buffer buffer)))
    (with-current-buffer buffer
      (let ((selection
             (or (and (not force-display-part)
                      (get-text-property (overlay-start
                                          anything-selection-overlay)
                                         'anything-realvalue))
                 (let ((disp (buffer-substring-no-properties
                              (overlay-start anything-selection-overlay)
                              (1- (overlay-end anything-selection-overlay))))
                       (source (anything-get-current-source)))
                   (anything-aif (and (not force-display-part)
                                      (assoc-default 'display-to-real source))
                       (anything-funcall-with-source source it disp)
                     disp)))))
        (unless (equal selection "")
          selection)))))

(defun anything-get-action ()
  "Return the associated action for the selected candidate."
  (unless (zerop (buffer-size (get-buffer (anything-buffer-get))))
    (let* ((source (anything-get-current-source))
           (actions (assoc-default 'action source)))

      (anything-aif (assoc-default 'action-transformer source)
          ;; (funcall it actions (anything-get-selection))
          (anything-composed-funcall-with-source source it actions (anything-get-selection))
        actions))))

(defun anything-get-current-source ()
  "Return the source for the current selection / in init/candidates/action/candidate-transformer/filtered-candidate-transformer function."
  (declare (special source))
  ;; The name `anything-get-current-source' should be used in init function etc.
  (if (and (boundp 'anything-source-name) (stringp anything-source-name))
      source
    (or 
     (with-current-buffer (anything-buffer-get)
       (get-text-property (point) 'anything-source))
     (block exit
       (with-current-buffer (anything-buffer-get)
         ;; This goto-char shouldn't be necessary, but point is moved to
         ;; point-min somewhere else which shouldn't happen.
         (goto-char (overlay-start anything-selection-overlay))
         (let* ((header-pos (or (anything-get-previous-header-pos)
                                (anything-get-next-header-pos)))
                (source-name
                 (save-excursion
                   (unless header-pos
                     (message "No candidates")
                     (return-from exit nil))
                   (goto-char header-pos)
                   (buffer-substring-no-properties
                    (line-beginning-position) (line-end-position)))))
           (some (lambda (source)
                   (if (equal (assoc-default 'name source)
                              source-name)
                       source))
                 (anything-get-sources))))))))

(defun anything-buffer-is-modified (buffer)
  "Return non-nil when BUFFER is modified since `anything' was invoked."
  (let* ((b (get-buffer buffer))
         (key (concat (buffer-name b)
                     "/"
                     (anything-attr 'name)))
         (source-tick (or (gethash key anything-tick-hash) 0))
         (buffer-tick (buffer-chars-modified-tick b)))
    (prog1 (/= source-tick buffer-tick)
      (puthash key buffer-tick anything-tick-hash))))
(defun anything-current-buffer-is-modified ()
  "Return non-nil when `anything-current-buffer' is modified since `anything' was invoked."
  (anything-buffer-is-modified anything-current-buffer))

(defvar anything-quit nil)
(defun anything-run-after-quit (function &rest args)
  "Perform an action after quitting `anything'.
The action is to call FUNCTION with arguments ARGS."
  (setq anything-quit t)
  (apply 'run-with-idle-timer 0 nil function args)
  (anything-exit-minibuffer))

(defun define-anything-type-attribute (type definition &optional doc)
  "Register type attribute of TYPE as DEFINITION with DOC.
DOC is displayed in `anything-type-attributes' docstring.

Use this function is better than setting `anything-type-attributes' directly."
  (anything-add-type-attribute type definition)
  (and doc (anything-document-type-attribute type doc))
  nil)

(defvar anything-additional-attributes nil
  "List of all `anything' attributes.")
(defvaralias 'anything-attributes 'anything-additional-attributes)
(defun anything-document-attribute (attribute short-doc &optional long-doc)
  "Register ATTRIBUTE documentation introduced by plug-in.
SHORT-DOC is displayed beside attribute name.
LONG-DOC is displayed below attribute name and short documentation."
  (if long-doc
      (setq short-doc (concat "(" short-doc ")"))
    (setq long-doc short-doc
          short-doc ""))
  (add-to-list 'anything-additional-attributes attribute t)
  (put attribute 'anything-attrdoc
       (concat "- " (symbol-name attribute) " " short-doc "\n\n" long-doc "\n")))
(put 'anything-document-attribute 'lisp-indent-function 2)

(defun anything-require-at-least-version (version)
  "Output error message unless anything.el is older than VERSION.
This is suitable for anything applications."
  (when (and (string= "1." (substring version 0 2))
             (string-match "1\.\\([0-9]+\\)" anything-version)
             (< (string-to-number (match-string 1 anything-version))
                (string-to-number (substring version 2))))
    (error "Please update anything.el!!

http://www.emacswiki.org/cgi-bin/wiki/download/anything.el

or  M-x install-elisp-from-emacswiki anything.el")))

(defun anything-interpret-value (value &optional source)
  "interpret VALUE as variable, function or literal.
If VALUE is a function, call it with no arguments and return the value.
If SOURCE is `anything' source, `anything-source-name' is source name.

If VALUE is a variable, return the value.

If VALUE is a symbol, but it is not a function or a variable, cause an error.

Otherwise, return VALUE itself."
  (cond ((and source (functionp value))
         (anything-funcall-with-source source value))
        ((functionp value)
         (funcall value))
        ((and (symbolp value) (boundp value))
         (symbol-value value))
        ((symbolp value)
         (error "anything-interpret-value: Symbol must be a function or a variable"))
        (t
         value)))

(defun anything-once (function &rest args)
  "Ensure FUNCTION with ARGS to be called once in `anything' session."
  (let ((spec (cons function args)))
    (unless (member spec anything-once-called-functions)
      (apply function args)
      (push spec anything-once-called-functions))))

;; (@* "Core: tools")
(defun anything-funcall-with-source (source func &rest args)
  "Call FUNC with ARGS with variable `anything-source-name' and `source' is bound.
FUNC can be function list. Return the result of last function call."
  (let ((anything-source-name (assoc-default 'name source))
        result)
    (dolist (func (if (functionp func) (list func) func) result)
      (setq result (apply func args)))))

(defun anything-funcall-foreach (sym)
  "Call the sym function(s) for each source if any."
  (dolist (source (anything-get-sources))
    (when (symbolp source)
      (setq source (symbol-value source)))
    (anything-aif (assoc-default sym source)
        (anything-funcall-with-source source it))))

(defun anything-normalize-sources (sources)
  "If SOURCES is only one source, make a list."
  (cond ((or (and sources               ; avoid nil
                  (symbolp sources))
             (and (listp sources) (assq 'name sources)))
         (list sources))
        (sources)
        (t anything-sources)))  

(defun anything-approximate-candidate-number ()
  "Approximate Number of candidates.
It is used to check if candidate number is 0, 1, or 2+."
  (with-current-buffer anything-buffer
    (let ((lines (1- (line-number-at-pos (1- (point-max))))))
      (if (zerop lines)
          0
        (save-excursion
          (goto-char (point-min))
          (forward-line 1)
          (if (anything-pos-multiline-p)
              (if (search-forward anything-candidate-separator nil t) 2 1)
            lines))))))

(defmacro with-anything-quittable (&rest body)
  `(let (inhibit-quit)
     (condition-case v
         (progn ,@body)
       (quit (setq anything-quit t)
             (exit-minibuffer)
             (keyboard-quit)))))
(put 'with-anything-quittable 'lisp-indent-function 0)

(defun anything-compose (arg-lst func-lst)
  "Call each function in FUNC-LST with the arguments specified in ARG-LST.
The result of each function will be the new `car' of ARG-LST.

This function allows easy sequencing of transformer functions."
  (dolist (func func-lst)
    (setcar arg-lst (apply func arg-lst)))
  (car arg-lst))

(defun anything-composed-funcall-with-source (source funcs &rest args)
  (if (functionp funcs)
      (apply 'anything-funcall-with-source source funcs args)
    (apply 'anything-funcall-with-source
           source (lambda (&rest args) (anything-compose args funcs)) args)))

;; (@* "Core: entry point")
(defvar anything-buffers nil
  "All of `anything-buffer' in most recently used order.")

;;;###autoload
(defun anything (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer any-keymap)
  "Select anything. In Lisp program, some optional arguments can be used.

Note that all the optional arguments are prefixed because of
dynamic scope problem, IOW argument variables may eat
already-bound variables. Yuck!

- ANY-SOURCES

  Temporary value of `anything-sources'.  It also accepts a
  symbol, interpreted as a variable of an anything source.  It
  also accepts an alist representing an anything source, which is
  detected by (assq 'name ANY-SOURCES)


- ANY-INPUT

  Temporary value of `anything-pattern', ie. initial input of minibuffer.

- ANY-PROMPT

  Prompt other than \"pattern: \".

- ANY-RESUME

  If t, Resurrect previously instance of `anything'. Skip the initialization.
  If 'noresume, this instance of `anything' cannot be resumed.

- ANY-PRESELECT

  Initially selected candidate. Specified by exact candidate or a regexp.
  Note that it is not working with delayed sources.

- ANY-BUFFER

  `anything-buffer' instead of *anything*.

- ANY-KEYMAP

  `anything-map' for current `anything' session.
"
  ;; TODO more document
  (interactive)
  (condition-case v
      (let ( ;; It is needed because `anything-source-name' is non-nil
            ;; when `anything' is invoked by action. Awful global scope.
            anything-source-name anything-in-persistent-action
                                 anything-quit
                                 (case-fold-search t)
                                 (anything-buffer (or any-buffer anything-buffer))
                                 (anything-map (or any-keymap anything-map)))
        (with-anything-restore-variables
          (anything-frame/window-configuration 'save)
          (setq anything-sources (anything-normalize-sources any-sources))
          (anything-initialize-1 any-resume any-input)
          (anything-hooks 'setup)
          (if (eq any-resume t)
              (condition-case x
                  (anything-window-configuration 'restore)
                (error (anything-display-buffer anything-buffer)))
            (anything-display-buffer anything-buffer))
          (unwind-protect
              (anything-read-pattern-maybe any-prompt any-input any-preselect any-resume)
            (anything-cleanup)
            (anything-hooks 'cleanup)
            (anything-frame/window-configuration 'restore)))
        (unless anything-quit
          (anything-execute-selection-action-1)))
    (quit
     (anything-on-quit)
     nil)))

(defun anything-resume-p (any-resume)
  "Whethre current anything session is resumed or not."
  (memq any-resume '(t window-only)))

(defun anything-initialize-1 (any-resume any-input)
  (anything-current-position 'save)
  (if (anything-resume-p any-resume)
      (anything-initialize-overlays (anything-buffer-get))
    (anything-initialize))
  (unless (eq any-resume 'noresume)
    (anything-recent-push anything-buffer 'anything-buffers)
    (setq anything-last-buffer anything-buffer))
  (when any-input (setq anything-input any-input anything-pattern any-input))
  (and (anything-resume-p any-resume) (anything-funcall-foreach 'resume)))

(defun anything-execute-selection-action-1 ()
  (unwind-protect
      (anything-execute-selection-action)
    (anything-aif (get-buffer anything-action-buffer)
        (kill-buffer it))
    (run-hooks 'anything-after-action-hook)))

(defun anything-on-quit ()
  (setq minibuffer-history (cons anything-input minibuffer-history))
  (anything-current-position 'restore))

(defun anything-resume-select-buffer (input)
  (anything '(((name . "Resume anything buffer")
               (candidates . anything-buffers)
               (action . identity)))
            input nil 'noresume nil "*anything resume*"))

(defun* anything-resume (&optional (any-buffer anything-last-buffer) buffer-pattern (any-resume t))
  "Resurrect previously invoked `anything'."
  (interactive)
  (when (or current-prefix-arg buffer-pattern)
    (setq any-buffer (anything-resume-select-buffer buffer-pattern)))
  (setq anything-compiled-sources nil)
  (anything
   (or (buffer-local-value 'anything-last-sources-local (get-buffer any-buffer))
       anything-last-sources anything-sources)
   (buffer-local-value 'anything-input-local (get-buffer any-buffer)) nil any-resume nil any-buffer))

;;; rubikitch: experimental
;;; I use this and check it whether I am convenient.
;;; I may introduce an option to control the behavior.
(defun* anything-resume-window-only (&optional (any-buffer anything-last-buffer) buffer-pattern)
  (interactive)
  (anything-resume any-buffer buffer-pattern 'window-only))

(defun anything-recent-push (elt list-var)
  "Add ELT to the value of LIST-VAR as most recently used value."
  (let ((m (member elt (symbol-value list-var))))
    (and m (set list-var (delq (car m) (symbol-value list-var))))
    (push elt (symbol-value list-var))))

;;; (@* "Core: Accessors")
(defvar anything-window-configuration nil)
;;; (set-window-configuration (buffer-local-value 'anything-window-configuration (get-buffer "*anything buffers*")))
(defun anything-window-configuration (save-or-restore)
  (case save-or-restore
    ((save store)
     (with-current-buffer anything-buffer
       (set (make-local-variable 'anything-window-configuration)
            (current-window-configuration))))
    ((restore set)
     (with-current-buffer anything-buffer
       (set-window-configuration anything-window-configuration))
     (select-window (anything-window)))))

(defvar anything-current-position nil
  "Cons of (point) and (window-start) when `anything' is invoked.
It is needed because restoring position when `anything' is keyboard-quitted.")
(defun anything-current-position (save-or-restore)
  (case save-or-restore
    (save
     (setq anything-current-position (cons (point) (window-start))))
    (restore
     (goto-char (car anything-current-position))
     (set-window-start (selected-window) (cdr anything-current-position)))))

;;; FIXME I want to remove them. But anything-iswitchb uses them.
(defun anything-current-frame/window-configuration ()
  (funcall (cdr anything-save-configuration-functions)))
(defun anything-set-frame/window-configuration (conf)
  (funcall (car anything-save-configuration-functions) conf))

(declare-function 'anything-frame/window-configuration "anything")
(lexical-let (conf)
  (defun anything-frame/window-configuration (save-or-restore)
    (case save-or-restore
      (save    (setq conf (funcall (cdr anything-save-configuration-functions))))
      (restore (funcall (car anything-save-configuration-functions) conf)))))



;;;###autoload
(defun anything-at-point (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer)
  "Same as `anything' except when C-u is pressed, the initial input is the symbol at point."
  (interactive)
  (anything any-sources
            (if current-prefix-arg
                (concat "\\b" (thing-at-point 'symbol) "\\b"
                        (if (featurep 'anything-match-plugin) " " ""))
              any-input)
            any-prompt any-resume any-preselect any-buffer))

(defun anything-other-buffer (any-sources any-buffer)
  "Simplified interface of `anything' with other `anything-buffer'"
  (anything any-sources nil nil nil nil any-buffer))

;; (@* "Core: Display *anything* buffer")
(defun anything-display-buffer (buf)
  "Display *anything* buffer."
  (funcall anything-display-function buf))

(defun anything-default-display-buffer (buf)
  (funcall (if anything-samewindow 'switch-to-buffer 'pop-to-buffer) buf))

;; (@* "Core: initialize")
(defun anything-initialize ()
  "Initialize anything settings and set up the anything buffer."
  (run-hooks 'anything-before-initialize-hook)
  (setq anything-once-called-functions nil)
  (setq anything-delayed-init-executed nil)
  (setq anything-current-buffer (current-buffer))
  (setq anything-buffer-file-name buffer-file-name)
  (setq anything-issued-errors nil)
  (setq anything-compiled-sources nil)
  (setq anything-saved-current-source nil)
  ;; Call the init function for sources where appropriate
  (anything-funcall-foreach 'init)

  (setq anything-pattern "")
  (setq anything-input "")
  (setq anything-candidate-cache nil)
  (setq anything-last-sources anything-sources)

  (anything-create-anything-buffer)
  (run-hooks 'anything-after-initialize-hook))

(defun anything-read-pattern-maybe (any-prompt any-input any-preselect any-resume)
  (if (anything-resume-p any-resume) (anything-mark-current-line) (anything-update))
  (select-frame-set-input-focus (window-frame (minibuffer-window)))
  (anything-preselect any-preselect)
  (let ((ncandidate (anything-approximate-candidate-number))
        (minibuffer-local-map anything-map))
    (cond ((and anything-execute-action-at-once-if-one
                (= ncandidate 1))
           (ignore))
          ((and anything-quit-if-no-candidate (= ncandidate 0))
           (setq anything-quit t)
           (and (functionp anything-quit-if-no-candidate)
                (funcall anything-quit-if-no-candidate)))
          (t
           (read-string (or any-prompt "pattern: ") any-input)))))

(defun anything-create-anything-buffer (&optional test-mode)
  "Create newly created `anything-buffer'.
If TEST-MODE is non-nil, clear `anything-candidate-cache'."
  (when test-mode
    (setq anything-candidate-cache nil))
  (with-current-buffer (get-buffer-create anything-buffer)
    (buffer-disable-undo)
    (erase-buffer)
    (set (make-local-variable 'inhibit-read-only) t)
    (set (make-local-variable 'anything-last-sources-local) anything-sources)
    (set (make-local-variable 'anything-follow-mode) nil)
    
    (setq cursor-type nil)
    (setq mode-name "Anything"))
  (anything-initialize-overlays anything-buffer)
  (get-buffer anything-buffer))

(defun anything-initialize-overlays (buffer)
  (if anything-selection-overlay
      ;; make sure the overlay belongs to the anything buffer if
      ;; it's newly created
      (move-overlay anything-selection-overlay (point-min) (point-min)
                    (get-buffer buffer))

    (setq anything-selection-overlay 
          (make-overlay (point-min) (point-min) (get-buffer buffer)))
    (overlay-put anything-selection-overlay 'face anything-selection-face))

  (when anything-enable-shortcuts
    (setq anything-shortcut-keys (assoc-default anything-enable-shortcuts anything-shortcut-keys-alist)))

  (if anything-enable-shortcuts
      (unless anything-digit-overlays
        (setq anything-digit-overlays
              (loop for key across anything-shortcut-keys
                    for overlay = (make-overlay (point-min) (point-min) (get-buffer buffer))
                    do (overlay-put overlay 'before-string
                                    (format "%s - " (upcase (make-string 1 key))))
                    collect overlay)))

    (when anything-digit-overlays
      (dolist (overlay anything-digit-overlays)
        (delete-overlay overlay))
      (setq anything-digit-overlays nil))))

(defun anything-hooks (setup-or-cleanup)
  (let ((hooks '((post-command-hook anything-check-minibuffer-input)
                 (minibuffer-setup-hook anything-print-error-messages)
                 (minibuffer-exit-hook (lambda () (anything-window-configuration 'save))))))
    (if (eq setup-or-cleanup 'setup)
        (dolist (args hooks) (apply 'add-hook args))
      (dolist (args (reverse hooks)) (apply 'remove-hook args)))))

;; (@* "Core: clean up")
(defun anything-cleanup ()
  "Clean up the mess."
  (with-current-buffer anything-buffer
    (setq cursor-type t))
  (bury-buffer anything-buffer)
  (anything-funcall-foreach 'cleanup)
  (if anything-check-minibuffer-input-timer
      (cancel-timer anything-check-minibuffer-input-timer))
  (anything-kill-async-processes)
  (run-hooks 'anything-cleanup-hook))

;; (@* "Core: input handling")
(defun anything-check-minibuffer-input ()
  "Extract input string from the minibuffer and check if it needs
to be handled."
  (if (or (not anything-input-idle-delay) (anything-action-window))
      (anything-check-minibuffer-input-1)
    (if anything-check-minibuffer-input-timer
        (cancel-timer anything-check-minibuffer-input-timer))
    (setq anything-check-minibuffer-input-timer
          (run-with-idle-timer anything-input-idle-delay nil
                               'anything-check-minibuffer-input-1))))

(defun anything-check-minibuffer-input-1 ()
  (with-anything-quittable
    (with-selected-window (minibuffer-window)
      (anything-check-new-input (minibuffer-contents)))))

(defun anything-check-new-input (input)
  "Check input string and update the anything buffer if
necessary."
  (unless (equal input anything-pattern)
    (setq anything-pattern input)
    (unless (anything-action-window)
      (setq anything-input anything-pattern))
    (anything-update)))

;; (@* "Core: source compiler")
(defvar anything-compile-source-functions-default anything-compile-source-functions
  "Plug-ins this file provides.")
(defun anything-compile-sources (sources funcs)
  "Compile sources (`anything-sources') with funcs (`anything-compile-source-functions').
Anything plug-ins are realized by this function."
  (mapcar
   (lambda (source)
     (loop with source = (if (listp source) source (symbol-value source))
           for f in funcs
           do (setq source (funcall f source))
           finally (return source)))
   sources))  

;; (@* "Core: plug-in attribute documentation hack")

;; `anything-document-attribute' is public API.
(defadvice documentation-property (after anything-document-attribute activate)
  "Hack to display plug-in attributes' documentation as `anything-sources' docstring."
  (when (eq symbol 'anything-sources)
    (setq ad-return-value
          (concat ad-return-value "\n"
                  (mapconcat (lambda (sym) (get sym 'anything-attrdoc))
                             anything-additional-attributes
                             "\n")))))
;; (describe-variable 'anything-sources)
;; (documentation-property 'anything-sources 'variable-documentation)
;; (progn (ad-disable-advice 'documentation-property 'after 'anything-document-attribute) (ad-update 'documentation-property)) 

;; (@* "Core: all candidates")
(defun anything-get-candidates (source)
  "Retrieve and return the list of candidates from
SOURCE."
  (let ((name (assoc-default 'name source)))
    (unless (member name anything-delayed-init-executed)
      (anything-aif (assoc-default 'delayed-init source)
          (with-current-buffer anything-current-buffer
            (anything-funcall-with-source source it)
            (dolist (f (if (functionp it) (list it) it))
              (add-to-list 'anything-delayed-init-executed name))))))
  (let* ((candidate-source (assoc-default 'candidates source))
         (candidates (anything-interpret-value candidate-source source)))
    (cond ((processp candidates) candidates)
          ((listp candidates) (anything-transform-candidates candidates source))
          (t (error (concat "Candidates must either be a function, "
                                 " a variable or a list: %s")
                        candidate-source)))))
         

(defun anything-transform-candidates (candidates source &optional process-p)
  "Transform CANDIDATES according to candidate transformers."
  (anything-aif (assoc-default 'candidate-transformer source)
      (setq candidates (anything-composed-funcall-with-source source it candidates)))
  (anything-aif (and process-p (assoc-default 'filtered-candidate-transformer source))
      (setq candidates (anything-composed-funcall-with-source source it candidates source)))
  (anything-aif (assoc-default 'real-to-display source)
      (setq candidates (anything-funcall-with-source
                        source 'mapcar
                        (lambda (cand_)
                          (if (consp cand_)
                              ;; override DISPLAY from candidate-transformer
                              (cons (funcall it (cdr cand_)) (cdr cand_))
                            (cons (funcall it cand_) cand_)))
                        candidates)))
  candidates)


(defun anything-get-cached-candidates (source)
  "Return the cached value of candidates for SOURCE.
Cache the candidates if there is not yet a cached value."
  (let* ((name (assoc-default 'name source))
         (candidate-cache (assoc name anything-candidate-cache))
         candidates)
    (if candidate-cache
        (setq candidates (cdr candidate-cache))

      (setq candidates (anything-get-candidates source))

      (if (processp candidates)
          (progn
            (push (cons candidates
                        (append source 
                                (list (cons 'item-count 0)
                                      (cons 'incomplete-line ""))))
                  anything-async-processes)
            (set-process-filter candidates 'anything-output-filter)
            (setq candidates nil))

        (unless (assoc 'volatile source)
          (setq candidate-cache (cons name candidates))
          (push candidate-cache anything-candidate-cache))))

    candidates))

;; (@* "Core: narrowing candidates")
(defun anything-candidate-number-limit (source)
  "`anything-candidate-number-limit' variable may be overridden by SOURCE.
If (candidate-number-limit) is in SOURCE, show all candidates in SOURCE,
ie. cancel the effect of `anything-candidate-number-limit'."
  (anything-aif (assq 'candidate-number-limit source)
      (or (cdr it) 99999999)
    (or anything-candidate-number-limit 99999999)))

(defun anything-compute-matches (source)
  "Compute matches from SOURCE according to its settings."
  (let ((doit (lambda ()
                (let ((functions (assoc-default 'match source))
                      (anything-source-name (assoc-default 'name source))
                      (limit (anything-candidate-number-limit source))
                      (anything-pattern
                       (anything-aif (assoc-default 'pattern-transformer source)
                           (anything-composed-funcall-with-source source it anything-pattern)
                         anything-pattern))
                      matches)
                  (cond ((or (equal anything-pattern "") (equal functions '(identity)))
                         (setq matches (anything-get-cached-candidates source))
                         (if (> (length matches) limit)
                             (setq matches 
                                   (subseq matches 0 limit))))
                        (t
                         (condition-case nil
                             (let ((item-count 0)
                                   (cands (anything-get-cached-candidates source))
                                   exit)

                               (unless functions
                                 (setq functions
                                       (list (lambda (candidate)
                                               (string-match anything-pattern candidate)))))

                               (clrhash anything-match-hash)
                               (dolist (function functions)
                                 (let (newmatches c cc)
                                   (dolist (candidate cands)
                                     (when (and (not (gethash candidate anything-match-hash))
                                                (setq c (if (listp candidate)
                                                                     (car candidate)
                                                                   candidate))
                                                (setq cc (cond ((stringp c) c)
                                                               ((symbolp c) (symbol-name c))))
                                                (funcall function cc))
                                       (puthash candidate t anything-match-hash)
                                       (push candidate newmatches)

                                       (when limit
                                         (incf item-count)
                                         (when (= item-count limit)
                                           (setq exit t)
                                           (return)))))

                                   (setq matches (append matches (reverse newmatches)))

                                   (if exit
                                       (return)))))

                           (invalid-regexp (setq matches nil)))))

                  (anything-aif (assoc-default 'filtered-candidate-transformer source)
                      (setq matches
                            (anything-composed-funcall-with-source source it matches source)))
                  matches))))
    (if debug-on-error
        (funcall doit)
      (condition-case v
          (funcall doit)
        (error (anything-log-error
                "anything-compute-matches: error when processing source: %s"
                (assoc-default 'name source))
               nil)))))

;; (anything '(((name . "error")(candidates . (lambda () (hage))) (action . identity))))

(defun anything-process-source (source)
  "Display matches from SOURCE according to its settings."
  (let ((matches (anything-compute-matches source)))
    (when matches
      (when anything-test-mode
          (setq anything-test-candidate-list
                `(,@anything-test-candidate-list
                  (,(assoc-default 'name source)
                   ,matches))))
      (let ((multiline (assq 'multiline source))
            (start (point))
            separate)
        (anything-insert-header-from-source source)
        (dolist (match matches)
          (if (and multiline separate)
              (anything-insert-candidate-separator)
            (setq separate t))

          (when (and anything-enable-shortcuts
                     (not (eq anything-digit-shortcut-count
                              (length anything-digit-overlays))))
            (move-overlay (nth anything-digit-shortcut-count
                               anything-digit-overlays)
                          (line-beginning-position)
                          (line-beginning-position))
            (incf anything-digit-shortcut-count))
          (anything-insert-match match 'insert source))
        
        (if multiline
            (put-text-property start (point) 'anything-multiline t))))))

(defun anything-process-delayed-sources (delayed-sources)
  "Process delayed sources if the user is idle for
`anything-idle-delay' seconds."
  (with-anything-quittable
    (if (sit-for (if anything-input-idle-delay
                     (max 0 (- anything-idle-delay anything-input-idle-delay))
                   anything-idle-delay))
        (with-current-buffer anything-buffer        
          (save-excursion
            (goto-char (point-max))
            (dolist (source delayed-sources)
              (anything-process-source source))

            (when (and (not (equal (buffer-size) 0))
                       ;; no selection yet
                       (= (overlay-start anything-selection-overlay)
                          (overlay-end anything-selection-overlay)))
              (goto-char (point-min))
              (anything-next-line)))
          (save-excursion
            (goto-char (point-min))
            (run-hooks 'anything-update-hook))
          (anything-maybe-fit-frame)))))

;; (@* "Core: *anything* buffer contents")
(defvar anything-input-local nil)
(defun anything-update ()
  "Update the list of matches in the anything buffer according to
the current pattern."
  (setq anything-digit-shortcut-count 0)
  (anything-kill-async-processes)
  (with-current-buffer (anything-buffer-get)
    (set (make-local-variable 'anything-input-local) anything-pattern)
    (erase-buffer)

    (if anything-enable-shortcuts
        (dolist (overlay anything-digit-overlays)
          (delete-overlay overlay)))

    (let (delayed-sources)
      (unwind-protect
          (dolist (source (anything-get-sources))
            (when (and (or (not anything-source-filter)
                           (member (assoc-default 'name source) anything-source-filter))
                       (>= (length anything-pattern)
                           (anything-aif (assoc 'requires-pattern source)
                               (or (cdr it) 1)
                             0)))
              (if (or (assoc 'delayed source)
                      (and anything-quick-update
                           (< (window-height (get-buffer-window (current-buffer)))
                              (line-number-at-pos (point-max)))))
                  (push source delayed-sources)
                (anything-process-source source))))

        (goto-char (point-min))
        (save-excursion (run-hooks 'anything-update-hook))
        (anything-next-line)
        (setq delayed-sources (nreverse delayed-sources))
        (if anything-test-mode
            (dolist (source delayed-sources)
              (anything-process-source source))
          (anything-maybe-fit-frame)
          (when delayed-sources
            (run-with-idle-timer (if (featurep 'xemacs)
                                     0.1
                                   0)
                                 nil
                                 'anything-process-delayed-sources
                                 delayed-sources))
          ;; FIXME I want to execute anything-after-update-hook
          ;; AFTER processing delayed sources
          (run-hooks 'anything-after-update-hook))))))

(defun anything-force-update ()
  "Recalculate and update candidates.
If current source has `update' attribute, a function without argument, call it before update."
  (interactive)
  (let ((source (anything-get-current-source)))
    (anything-aif (anything-funcall-with-source source 'anything-candidate-buffer)
        (kill-buffer it))
    (anything-aif (assoc-default 'init source)
        (anything-funcall-with-source source it))
    (anything-aif (assoc-default 'update source)
        (anything-funcall-with-source source it))
    ;; Remove from candidate cache to recalculate candidates
    (setq anything-candidate-cache
          (delete (assoc (assoc-default 'name source) anything-candidate-cache)
                  anything-candidate-cache))
    ;; Go to original selection after update
    (let ((selection (anything-get-selection nil t)))
      (anything-update)
      (with-anything-window
        (anything-goto-source source)
        (forward-char -1)                ;back to \n
        (if (search-forward (concat "\n" selection "\n") nil t)
            (forward-line -1)
          (goto-char (point-min))
          (forward-line 1))
        (anything-mark-current-line)))))

(defun anything-insert-match (match insert-function source)
  "Insert MATCH into the anything buffer. If MATCH is a list then
insert the string inteneded to appear on the display and store
the real value in a text property."
  (let ((start (line-beginning-position (point)))
        (string (if (listp match) (car match) match))
        (realvalue (if (listp match) (cdr match))))
    (when (symbolp string) (setq string (symbol-name string)))
    (when (stringp string)
      (funcall insert-function string)
      ;; Some sources with candidates-in-buffer have already added
      ;; 'anything-realvalue property when creating candidate buffer.
      (unless (get-text-property start 'anything-realvalue)
        (and realvalue
             (put-text-property start (line-end-position)
                                'anything-realvalue realvalue)))
      (when anything-source-in-each-line-flag
        (put-text-property start (line-end-position)
                           'anything-source source))
      (funcall insert-function "\n"))))

(defun anything-insert-header-from-source (source)
  (let ((name (assoc-default 'name source)))
    (anything-insert-header name
                            (anything-aif (assoc-default 'header-name source)
                                (anything-funcall-with-source source it name)))))

(defun anything-insert-header (name &optional display-string)
  "Insert header of source NAME into the anything buffer."
  (unless (bobp)
    (let ((start (point)))
      (insert "\n")
      (put-text-property start (point) 'anything-header-separator t)))

  (let ((start (point)))
    (insert name)
    (put-text-property (line-beginning-position)
                       (line-end-position) 'anything-header t)
    (when display-string
      (overlay-put (make-overlay (line-beginning-position) (line-end-position))
                   'display display-string))
    (insert "\n")
    (put-text-property start (point) 'face anything-header-face)))


(defun anything-insert-candidate-separator ()
  "Insert separator of candidates into the anything buffer."
  (insert anything-candidate-separator)
  (put-text-property (line-beginning-position)
                     (line-end-position) 'anything-candidate-separator t)
  (insert "\n"))




;; (@* "Core: async process")
(defun anything-output-filter (process string)
  "Process output from PROCESS."
  (let* ((process-assoc (assoc process anything-async-processes))
         (process-info (cdr process-assoc))
         (insertion-marker (assoc-default 'insertion-marker process-info))
         (incomplete-line-info (assoc 'incomplete-line process-info))
         (item-count-info (assoc 'item-count process-info))
         (limit (anything-candidate-number-limit process-info)))

    (with-current-buffer anything-buffer
      (save-excursion
        (if insertion-marker
            (goto-char insertion-marker)
        
          (goto-char (point-max))
          (anything-insert-header-from-source process-info)
          (setcdr process-assoc
                  (append process-info `((insertion-marker . ,(point-marker))))))

        (let ((lines (split-string string "\n"))
              (multiline (assq 'multiline process-info))
              (start (point))
              candidates separate)
          (while lines
            (if (not (cdr lines))
                ;; store last incomplete line until new output arrives
                (setcdr incomplete-line-info (car lines))

              (if (cdr incomplete-line-info)
                  (progn
                    (push (concat (cdr incomplete-line-info) (car lines))
                          candidates)
                    (setcdr incomplete-line-info nil))

                (push (car lines) candidates)))
                  
            (pop lines))

          (setq candidates (reverse candidates))
          (dolist (candidate (anything-transform-candidates candidates process-info t))
            ;; FIXME
            ;; (if (and multiline separate)
            ;;      (anything-insert-candidate-separator)
            ;;   (setq separate t))
            (anything-insert-match candidate 'insert-before-markers process-info)
            (incf (cdr item-count-info))
            ;; FIXME
            ;; (if multiline
            ;;     (put-text-property start (point) 'anything-multiline t))
            (when (>= (cdr item-count-info) limit)
              (anything-kill-async-process process)
              (return)))))

      (anything-maybe-fit-frame)

      (run-hooks 'anything-update-hook)

      (if (bobp)
          (anything-next-line)

        (save-selected-window
          (select-window (get-buffer-window anything-buffer 'visible))
          (anything-mark-current-line))))))


(defun anything-kill-async-processes ()
  "Kill all known asynchronous processes according to
`anything-async-processes'."
    "Kill locate process."
    (dolist (process-info anything-async-processes)
      (anything-kill-async-process (car process-info)))
    (setq anything-async-processes nil))


(defun anything-kill-async-process (process)
  "Kill PROCESS and detach the associated functions."
  (set-process-filter process nil)
  (delete-process process))
  

;; (@* "Core: action")
(defun anything-execute-selection-action (&optional selection action clear-saved-action)
  "If a candidate was selected then perform the associated
action."
  (setq selection (or selection (anything-get-selection)))
  (setq action (or action
                   anything-saved-action
                   (if (get-buffer anything-action-buffer)
                       (anything-get-selection anything-action-buffer)
                     (anything-get-action))))
  (let ((source (or anything-saved-current-source (anything-get-current-source))))
    (if (and (not selection) (assoc 'accept-empty source))
        (setq selection ""))
    (if (and (listp action)
             (not (functionp action)))  ; lambda
        ;;select the default action
        (setq action (cdar action)))
    (unless clear-saved-action (setq anything-saved-action nil))
    (if (and selection action)
        (anything-funcall-with-source source  action selection))))

(defun anything-select-action ()
  "Select an action for the currently selected candidate.
If action buffer is selected, back to the anything buffer."
  (interactive)
  (cond ((get-buffer-window anything-action-buffer 'visible)
         (set-window-buffer (get-buffer-window anything-action-buffer) anything-buffer)
         (kill-buffer anything-action-buffer)
         (insert anything-input))
        (t
         (setq anything-saved-selection (anything-get-selection))
         (unless anything-saved-selection
           (error "Nothing is selected."))
         (setq anything-saved-current-source (anything-get-current-source))
         (let ((actions (anything-get-action)))
           (if (functionp actions)
               (message "Sole action: %s" actions)
             (with-current-buffer (get-buffer-create anything-action-buffer)
               (erase-buffer)
               (buffer-disable-undo)
               (set-window-buffer (get-buffer-window anything-buffer) anything-action-buffer)
               (set (make-local-variable 'anything-sources)
                    `(((name . "Actions")
                       (volatile)
                       (candidates . ,actions)
                       ;; Override `anything-candidate-number-limit'
                       (candidate-number-limit . 9999))))
               (set (make-local-variable 'anything-source-filter) nil)
               (set (make-local-variable 'anything-selection-overlay) nil)
               (set (make-local-variable 'anything-digit-overlays) nil)
               (anything-initialize-overlays anything-action-buffer))
             (with-selected-window (minibuffer-window)
               (delete-minibuffer-contents))
             (setq anything-pattern 'dummy) ; so that it differs from the
                                        ; previous one
           
             (anything-check-minibuffer-input))))))

;; (@* "Core: selection")
(defun anything-move-selection-common (move-func unit direction)
  "Move the selection marker to a new position determined by
UNIT and DIRECTION."
  (unless (or (zerop (buffer-size (get-buffer (anything-buffer-get))))
              (not (anything-window)))
    (with-anything-window
      (funcall move-func)
      (while (and (not (bobp))
                  (or (anything-pos-header-line-p)
                      (anything-pos-candidate-separator-p)))
        (forward-line (if (and (eq direction 'previous)
                               (not (eq (line-beginning-position) (point-min))))
                          -1
                        1)))
      (and (bobp) (forward-line 1))     ;skip first header
      (and (eobp) (forward-line -1))    ;avoid last empty line
      (when (and anything-display-source-at-screen-top (eq unit 'source))
        (set-window-start (selected-window)
                          (save-excursion (forward-line -1) (point))))
      (when (anything-get-previous-header-pos)
        (anything-mark-current-line))
      (anything-display-mode-line (anything-get-current-source)))))

(defvar anything-mode-line-string-real nil)
(defun anything-display-mode-line (source)
  (set (make-local-variable 'anything-mode-line-string)
       (anything-interpret-value (or (assoc-default 'mode-line source)
                                     (default-value 'anything-mode-line-string))
                                 source))
  (if anything-mode-line-string
      (setq mode-line-format
            '(" " mode-line-buffer-identification " "
              (line-number-mode "%l") " " (anything-follow-mode "(F)")
              " " anything-mode-line-string-real "-%-")
            anything-mode-line-string-real
            (substitute-command-keys anything-mode-line-string))
    (setq mode-line-format
          (default-value 'mode-line-format)))
  (setq header-line-format
        (anything-interpret-value (assoc-default 'header-line source) source)))

(defun anything-previous-line ()
  "Move selection to the previous line."
  (interactive)
  (anything-move-selection-common
   (lambda ()
     (forward-line -1)
     (when (anything-pos-multiline-p)
       (if (or (anything-pos-header-line-p)
               (anything-pos-candidate-separator-p))
           (forward-line -1)
         (forward-line 1))
       (let ((header-pos (anything-get-previous-header-pos))
             (candidate-pos (anything-get-previous-candidate-separator-pos)))
         (when header-pos
           (if (or (null candidate-pos) (< candidate-pos header-pos))
               (goto-char header-pos)
             (goto-char candidate-pos))
           (forward-line 1)))))
   'line 'previous))

(defun anything-next-line ()
  "Move selection to the next line."
  (interactive)
  (anything-move-selection-common
   (lambda ()
     (if (not (anything-pos-multiline-p))
         (forward-line 1)
       (let ((header-pos (anything-get-next-header-pos))
             (candidate-pos (anything-get-next-candidate-separator-pos)))
         (if (and candidate-pos
                  (or (null header-pos)
                      (< candidate-pos header-pos)))
             (goto-char candidate-pos)
           (if header-pos
               (goto-char header-pos)))
         (if candidate-pos
             (forward-line 1)))))
   'line 'next))

(defun anything-previous-page ()
  "Move selection back with a pageful."
  (interactive)
  (anything-move-selection-common
   (lambda ()
     (condition-case nil
         (scroll-down)
       (beginning-of-buffer (goto-char (point-min)))))
   'page 'previous))

(defun anything-next-page ()
  "Move selection forward with a pageful."
  (interactive)
  (anything-move-selection-common
   (lambda ()
     (condition-case nil
         (scroll-up)
       (end-of-buffer (goto-char (point-max)))))
   'page 'next))

(defun anything-beginning-of-buffer ()
  "Move selection at the top."
  (interactive)
  (anything-move-selection-common (lambda () (goto-char (point-min)))
                                  'edge 'previous))

(defun anything-end-of-buffer ()
  "Move selection at the bottom."
  (interactive)
  (anything-move-selection-common (lambda () (goto-char (point-max)))
                                  'edge 'next))

(defun anything-previous-source ()
  "Move selection to the previous source."
  (interactive)
  (anything-move-selection-common
   (lambda ()
     (forward-line -1)
     (if (bobp)
         (goto-char (point-max))
       (if (anything-pos-header-line-p)
           (forward-line -1)
         (forward-line 1)))
     (goto-char (anything-get-previous-header-pos))
     (forward-line 1))
   'source 'previous))

(defun anything-next-source ()
  "Move selection to the next source."
  (interactive)
  (anything-move-selection-common
   (lambda () (goto-char (or (anything-get-next-header-pos) (point-min))))
   'source 'next))

(defun anything-goto-source (source-or-name)
  "Move the selection to the source (SOURCE-OR-NAME)."
  (anything-move-selection-common
   (lambda ()
     (goto-char (point-min))
     (let ((name (if (stringp source-or-name) source-or-name
                   (assoc-default 'name source-or-name))))
       (while (not (string= name (buffer-substring (point-at-bol) (point-at-eol))))
         (goto-char (anything-get-next-header-pos)))))
   'source 'next))

(defun anything-mark-current-line ()
  "Move selection overlay to current line."
  (move-overlay anything-selection-overlay
                (line-beginning-position)
                (if (anything-pos-multiline-p)
                    (let ((header-pos (anything-get-next-header-pos))
                          (candidate-pos (anything-get-next-candidate-separator-pos)))
                      (or (and (null header-pos) candidate-pos candidate-pos)
                          (and header-pos candidate-pos (< candidate-pos header-pos) candidate-pos)
                          header-pos
                          (point-max)))
                  (1+ (line-end-position))))
  (anything-follow-execute-persistent-action-maybe))

(defun anything-this-command-key ()
  (event-basic-type (elt (this-command-keys-vector) 0)))
;; (progn (read-key-sequence "Key: ") (p (anything-this-command-key)))

(defun anything-select-with-digit-shortcut ()
  (interactive)
  (if (eq anything-enable-shortcuts 'alphabet)
      (save-selected-window
        (select-window (anything-window))          
        (let* ((index (position (anything-this-command-key) anything-shortcut-keys))
               (overlay (nth index anything-digit-overlays)))
          (when (overlay-buffer overlay)
            (goto-char (overlay-start overlay))
            (anything-mark-current-line)
            (anything-exit-minibuffer))))
    (self-insert-command 1)))

;;; EXPERIMENTAL TODO documentation 
(defun anything-select-with-prefix-shortcut ()
  (interactive)
  (if (eq anything-enable-shortcuts 'prefix)
      (save-selected-window
        (select-window (anything-window))          
        (let* ((key (read-event "Select shortcut key: "))
               (index (position key anything-shortcut-keys))
               (overlay (ignore-errors (nth index anything-digit-overlays))))
          (if (not (and overlay (overlay-buffer overlay)))
              (when (numberp key)
                (select-window (minibuffer-window))
                (self-insert-command 1))
            (goto-char (overlay-start overlay))
            (anything-mark-current-line)
            (anything-exit-minibuffer))))
    (self-insert-command 1)))
;; (setq anything-enable-shortcuts 'prefix)
;; (define-key anything-map "@" 'anything-select-with-prefix-shortcut)
;; (define-key anything-map (kbd "<f18>") 'anything-select-with-prefix-shortcut)

(defun anything-exit-minibuffer ()
  "Select the current candidate by exiting the minibuffer."
  (interactive)
  (declare (special anything-iswitchb-candidate-selected))
  (setq anything-iswitchb-candidate-selected (anything-get-selection))
  (exit-minibuffer))


(defun anything-get-next-header-pos ()
  "Return the position of the next header from point."
  (next-single-property-change (point) 'anything-header))


(defun anything-get-previous-header-pos ()
  "Return the position of the previous header from point"
  (previous-single-property-change (point) 'anything-header))


(defun anything-pos-multiline-p ()
  "Return non-nil if the current position is in the multiline source region."
  (get-text-property (point) 'anything-multiline))


(defun anything-get-next-candidate-separator-pos ()
  "Return the position of the next candidate separator from point."
  (next-single-property-change (point) 'anything-candidate-separator))


(defun anything-get-previous-candidate-separator-pos ()
  "Return the position of the previous candidate separator from point."
  (previous-single-property-change (point) 'anything-candidate-separator))


(defun anything-pos-header-line-p ()
  "Return t if the current line is a header line."
  (or (get-text-property (line-beginning-position) 'anything-header)
      (get-text-property (line-beginning-position) 'anything-header-separator)))

(defun anything-pos-candidate-separator-p ()
  "Return t if the current line is a candidate separator."
  (get-text-property (line-beginning-position) 'anything-candidate-separator))

;; (@* "Core: error handling")
(defun anything-log-error (&rest args)
  "Accumulate error messages into `anything-issued-errors'."
  (let ((msg (apply 'format args)))
    (unless (member msg anything-issued-errors)
      (add-to-list 'anything-issued-errors msg))))

(defun anything-print-error-messages ()
  "Print error messages in `anything-issued-errors'."
  (message "%s" (mapconcat 'identity (reverse anything-issued-errors) "\n")))


;; (@* "Core: help")
(defun anything-help-internal (bufname insert-content-fn)
  "Show long message during `anything' session."
  (save-window-excursion
    (select-window (anything-window))
    (delete-other-windows)
    (switch-to-buffer (get-buffer-create bufname))
    (setq mode-line-format "%b (SPC,C-v:NextPage  b,M-v:PrevPage  other:Exit)")
    (setq cursor-type nil)
    (erase-buffer)
    (funcall insert-content-fn)
    (goto-char 1)
    (ignore-errors
      (loop for event = (read-event) do
            (case event
              ((?\C-v ? )  (scroll-up))
              ((?\M-v ?b) (scroll-down))
              (t (return)))))))

(defun anything-help ()
  "Help of `anything'."
  (interactive)
  (anything-help-internal
   " *Anything Help*"
   (lambda ()
     (insert (substitute-command-keys
              (anything-interpret-value anything-help-message)))
     (org-mode))))

(defun anything-debug-output ()
  "Show all anything-related variables at this time."
  (interactive)
  (anything-help-internal " *Anything Debug*" 'anything-debug-output-function))

(defun anything-debug-output-function (&optional vars)
  (message "Calculating all anything-related values...")
  (insert "If you debug some variables or forms, set `anything-debug-forms'
to a list of forms.\n\n")
  (dolist (v (or vars
                 anything-debug-forms
                 (apropos-internal "^anything-" 'boundp)))
    (insert "** "
            (pp-to-string v) "\n"
            (pp-to-string (eval v)) "\n"))
    (message "Calculating all anything-related values...Done")
)

;; (@* "Core: misc")
(defun anything-kill-buffer-hook ()
  "Remove tick entry from `anything-tick-hash' when killing a buffer."
  (loop for key being the hash-keys in anything-tick-hash
        if (string-match (format "^%s/" (regexp-quote (buffer-name))) key)
        do (remhash key anything-tick-hash)))
(add-hook 'kill-buffer-hook 'anything-kill-buffer-hook)

(defun anything-maybe-fit-frame ()
  "Fit anything frame to its buffer, and put it at top right of display.

It is disabled by default because some flickering occurred in some environment.
To enable fitting, set both `anything-inhibit-fit-frame-flag' and
 `fit-frame-inhibit-fitting' to nil.
You can set user options `fit-frame-max-width-percent' and
`fit-frame-max-height-percent' to control max frame size."
  (declare (warn (unresolved 0)))
  (when (and (require 'fit-frame nil t)
             (boundp 'fit-frame-inhibit-fitting-flag)
             (not anything-inhibit-fit-frame-flag)
             (not fit-frame-inhibit-fitting-flag)
             (anything-window))
    (ignore-errors
      (with-anything-window
        (fit-frame nil nil nil t)
        (modify-frame-parameters
         (selected-frame)
         `((left . ,(- (x-display-pixel-width) (+ (frame-pixel-width) 7)))
           (top . 0))))))) ; The (top . 0) shouldn't be necessary (Emacs bug).

(defun anything-preselect (candidate-or-regexp)
  (when candidate-or-regexp
    (with-anything-window
      (goto-char (point-min))
      ;; go to first candidate of first source
      (forward-line 1)
      (let ((start (point)))
        (unless (or (re-search-forward (concat "^" (regexp-quote candidate-or-regexp) "$") nil t)
                (progn (goto-char start)
                       (re-search-forward candidate-or-regexp nil t)))
          (goto-char start))
        (anything-mark-current-line)))))

(defun anything-delete-current-selection ()
  "Delete the currently selected item."
  (interactive)
  (with-anything-window
    (cond ((anything-pos-multiline-p)
           (anything-aif (anything-get-next-candidate-separator-pos)
               (delete-region (point-at-bol)
                              (1+ (progn (goto-char it) (point-at-eol))))
             ;; last candidate
             (goto-char (anything-get-previous-candidate-separator-pos))
             (delete-region (point-at-bol) (point-max)))
           (when (eobp)
             (goto-char (or (anything-get-previous-candidate-separator-pos)
                            (point-min)))
             (forward-line 1)))
          (t
           (delete-region (point-at-bol) (1+ (point-at-eol)))
           (when (eobp) (forward-line -1))))
    (anything-mark-current-line)))

(defun anything-edit-current-selection-1 (func)
  (with-anything-window
    (beginning-of-line)
    (let ((realvalue (get-text-property (point) 'anything-realvalue)))
      (funcall func)
      (beginning-of-line)
      (and realvalue
           (put-text-property (point) (point-at-eol) 'anything-realvalue realvalue))
      (anything-mark-current-line))))

(defmacro anything-edit-current-selection (&rest forms)
  "Evaluate FORMS at current selection in the anything buffer.
You can edit the line."
  `(anything-edit-current-selection-1
    (lambda () ,@forms)))
(put 'anything-edit-current-selection 'lisp-indent-function 0)

(defun anything-delete-minibuffer-content ()
  "Same as `delete-minibuffer-contents' but this is a command."
  (interactive)
  (delete-minibuffer-contents))

;; (@* "Built-in plug-in: type")
(defun anything-compile-source--type (source)
  (anything-aif (assoc-default 'type source)
      (append source (assoc-default it anything-type-attributes) nil)
    source))

;; `define-anything-type-attribute' is public API.

(defun anything-add-type-attribute (type definition)
  (anything-aif (assq type anything-type-attributes)
      (setq anything-type-attributes (delete it anything-type-attributes)))
  (push (cons type definition) anything-type-attributes))

(defvar anything-types nil)
(defun anything-document-type-attribute (type doc)
  (add-to-list 'anything-types type t)
  (put type 'anything-typeattrdoc
       (concat "- " (symbol-name type) "\n\n" doc "\n")))

(defadvice documentation-property (after anything-document-type-attribute activate)
  "Hack to display type attributes' documentation as `anything-type-attributes' docstring."
  (when (eq symbol 'anything-type-attributes)
    (setq ad-return-value
          (concat ad-return-value "\n\n++++ Types currently defined ++++\n"
                  (mapconcat (lambda (sym) (get sym 'anything-typeattrdoc))
                             anything-types "\n")))))

;; (@* "Built-in plug-in: dummy")
(defun anything-dummy-candidate (candidate source)
  ;; `source' is defined in filtered-candidate-transformer
  (list anything-pattern))  

(defun anything-compile-source--dummy (source)
  (if (assoc 'dummy source)
      (append source
              '((candidates "dummy")
                (accept-empty)
                (match identity)
                (filtered-candidate-transformer . anything-dummy-candidate)
                (disable-shortcuts)
                (volatile)))
    source))

;; (@* "Built-in plug-in: disable-shortcuts")
(defvar anything-orig-enable-shortcuts nil)
(defun anything-save-enable-shortcuts ()
  (anything-once
   (lambda () (setq anything-orig-enable-shortcuts anything-enable-shortcuts
                    anything-enable-shortcuts nil))))
(defun anything-compile-source--disable-shortcuts (source)
  (if (assoc 'disable-shortcuts source)
      (append `((init ,@(anything-mklist (assoc-default 'init source))
                      anything-save-enable-shortcuts)
                (resume ,@(anything-mklist (assoc-default 'resume source))
                        anything-save-enable-shortcuts)
                (cleanup ,@(anything-mklist (assoc-default 'cleanup source))
                         (lambda () (setq anything-enable-shortcuts anything-orig-enable-shortcuts))))
              source)
    source))

;; (@* "Built-in plug-in: candidates-in-buffer")
(defun anything-candidates-in-buffer ()
  "Get candidates from the candidates buffer according to `anything-pattern'.

BUFFER is `anything-candidate-buffer' by default.  Each
candidate must be placed in one line.  This function is meant to
be used in candidates-in-buffer or candidates attribute of an
anything source.  Especially fast for many (1000+) candidates.

eg.
 '((name . \"many files\")
   (init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
                        (insert-many-filenames))))
   (search re-search-forward)  ; optional
   (candidates-in-buffer)
   (type . file))

+===============================================================+
| The new way of making and narrowing candidates: Using buffers |
+===============================================================+

By default, `anything' makes candidates by evaluating the
candidates function, then narrows them by `string-match' for each
candidate.

But this way is very slow for many candidates. The new way is
storing all candidates in a buffer and narrowing them by
`re-search-forward'. Search function is customizable by search
attribute. The important point is that buffer processing is MUCH
FASTER than string list processing and is the Emacs way.

The init function writes all candidates to a newly-created
candidate buffer.  The candidates buffer is created or specified
by `anything-candidate-buffer'.  Candidates are stored in a line.

The candidates function narrows all candidates, IOW creates a
subset of candidates dynamically. It is the task of
`anything-candidates-in-buffer'.  As long as
`anything-candidate-buffer' is used,`(candidates-in-buffer)' is
sufficient in most cases.

Note that `(candidates-in-buffer)' is shortcut of three attributes:
  (candidates . anything-candidates-in-buffer)
  (volatile)
  (match identity)
And `(candidates-in-buffer . func)' is shortcut of three attributes:
  (candidates . func)
  (volatile)
  (match identity)
The expansion is performed in `anything-get-sources'.

The candidates-in-buffer attribute implies the volatile attribute.
The volatile attribute is needed because `anything-candidates-in-buffer'
creates candidates dynamically and need to be called everytime
`anything-pattern' changes.

Because `anything-candidates-in-buffer' plays the role of `match' attribute
function, specifying `(match identity)' makes the source slightly faster.

To customize `anything-candidates-in-buffer' behavior, use search,
get-line and search-from-end attributes. See also `anything-sources' docstring.
"
  (declare (special source))
  (anything-candidates-in-buffer-1 (anything-candidate-buffer)
                                   anything-pattern
                                   (or (assoc-default 'get-line source)
                                       #'buffer-substring-no-properties)
                                   ;; use external variable `source'.
                                   (or (assoc-default 'search source)
                                       (if (assoc 'search-from-end source)
                                           '(re-search-backward)
                                         '(re-search-forward)))
                                   (anything-candidate-number-limit source)
                                   (assoc 'search-from-end source)))

(defun* anything-candidates-in-buffer-1 (buffer &optional (pattern anything-pattern) (get-line-fn 'buffer-substring-no-properties) (search-fns '(re-search-forward)) (limit anything-candidate-number-limit) search-from-end)
  ;; buffer == nil when candidates buffer does not exist.
  (when buffer
    (with-current-buffer buffer
      (let ((start-point (if search-from-end (point-max) (point-min)))
            (next-line-fn (if search-from-end
                              (lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
                            #'forward-line))
            (endp (if search-from-end #'bobp #'eobp)))
        (goto-char (1- start-point))
        (if (string= pattern "")
            (delq nil (loop until (funcall endp)
                                    for i from 1 to limit
                                    collecting (funcall get-line-fn (point-at-bol) (point-at-eol))
                                    do (funcall next-line-fn 1)))
                    
          (let ((i 1)
                (next-line-fn (if search-from-end
                                  (lambda (x) (goto-char (max (point-at-bol) 1)))
                                #'forward-line))
                buffer-read-only
                matches exit newmatches)
            (progn
              (goto-char (point-min))
              (insert "\n")
              (goto-char (point-max))
              (insert "\n")
              (setq start-point (if search-from-end (point-max) (point-min)))
              (clrhash anything-cib-hash)
              (unwind-protect
                  (dolist (searcher search-fns)
                    (goto-char start-point)
                    (setq newmatches nil)
                    (loop while (funcall searcher pattern nil t)
                          if (or (funcall endp) (< limit i))
                          do (setq exit t) (return)
                          else do
                          (let ((cand (funcall get-line-fn (point-at-bol) (point-at-eol))))
                            (unless (gethash cand anything-cib-hash)
                              (puthash cand t anything-cib-hash)
                              (incf i)
                              (push cand newmatches)))
                          (funcall next-line-fn 1))
                    (setq matches (append matches (nreverse newmatches)))
                    (if exit (return)))
                (goto-char (point-min))
                (delete-char 1)
                (goto-char (1- (point-max)))
                (delete-char 1)
                           
                (set-buffer-modified-p nil)))
            (delq nil matches)))))))


(defun anything-candidate-buffer (&optional create-or-buffer)
  "Register and return a buffer containing candidates of current source.
`anything-candidate-buffer' searches buffer-local candidates buffer first,
then global candidates buffer.

Acceptable values of CREATE-OR-BUFFER:

- nil (omit)
  Only return the candidates buffer.
- a buffer
  Register a buffer as a candidates buffer.
- 'global
  Create a new global candidates buffer,
  named \" *anything candidates:SOURCE*\".
- other non-nil value
  Create a new global candidates buffer,
  named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\".
"
  (let* ((gbufname (format " *anything candidates:%s*" anything-source-name))
         (lbufname (concat gbufname (buffer-name anything-current-buffer)))
         buf)
    (when create-or-buffer
      (if (bufferp create-or-buffer)
          (setq anything-candidate-buffer-alist
                (cons (cons anything-source-name create-or-buffer)
                      (delete (assoc anything-source-name anything-candidate-buffer-alist)
                              anything-candidate-buffer-alist)))
        (add-to-list 'anything-candidate-buffer-alist
                     (cons anything-source-name create-or-buffer))
        (when (eq create-or-buffer 'global)
          (loop for b in (buffer-list)
                if (string-match (format "^%s" (regexp-quote gbufname)) (buffer-name b))
                do (kill-buffer b)))
        (with-current-buffer
            (get-buffer-create (if (eq create-or-buffer 'global) gbufname lbufname))
          (buffer-disable-undo)
          (erase-buffer)
          (font-lock-mode -1))))
    (or (get-buffer lbufname)
        (get-buffer gbufname)
        (anything-aif (assoc-default anything-source-name anything-candidate-buffer-alist)
            (and (buffer-live-p it) it)))))

(defun anything-compile-source--candidates-in-buffer (source)
  (anything-aif (assoc 'candidates-in-buffer source)
      (append source `((candidates . ,(or (cdr it) 'anything-candidates-in-buffer))
                       (volatile) (match identity)))
    source))

;; (@* "Utility: resplit anything window")
(defun anything-toggle-resplit-window ()
  "Toggle resplit anything window, vertically or horizontally."
  (interactive)
  (with-anything-window
    (let ((before-height (window-height)))
      (delete-window)
      (set-window-buffer
       (select-window (if (= (window-height) before-height)
                          (split-window-vertically)
                        (split-window-horizontally)))
       anything-buffer))))

;; (@* "Utility: select another action by key")
(defun anything-select-nth-action (n)
  "Select the nth action for the currently selected candidate."
  (setq anything-saved-selection (anything-get-selection))
  (unless anything-saved-selection
    (error "Nothing is selected."))
  (setq anything-saved-action (cdr (elt (anything-get-action) n)))
  (anything-exit-minibuffer))

(defun anything-select-2nd-action ()
  "Select the 2nd action for the currently selected candidate."
  (interactive)
  (anything-select-nth-action 1))

(defun anything-select-3rd-action ()
  "Select the 3rd action for the currently selected candidate."
  (interactive)
  (anything-select-nth-action 2))

(defun anything-select-4th-action ()
  "Select the 4th action for the currently selected candidate."
  (interactive)
  (anything-select-nth-action 3))

(defun anything-select-2nd-action-or-end-of-line ()
  "Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
Otherwise goto the end of minibuffer."
  (interactive)
  (if (eolp)
      (anything-select-nth-action 1)
    (end-of-line)))

;; (@* "Utility: Persistent Action")
(defmacro with-anything-display-same-window (&rest body)
  "Make `pop-to-buffer' and `display-buffer' display in the same window."
  `(let ((display-buffer-function 'anything-persistent-action-display-buffer))
     ,@body))
(put 'with-anything-display-same-window 'lisp-indent-function 0)

(defun* anything-execute-persistent-action (&optional (attr 'persistent-action))
  "If a candidate is selected then perform the associated action without quitting anything."
  (interactive)
  (save-selected-window
    (select-window (get-buffer-window (anything-buffer-get)))
    (select-window (setq minibuffer-scroll-window
                         (if (one-window-p t) (split-window)
                           (next-window (selected-window) 1))))
    (let ((anything-in-persistent-action t))
      (with-anything-display-same-window
        (anything-execute-selection-action
         nil
         (or (assoc-default attr (anything-get-current-source))
             (anything-get-action))
         t)
        (run-hooks 'anything-after-persistent-action-hook)))))

(defun anything-persistent-action-display-buffer (buf &optional not-this-window)
  "Make `pop-to-buffer' and `display-buffer' display in the same window in persistent action.
If `anything-persistent-action-use-special-display' is non-nil and
BUF is to be displayed by `special-display-function', use it.
Otherwise ignores `special-display-buffer-names' and `special-display-regexps'."
  (let* ((name (buffer-name buf))
         display-buffer-function pop-up-windows
         (same-window-regexps
          (unless (and anything-persistent-action-use-special-display
                       (or (member name
                                   (mapcar (lambda (x) (or (car-safe x) x)) special-display-buffer-names))
                           (remove-if-not
                            (lambda (x) (string-match (or (car-safe x) x) name))
                            special-display-regexps)))
            '("."))))
    (display-buffer buf not-this-window)))

;; scroll-other-window(-down)? for persistent-action
(defun anything-scroll-other-window-base (command)
  (save-selected-window
    (select-window
     (some-window
      (lambda (w) (not (string= anything-buffer (buffer-name (window-buffer w)))))
      'no-minibuffer 'current-frame))
    (call-interactively command)))

(defun anything-scroll-other-window ()
  "Scroll other window (not *Anything* window) upward."
  (interactive)
  (anything-scroll-other-window-base (lambda ()
                                       (interactive)
                                       (scroll-up anything-scroll-amount))))
(defun anything-scroll-other-window-down ()
  "Scroll other window (not *Anything* window) downward."
  (interactive)
  (anything-scroll-other-window-base (lambda ()
                                       (interactive)
                                       (scroll-down anything-scroll-amount))))

;; (@* "Utility: Visible Mark")
(defface anything-visible-mark
  '((((min-colors 88) (background dark))
     (:background "green1" :foreground "black"))
    (((background dark)) (:background "green" :foreground "black"))
    (((min-colors 88)) (:background "green1"))
    (t (:background "green")))
  "Face for visible mark."
  :group 'anything)
(defvar anything-visible-mark-face 'anything-visible-mark)
(defvar anything-visible-mark-overlays nil)

(defun anything-clear-visible-mark ()
  (mapc 'delete-overlay anything-visible-mark-overlays)
  (setq anything-visible-mark-overlays nil))
(add-hook 'anything-after-initialize-hook 'anything-clear-visible-mark)

;; (defun anything-toggle-visible-mark ()
;;   (interactive)
;;   (with-anything-window
;;     (anything-aif (loop for o in anything-visible-mark-overlays
;;                         when (equal (line-beginning-position) (overlay-start o))
;;                         do (return o))
;;         ;; delete
;;         (progn (delete-overlay it)
;;                (delq it anything-visible-mark-overlays))
;;       (let ((o (make-overlay (line-beginning-position) (1+ (line-end-position)))))
;;         (overlay-put o 'face anything-visible-mark-face)
;;         (overlay-put o 'source (assoc-default 'name (anything-get-current-source)))
;;         (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
;;         (add-to-list 'anything-visible-mark-overlays o)))))

(defvar anything-c-marked-candidate-list nil
  "[OBSOLETE] DO NOT USE!!")
(defvar anything-marked-candidates nil
  "Marked candadates. List of (source . real) pair.")
(defun anything-toggle-visible-mark ()
  (interactive)
  (with-anything-window
    (let ((display (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
          (source (anything-get-current-source))
          (selection (anything-get-selection)))
      (anything-aif (loop for o in anything-visible-mark-overlays
                          when (equal (line-beginning-position) (overlay-start o))
                          do   (return o))
          ;; delete
          (progn
            (setq anything-c-marked-candidate-list
                  (remove
                   display anything-c-marked-candidate-list))
            (setq anything-marked-candidates
                  (remove
                   (cons source selection)
                   anything-marked-candidates))
            (delete-overlay it)
            (setq anything-visible-mark-overlays (delq it anything-visible-mark-overlays)))
        (let ((o (make-overlay (line-beginning-position) (1+ (line-end-position)))))
          (overlay-put o 'face anything-visible-mark-face)
          (overlay-put o 'source (assoc-default 'name source))
          (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
          (add-to-list 'anything-visible-mark-overlays o)
          (push display anything-c-marked-candidate-list)
          (push (cons source selection) anything-marked-candidates)))
      (anything-next-line))))

(defun anything-display-all-visible-marks ()
  "Show all `anything' visible marks strings."
  (interactive)
  (lexical-let ((overlays (reverse anything-visible-mark-overlays)))
    (anything-run-after-quit
     (lambda ()
       (with-output-to-temp-buffer "*anything visible marks*"
         (dolist (o overlays) (princ (overlay-get o 'string))))))))

(defun anything-marked-candidates ()
  "Marked candidates (real value) of current source if any,
otherwise 1-element list of current selection.

It is analogous to `dired-get-marked-files'."
  (if anything-marked-candidates
      (loop with current-src = (anything-get-current-source)
            for (source . real) in (reverse anything-marked-candidates)
            when (eq current-src source)
            collect real)
    (list (anything-get-selection))))

(defun anything-reset-marked-candidates ()
  (setq anything-c-marked-candidate-list nil)
  (setq anything-marked-candidates nil))

(add-hook 'anything-after-initialize-hook 'anything-reset-marked-candidates)
(add-hook 'anything-after-action-hook 'anything-reset-marked-candidates)

(defun anything-revive-visible-mark ()
  (interactive)
  (with-current-buffer anything-buffer
    (loop for o in anything-visible-mark-overlays do
          (goto-char (point-min))
          (let (moved)
            (while (and (not moved)
                        (search-forward (overlay-get o 'string) nil t))
              (forward-line -1)
              (when (and (save-excursion
                           (goto-char (anything-get-previous-header-pos))
                           (equal (overlay-get o 'source)
                                  (buffer-substring (line-beginning-position) (line-end-position))))
                         (not (find-if (lambda (x)
                                         (memq x anything-visible-mark-overlays))
                                       (overlays-at (point)))))
                (move-overlay o (line-beginning-position) (1+ (line-end-position)))
                (setq moved t))
              (forward-line 1))))))
(add-hook 'anything-update-hook 'anything-revive-visible-mark)

(defun anything-next-visible-mark (&optional prev)
  (interactive)
  (with-anything-window
    (block 'exit
      (setq anything-visible-mark-overlays
            (sort* anything-visible-mark-overlays
                   '< :key 'overlay-start))
      (let ((i (position-if (lambda (o) (< (point) (overlay-start o)))
                            anything-visible-mark-overlays)))
        (when prev
          (unless anything-visible-mark-overlays (return-from 'exit nil))
          (if (not i) (setq i (length anything-visible-mark-overlays)))
          (if (equal (point) (overlay-start (nth (1- i) anything-visible-mark-overlays)))
              (setq i (1- i))))
        (when i
          (goto-char (overlay-start (nth (if prev (1- i) i) anything-visible-mark-overlays)))
          (anything-mark-current-line))))))

(defun anything-prev-visible-mark ()
  (interactive)
  (anything-next-visible-mark t))

;; (@* "Utility: `find-file' integration")
(defun anything-quit-and-find-file ()
  "Drop into `find-file' from `anything' like `iswitchb-find-file'.
If current selection is a buffer or a file, `find-file' from its directory."
  (interactive)
  (anything-run-after-quit
   (lambda (f)
     (if (file-exists-p f)
         (let ((default-directory (file-name-directory f)))
           (call-interactively 'find-file))
       (call-interactively 'find-file)))
   (anything-aif (get-buffer (anything-get-selection))
       (buffer-file-name it)
     (expand-file-name (anything-get-selection)))))

;; (@* "Utility: Selection Paste")
(defun anything-yank-selection ()
  "Set minibuffer contents to current selection."
  (interactive)
  (delete-minibuffer-contents)
  (insert (anything-get-selection nil t)))

(defun anything-kill-selection-and-quit ()
  "Store current selection to kill ring.
You can paste it by typing C-y."
  (interactive)
  (anything-run-after-quit
   (lambda (sel)
     (kill-new sel)
     (message "Killed: %s" sel))
   (anything-get-selection nil t)))


;; (@* "Utility: Automatical execution of persistent-action")
(add-to-list 'minor-mode-alist '(anything-follow-mode " AFollow"))
(defun anything-follow-mode ()
  "If this mode is on, persistent action is executed everytime the cursor is moved."
  (interactive)
  (with-current-buffer anything-buffer
    (setq anything-follow-mode (not anything-follow-mode))
    (message "anything-follow-mode is %s"
             (if anything-follow-mode "enabled" "disabled"))))

(defun anything-follow-execute-persistent-action-maybe ()
  "Execute persistent action after `anything-input-idle-delay' secs when `anything-follow-mode' is enabled."
  (and (buffer-local-value 'anything-follow-mode
                           (get-buffer-create anything-buffer))
       (sit-for anything-input-idle-delay)
       (anything-window)
       (anything-get-selection)
       (save-excursion
         (anything-execute-persistent-action))))

;; (@* "Utility: Migrate `anything-sources' to my-anything command")
(defun anything-migrate-sources ()
  "Help to migrate to new `anything' way."
  (interactive)
  (with-current-buffer (get-buffer-create "*anything migrate*")
    (erase-buffer)
    (insert (format "\
Setting `anything-sources' directly is not good because
`anything' is not for one command.  For now, interactive use of
`anything' (M-x anything) is only for demonstration purpose.
So you should define commands calling `anything'.
I help you to migrate to the new way.

The code below is automatically generated from current
`anything-sources' value. You can use the `my-anything' command
now!

Copy and paste it to your .emacs. Then substitute `my-anything'
for `anything' bindings in all `define-key', `local-set-key' and
`global-set-key' calls.

\(defun my-anything ()
  \"Anything command for you.

It is automatically generated by `anything-migrate-sources'.\"
  (interactive)
  (anything-other-buffer
    '%S
    \"*my-anything*\"))
" anything-sources))
    (eval-last-sexp nil)
    (substitute-key-definition 'anything 'my-anything global-map)
    (pop-to-buffer (current-buffer))))

;; (@* "Utility: Incremental search within results (unmaintained)")

(defvar anything-isearch-original-global-map nil
  "Original global map before Anything isearch is started.")

(defvar anything-isearch-original-message-timeout nil
  "Original message timeout before Anything isearch is started.")

(defvar anything-isearch-pattern nil
  "The current isearch pattern.")

(defvar anything-isearch-message-suffix ""
  "Message suffix indicating the current state of the search.")

(defvar anything-isearch-original-point nil
  "Original position of point before isearch is started.")

(defvar anything-isearch-original-window nil
  "Original selected window before isearch is started.")

(defvar anything-isearch-original-cursor-in-non-selected-windows nil
  "Original value of cursor-in-non-selected-windows before isearch is started.")

(defvar anything-isearch-original-post-command-hook nil
  "Original value of post-command-hook before isearch is started.")

(defvar anything-isearch-match-positions nil
  "Stack of positions of matches or non-matches.

It's a list of plists with two properties: `event', the last user
 event, `start', the start position of the current match, and
 `pos', the position of point after that event.

The value of `event' can be the following symbols: `char' if a
character was typed, `error' if a non-matching character was
typed, `search' if a forward search had to be done after a
character, and `search-again' if a search was done for the next
occurrence of the current pattern.")

(defvar anything-isearch-match-start nil
  "Start position of the current match.")


(defun anything-isearch ()
  "Start incremental search within results. (UNMAINTAINED)"
  (interactive)
  (if (zerop (buffer-size (get-buffer (anything-buffer-get))))
      (message "There are no results.")

    (setq anything-isearch-original-message-timeout minibuffer-message-timeout)
    (setq minibuffer-message-timeout nil)

    (setq anything-isearch-original-global-map global-map)

    (condition-case nil
        (progn
          (setq anything-isearch-original-window (selected-window))
          (select-window (anything-window))
          (setq cursor-type t)

          (setq anything-isearch-original-post-command-hook
                (default-value 'post-command-hook))
          (setq-default post-command-hook nil)
          (add-hook 'post-command-hook 'anything-isearch-post-command)

          (use-global-map anything-isearch-map)
          (setq overriding-terminal-local-map anything-isearch-map)

          (setq anything-isearch-pattern "")

          (setq anything-isearch-original-cursor-in-non-selected-windows
                cursor-in-non-selected-windows)
          (setq cursor-in-non-selected-windows nil) 

          (setq anything-isearch-original-point (point-marker))
          (goto-char (point-min))
          (forward-line)
          (anything-mark-current-line)

          (setq anything-isearch-match-positions nil)
          (setq anything-isearch-match-start (point-marker))

          (if anything-isearch-overlay
              ;; make sure the overlay belongs to the anything buffer
              (move-overlay anything-isearch-overlay (point-min) (point-min)
                            (get-buffer (anything-buffer-get)))

            (setq anything-isearch-overlay (make-overlay (point-min) (point-min)))
            (overlay-put anything-isearch-overlay 'face anything-isearch-match-face))

          (setq anything-isearch-message-suffix
                (substitute-command-keys "cancel with \\[anything-isearch-cancel]")))

      (error (anything-isearch-cleanup)))))


(defun anything-isearch-post-command ()
  "Print the current pattern after every command."
  (anything-isearch-message)
  (when (anything-window)
    (with-anything-window
      (move-overlay anything-isearch-overlay anything-isearch-match-start (point)
                    (get-buffer (anything-buffer-get))))))


(defun anything-isearch-printing-char ()
  "Add printing char to the pattern."
  (interactive)
  (let ((char (char-to-string last-command-event)))
    (setq anything-isearch-pattern (concat anything-isearch-pattern char))

    (with-anything-window
      (if (looking-at char)
          (progn
            (push (list 'event 'char
                        'start anything-isearch-match-start
                        'pos (point-marker))
                  anything-isearch-match-positions)
            (forward-char))

        (let ((start (point)))
          (while (and (re-search-forward anything-isearch-pattern nil t)
                      (anything-pos-header-line-p)))
          (if (or (anything-pos-header-line-p)
                  (eq start (point)))
              (progn
                (goto-char start)
                (push (list 'event 'error
                            'start anything-isearch-match-start
                            'pos (point-marker))
                      anything-isearch-match-positions))

            (push (list 'event 'search
                        'start anything-isearch-match-start
                        'pos (copy-marker start))
                  anything-isearch-match-positions)
            (setq anything-isearch-match-start (copy-marker (match-beginning 0))))))
  
      (anything-mark-current-line))))


(defun anything-isearch-again ()
  "Search again for the current pattern"
  (interactive)
  (if (equal anything-isearch-pattern "")
      (setq anything-isearch-message-suffix "no pattern yet")

    (with-anything-window
      (let ((start (point)))
        (while (and (re-search-forward anything-isearch-pattern nil t)
                    (anything-pos-header-line-p)))
        (if (or (anything-pos-header-line-p)
                (eq start (point)))
            (progn
              (goto-char start)
              (unless (eq 'error (plist-get (car anything-isearch-match-positions)
                                            'event))
                (setq anything-isearch-message-suffix "no more matches")))

          (push (list 'event 'search-again
                      'start anything-isearch-match-start
                      'pos (copy-marker start))
                anything-isearch-match-positions)
          (setq anything-isearch-match-start (copy-marker (match-beginning 0)))

          (anything-mark-current-line))))))


(defun anything-isearch-delete ()
  "Undo last event."
  (interactive)
  (unless (equal anything-isearch-pattern "")
    (let ((last (pop anything-isearch-match-positions)))
      (unless (eq 'search-again (plist-get last 'event))
        (setq anything-isearch-pattern
              (substring anything-isearch-pattern 0 -1)))

      (with-anything-window      
        (goto-char (plist-get last 'pos))
        (setq anything-isearch-match-start (plist-get last 'start))
        (anything-mark-current-line)))))


(defun anything-isearch-default-action ()
  "Execute the default action for the selected candidate."
  (interactive)
  (anything-isearch-cleanup)
  (with-current-buffer (anything-buffer-get) (anything-exit-minibuffer)))


(defun anything-isearch-select-action ()
  "Choose an action for the selected candidate."
  (interactive)
  (anything-isearch-cleanup)
  (with-anything-window
    (anything-select-action)))


(defun anything-isearch-cancel ()
  "Cancel Anything isearch."
  (interactive)
  (anything-isearch-cleanup)
  (when (anything-window)
    (with-anything-window
      (goto-char anything-isearch-original-point)
      (anything-mark-current-line))))


(defun anything-isearch-cleanup ()
  "Clean up the mess."
  (setq minibuffer-message-timeout anything-isearch-original-message-timeout)
  (with-current-buffer (anything-buffer-get)
    (setq overriding-terminal-local-map nil)
    (setq cursor-type nil)
    (setq cursor-in-non-selected-windows
          anything-isearch-original-cursor-in-non-selected-windows))
  (when anything-isearch-original-window
    (select-window anything-isearch-original-window))

  (use-global-map anything-isearch-original-global-map)
  (setq-default post-command-hook anything-isearch-original-post-command-hook)
  (when (overlayp anything-isearch-overlay) 
    (delete-overlay anything-isearch-overlay)))


(defun anything-isearch-message ()
  "Print prompt."
  (if (and (equal anything-isearch-message-suffix "")
           (eq (plist-get (car anything-isearch-match-positions) 'event)
               'error))
      (setq anything-isearch-message-suffix "failing"))

  (unless (equal anything-isearch-message-suffix "")
    (setq anything-isearch-message-suffix 
          (concat " [" anything-isearch-message-suffix "]")))

  (message (concat "Search within results: "
                   anything-isearch-pattern
                   anything-isearch-message-suffix))

  (setq anything-isearch-message-suffix ""))


;; (@* "Utility: Iswitchb integration (unmaintained)")

(defvar anything-iswitchb-candidate-selected nil
  "Indicates whether an anything candidate is selected from iswitchb.")

(defvar anything-iswitchb-frame-configuration nil
  "Saved frame configuration, before anything buffer was displayed.")

(defvar anything-iswitchb-saved-keys nil
  "The original in iswitchb before binding anything keys.")


(defun anything-iswitchb-setup ()
  "Integrate anything completion into iswitchb (UNMAINTAINED).

If the user is idle for `anything-iswitchb-idle-delay' seconds
after typing something into iswitchb then anything candidates are
shown for the current iswitchb input.

ESC cancels anything completion and returns to normal iswitchb.

Some key bindings in `anything-map' are modified.
See also `anything-iswitchb-setup-keys'."
  (interactive)

  (require 'iswitchb)

  ;; disable timid completion during iswitchb
  (put 'iswitchb-buffer 'timid-completion 'disabled)
  (add-hook 'minibuffer-setup-hook  'anything-iswitchb-minibuffer-setup)

  (defadvice iswitchb-visit-buffer
    (around anything-iswitchb-visit-buffer activate)
    (if anything-iswitchb-candidate-selected
        (anything-execute-selection-action)
      ad-do-it))

  (defadvice iswitchb-possible-new-buffer
    (around anything-iswitchb-possible-new-buffer activate)
    (if anything-iswitchb-candidate-selected
        (anything-execute-selection-action)
      ad-do-it))
  (anything-iswitchb-setup-keys)
  (message "Iswitchb integration is activated."))

(defun anything-iswitchb-setup-keys ()
  "Modify `anything-map' for anything-iswitchb users.

C-p is used instead of M-p, because anything uses ESC
 (currently hardcoded) for `anything-iswitchb-cancel-anything' and
Emacs handles ESC and Meta as synonyms, so ESC overrides
other commands with Meta prefix.

Note that iswitchb uses M-p and M-n by default for history
navigation, so you should bind C-p and C-n in
`iswitchb-mode-map' if you use the history keys and don't want
to use different keys for iswitchb while anything is not yet
kicked in. These keys are not bound automatically by anything
in `iswitchb-mode-map' because they (C-n at least) already have
a standard iswitchb binding which you might be accustomed to.

Binding M-s is used instead of C-s, because C-s has a binding in
iswitchb.  You can rebind it AFTER `anything-iswitchb-setup'.

Unbind C-r to prevent problems during anything-isearch."
  (define-key anything-map (kbd "C-s") nil)
  (define-key anything-map (kbd "M-p") nil)
  (define-key anything-map (kbd "M-n") nil)
  (define-key anything-map (kbd "M-v") nil)
  (define-key anything-map (kbd "C-v") nil)
  (define-key anything-map (kbd "C-p") 'anything-previous-history-element)
  (define-key anything-map (kbd "C-n") 'anything-next-history-element)
  (define-key anything-map (kbd "M-s") nil)
  (define-key anything-map (kbd "M-s") 'anything-isearch)
  (define-key anything-map (kbd "C-r") nil))

(defun anything-iswitchb-minibuffer-setup ()
  (when (eq this-command 'iswitchb-buffer)
    (add-hook 'minibuffer-exit-hook  'anything-iswitchb-minibuffer-exit)

    (setq anything-iswitchb-frame-configuration nil)
    (setq anything-iswitchb-candidate-selected nil)
    (add-hook 'anything-update-hook 'anything-iswitchb-handle-update)

    (anything-initialize)
    
    (add-hook 'post-command-hook 'anything-iswitchb-check-input)))


(defun anything-iswitchb-minibuffer-exit ()
  (remove-hook 'minibuffer-exit-hook  'anything-iswitchb-minibuffer-exit)
  (remove-hook 'post-command-hook 'anything-iswitchb-check-input)
  (remove-hook 'anything-update-hook 'anything-iswitchb-handle-update)

  (anything-cleanup)

  (when anything-iswitchb-frame-configuration
    (anything-set-frame/window-configuration anything-iswitchb-frame-configuration)
    (setq anything-iswitchb-frame-configuration nil)))


(defun anything-iswitchb-check-input ()
  "Extract iswitchb input and check if it needs to be handled."
  (declare (special iswitchb-text))
  (if (or anything-iswitchb-frame-configuration
          (sit-for anything-iswitchb-idle-delay))
      (anything-check-new-input iswitchb-text)))


(defun anything-iswitchb-handle-update ()
  "Pop up the anything buffer if it's not empty and it's not
shown yet and bind anything commands in iswitchb."
  (unless (or (equal (buffer-size (get-buffer anything-buffer)) 0)
              anything-iswitchb-frame-configuration)
    (setq anything-iswitchb-frame-configuration (anything-current-frame/window-configuration))

    (save-selected-window 
      (if (not anything-samewindow)
          (pop-to-buffer anything-buffer)

        (select-window (get-lru-window))
        (switch-to-buffer anything-buffer)))

    (with-current-buffer (window-buffer (active-minibuffer-window))
      (let* ((anything-prefix "anything-")
             (prefix-length (length anything-prefix))
             (commands 
              (delete-dups
               (remove-if 'null
                          (mapcar 
                           (lambda (binding)
                             (let ((command (cdr binding)))
                               (when (and (symbolp command)
                                          (eq (compare-strings 
                                               anything-prefix 
                                               0 prefix-length
                                               (symbol-name command)
                                               0 prefix-length)
                                              t))
                                 command)))
                           (cdr anything-map)))))
             (bindings (mapcar (lambda (command)
                                 (cons command 
                                       (where-is-internal command anything-map)))
                               commands)))

        (push (list 'anything-iswitchb-cancel-anything (kbd "<ESC>"))
              bindings)

        (setq anything-iswitchb-saved-keys nil)

      (let* ((iswitchb-prefix "iswitchb-")
             (prefix-length (length iswitchb-prefix)))
        (dolist (binding bindings)
          (dolist (key (cdr binding))
            (let ((old-command (lookup-key (current-local-map) key)))
              (unless (and anything-iswitchb-dont-touch-iswithcb-keys
                           (symbolp old-command)
                           (eq (compare-strings iswitchb-prefix 
                                                0 prefix-length
                                                (symbol-name old-command)
                                                0 prefix-length)
                               t))
                (push (cons key old-command)
                      anything-iswitchb-saved-keys)
                (define-key (current-local-map) key (car binding)))))))))))


(defun anything-iswitchb-cancel-anything ()
  "Cancel anything completion and return to standard iswitchb."
  (interactive)
  (save-excursion
    (dolist (binding anything-iswitchb-saved-keys)
      (define-key (current-local-map) (car binding) (cdr binding)))
    (anything-iswitchb-minibuffer-exit)))

;; (@* "Compatibility")

;; Copied assoc-default from XEmacs version 21.5.12
(unless (fboundp 'assoc-default)
  (defun assoc-default (key alist &optional test default)
    "Find object KEY in a pseudo-alist ALIST.
ALIST is a list of conses or objects.  Each element (or the element's car,
if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
If that is non-nil, the element matches;
then `assoc-default' returns the element's cdr, if it is a cons,
or DEFAULT if the element is not a cons.

If no element matches, the value is nil.
If TEST is omitted or nil, `equal' is used."
    (let (found (tail alist) value)
      (while (and tail (not found))
        (let ((elt (car tail)))
          (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
            (setq found t value (if (consp elt) (cdr elt) default))))
        (setq tail (cdr tail)))
      value)))

;; Function not available in XEmacs, 
(unless (fboundp 'minibuffer-contents)
  (defun minibuffer-contents ()
    "Return the user input in a minbuffer as a string.
The current buffer must be a minibuffer."
    (field-string (point-max)))

  (defun delete-minibuffer-contents  ()
    "Delete all user input in a minibuffer.
The current buffer must be a minibuffer."
    (delete-field (point-max))))

;; Function not available in older Emacs (<= 22.1).
(unless (fboundp 'buffer-chars-modified-tick)
  (defun buffer-chars-modified-tick (&optional buffer)
    "Return BUFFER's character-change tick counter.
Each buffer has a character-change tick counter, which is set to the
value of the buffer's tick counter (see `buffer-modified-tick'), each
time text in that buffer is inserted or deleted.  By comparing the
values returned by two individual calls of `buffer-chars-modified-tick',
you can tell whether a character change occurred in that buffer in
between these calls.  No argument or nil as argument means use current
buffer as BUFFER."
    (with-current-buffer (or buffer (current-buffer))
      (if (listp buffer-undo-list)
          (length buffer-undo-list)
        (buffer-modified-tick)))))

;;(@* "Attribute Documentation")
(defun anything-describe-anything-attribute (anything-attribute)
  "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol)."
  (interactive (list (intern
                      (completing-read
                       "Describe anything attribute: "
                       (mapcar 'symbol-name anything-additional-attributes)))))
  (with-output-to-temp-buffer "*Help*"
    (princ (get anything-attribute 'anything-attrdoc))))

(anything-document-attribute 'name "mandatory"
  "  The name of the source. It is also the heading which appears
  above the list of matches from the source. Must be unique. ")
(anything-document-attribute 'header-name "optional"
  "  A function returning the display string of the header. Its
  argument is the name of the source. This attribute is useful to
  add an additional information with the source name. ")
(anything-document-attribute 'candidates "mandatory if candidates-in-buffer attribute is not provided"
  "  Specifies how to retrieve candidates from the source. It can
  either be a variable name, a function called with no parameters
  or the actual list of candidates.

  The list must be a list whose members are strings, symbols
  or (DISPLAY . REAL) pairs.

  In case of (DISPLAY . REAL) pairs, the DISPLAY string is shown
  in the Anything buffer, but the REAL one is used as action
  argument when the candidate is selected. This allows a more
  readable presentation for candidates which would otherwise be,
  for example, too long or have a common part shared with other
  candidates which can be safely replaced with an abbreviated
  string for display purposes.

  Note that if the (DISPLAY . REAL) form is used then pattern
  matching is done on the displayed string, not on the real
  value.

  If the candidates have to be retrieved asynchronously (for
  example, by an external command which takes a while to run)
  then the function should start the external command
  asynchronously and return the associated process object.
  Anything will take care of managing the process (receiving the
  output from it, killing it if necessary, etc.). The process
  should return candidates matching the current pattern (see
  variable `anything-pattern'.)

  Note that currently results from asynchronous sources appear
  last in the anything buffer regardless of their position in
  `anything-sources'. ")
(anything-document-attribute 'action "mandatory if type attribute is not provided"
  "  It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
  FUNCTION is called with one parameter: the selected candidate.

  An action other than the default can be chosen from this list
  of actions for the currently selected candidate (by default
  with TAB). The DISPLAY string is shown in the completions
  buffer and the FUNCTION is invoked when an action is
  selected. The first action of the list is the default. ")
(anything-document-attribute 'type "optional if action attribute is provided"
  "  Indicates the type of the items the source returns. 

  Merge attributes not specified in the source itself from
  `anything-type-attributes'.

  This attribute is implemented by plug-in. ")
(anything-document-attribute 'init "optional"
  "  Function called with no parameters when anything is started. It
  is useful for collecting current state information which can be
  used to create the list of candidates later.

  For example, if a source needs to work with the current
  directory then it can store its value here, because later
  anything does its job in the minibuffer and in the
  `anything-buffer' and the current directory can be different
  there. ")
(anything-document-attribute 'delayed-init "optional"
  "  Function called with no parameters before candidate function is
  called.  It is similar with `init' attribute, but its
  evaluation is deferred. It is useful to combine with ")
(anything-document-attribute 'match "optional"
  "  List of functions called with one parameter: a candidate. The
  function should return non-nil if the candidate matches the
  current pattern (see variable `anything-pattern').

  This attribute allows the source to override the default
  pattern matching based on `string-match'. It can be used, for
  example, to implement a source for file names and do the
  pattern matching on the basename of files, since it's more
  likely one is typing part of the basename when searching for a
  file, instead of some string anywhere else in its path.

  If the list contains more than one function then the list of
  matching candidates from the source is constructed by appending
  the results after invoking the first function on all the
  potential candidates, then the next function, and so on. The
  matching candidates supplied by the first function appear first
  in the list of results and then results from the other
  functions, respectively.

  This attribute has no effect for asynchronous sources (see
  attribute `candidates'), since they perform pattern matching
  themselves. ")
(anything-document-attribute 'candidate-transformer "optional"
  "  It's a function or a list of functions called with one argument
  when the completion list from the source is built. The argument
  is the list of candidates retrieved from the source. The
  function should return a transformed list of candidates which
  will be used for the actual completion.  If it is a list of
  functions, it calls each function sequentially.

  This can be used to transform or remove items from the list of
  candidates.

  Note that `candidates' is run already, so the given transformer
  function should also be able to handle candidates with (DISPLAY
  . REAL) format. ")
(anything-document-attribute 'filtered-candidate-transformer "optional"
  "  It has the same format as `candidate-transformer', except the
  function is called with two parameters: the candidate list and
  the source.

  This transformer is run on the candidate list which is already
  filtered by the current pattern. While `candidate-transformer'
  is run only once, it is run every time the input pattern is
  changed.

  It can be used to transform the candidate list dynamically, for
  example, based on the current pattern.

  In some cases it may also be more efficent to perform candidate
  transformation here, instead of with `candidate-transformer'
  even if this transformation is done every time the pattern is
  changed.  For example, if a candidate set is very large then
  `candidate-transformer' transforms every candidate while only
  some of them will actually be dislpayed due to the limit
  imposed by `anything-candidate-number-limit'.

  Note that `candidates' and `candidate-transformer' is run
  already, so the given transformer function should also be able
  to handle candidates with (DISPLAY . REAL) format.

  This option has no effect for asynchronous sources. (Not yet,
  at least. ")
(anything-document-attribute 'action-transformer "optional"
  "  It's a function or a list of functions called with two
  arguments when the action list from the source is
  assembled. The first argument is the list of actions, the
  second is the current selection.  If it is a list of functions,
  it calls each function sequentially.

  The function should return a transformed action list.

  This can be used to customize the list of actions based on the
  currently selected candidate. ")
(anything-document-attribute 'pattern-transformer "optional"
  "  It's a function or a list of functions called with one argument
  before computing matches. Its argument is `anything-pattern'.
  Functions should return transformed `anything-pattern'.

  It is useful to change interpretation of `anything-pattern'. ")
(anything-document-attribute 'delayed "optional"
  "  Candidates from the source are shown only if the user stops
  typing and is idle for `anything-idle-delay' seconds. ")
(anything-document-attribute 'volatile "optional"
  "  Indicates the source assembles the candidate list dynamically,
  so it shouldn't be cached within a single Anything
  invocation. It is only applicable to synchronous sources,
  because asynchronous sources are not cached. ")
(anything-document-attribute 'requires-pattern "optional"
  "  If present matches from the source are shown only if the
  pattern is not empty. Optionally, it can have an integer
  parameter specifying the required length of input which is
  useful in case of sources with lots of candidates. ")
(anything-document-attribute 'persistent-action "optional"
  "  Function called with one parameter; the selected candidate.

  An action performed by `anything-execute-persistent-action'.
  If none, use the default action. ")
(anything-document-attribute 'candidates-in-buffer "optional"
  "  Shortcut attribute for making and narrowing candidates using
  buffers.  This newly-introduced attribute prevents us from
  forgetting to add volatile and match attributes.

  See docstring of `anything-candidates-in-buffer'.

  (candidates-in-buffer) is equivalent of three attributes:
    (candidates . anything-candidates-in-buffer)
    (volatile)
    (match identity)

  (candidates-in-buffer . candidates-function) is equivalent of:
    (candidates . candidates-function)
    (volatile)
    (match identity)

  This attribute is implemented by plug-in. ")
(anything-document-attribute 'search "optional"
  "  List of functions like `re-search-forward' or `search-forward'.
  Buffer search function used by `anything-candidates-in-buffer'.
  By default, `anything-candidates-in-buffer' uses `re-search-forward'.
  This attribute is meant to be used with
  (candidates . anything-candidates-in-buffer) or
  (candidates-in-buffer) in short. ")
(anything-document-attribute 'search-from-end "optional"
  "  Make `anything-candidates-in-buffer' search from the end of buffer.
  If this attribute is specified, `anything-candidates-in-buffer' uses
  `re-search-backward' instead. ")
(anything-document-attribute 'get-line "optional"
  "  A function like `buffer-substring-no-properties' or `buffer-substring'.
  This function converts point of line-beginning and point of line-end,
  which represents a candidate computed by `anything-candidates-in-buffer'.
  By default, `anything-candidates-in-buffer' uses
  `buffer-substring-no-properties'. ")
(anything-document-attribute 'display-to-real "optional"
  "  Function called with one parameter; the selected candidate.

  The function transforms the selected candidate, and the result
  is passed to the action function.  The display-to-real
  attribute provides another way to pass other string than one
  shown in Anything buffer.

  Traditionally, it is possible to make candidates,
  candidate-transformer or filtered-candidate-transformer
  function return a list with (DISPLAY . REAL) pairs. But if REAL
  can be generated from DISPLAY, display-to-real is more
  convenient and faster. ")
(anything-document-attribute 'real-to-display "optional"
  "  Function called with one parameter; the selected candidate.

  The inverse of display-to-real attribute.

  The function transforms the selected candidate, which is passed
  to the action function, for display.  The real-to-display
  attribute provides the other way to pass other string than one
  shown in Anything buffer.

  Traditionally, it is possible to make candidates,
  candidate-transformer or filtered-candidate-transformer
  function return a list with (DISPLAY . REAL) pairs. But if
  DISPLAY can be generated from REAL, real-to-display is more
  convenient.

  Note that DISPLAY parts returned from candidates /
  candidate-transformer are IGNORED as the name `display-to-real'
  says. ")
(anything-document-attribute 'cleanup "optional"
  "  Function called with no parameters when *anything* buffer is closed. It
  is useful for killing unneeded candidates buffer.

  Note that the function is executed BEFORE performing action. ")
(anything-document-attribute 'candidate-number-limit "optional"
  "  Override `anything-candidate-number-limit' only for this source. ")
(anything-document-attribute 'accept-empty "optional"
  "  Pass empty string \"\" to action function. ")
(anything-document-attribute 'disable-shortcuts "optional"
  "  Disable `anything-enable-shortcuts' in current `anything' session.

  This attribute is implemented by plug-in. ")
(anything-document-attribute 'dummy "optional"
  "  Set `anything-pattern' to candidate. If this attribute is
  specified, The candidates attribute is ignored.

  This attribute is implemented by plug-in.
  This plug-in implies disable-shortcuts plug-in. ")
(anything-document-attribute 'multiline "optional"
  "  Enable to selection multiline candidates. ")
(anything-document-attribute 'update "optional"
  "  Function called with no parameters when \\<anything-map>\\[anything-force-update] is pressed. ")
(anything-document-attribute 'mode-line "optional"
  "  source local `anything-mode-line-string'. (included in `mode-line-format')
  It accepts also variable/function name. ")
(anything-document-attribute 'header-line "optional"
  "  source local `header-line-format'.
  It accepts also variable/function name. ")
(anything-document-attribute 'resume "optional" "  Function called with no parameters when `anything-resume' is started.")

;; (@* "Bug Report")
(defvar anything-maintainer-mail-address
  (concat "rubiki" "tch@ru" "by-lang.org"))
(defvar anything-bug-report-salutation
  "Describe bug below, using a precise recipe.

When I executed M-x ...

How to send a bug report:
  1) Be sure to use the LATEST version of anything.el.
  2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
  3) Use Lisp version instead of compiled one: (load \"anything.el\")
  4) If you got an error, please paste *Backtrace* buffer.
  5) Type C-c C-c to send.
# If you are a Japanese, please write in Japanese:-)")
(defvar anything-no-dump-variables
  '(anything-candidate-buffer-alist
    anything-digit-overlays
    anything-help-message
    anything-candidate-cache
    )
  "Variables not to dump in bug report.")

(defun anything-dumped-variables-in-bug-report ()
  (let ((hash (make-hash-table)))
    (loop for var in (apropos-internal "anything-" 'boundp)
          for vname = (symbol-name var)
          unless (or (string-match "-map$" vname)
                     (string-match "^anything-c-source-" vname)
                     (string-match "-hash$" vname)
                     (string-match "-face$" vname)
                     (memq var anything-no-dump-variables))
          collect var)))

(defun anything-send-bug-report ()
  "Send a bug report of anything.el."
  (interactive)
  (with-current-buffer (or anything-last-buffer
                           (current-buffer))
    (reporter-submit-bug-report
     anything-maintainer-mail-address
     "anything.el"
     (anything-dumped-variables-in-bug-report)
     nil nil
     anything-bug-report-salutation)))

(defun anything-send-bug-report-from-anything ()
  "Send a bug report of anything.el in anything session."
  (interactive)
  (anything-run-after-quit 'anything-send-bug-report))

;; (@* "Unit Tests")

(defun* anything-test-candidates (sources &optional (input "") (compile-source-functions anything-compile-source-functions-default))
  "Test helper function for anything.
Given pseudo `anything-sources' and `anything-pattern', returns list like
  ((\"source name1\" (\"candidate1\" \"candidate2\"))
   (\"source name2\" (\"candidate3\" \"candidate4\")))
"
  (let ((anything-test-mode t)
        anything-enable-shortcuts
        anything-candidate-cache
        (anything-sources (anything-normalize-sources sources))
        (anything-compile-source-functions compile-source-functions)
        anything-before-initialize-hook
        anything-after-initialize-hook
        anything-update-hook
        anything-test-candidate-list)
    (get-buffer-create anything-buffer)

    (anything-initialize)
    (setq anything-input input anything-pattern input)
    (anything-update)
    ;; test-mode spec: select 1st candidate!
    (with-current-buffer anything-buffer
      (forward-line 1)
      (anything-mark-current-line))
    (prog1
        anything-test-candidate-list
      (anything-cleanup))))

(defmacro anything-test-update (sources pattern)
  "Test helper macro for anything. It is meant for testing *anything* buffer contents."
  `(progn (stub anything-get-sources => ,sources)
          (stub run-hooks => nil)
          (stub anything-maybe-fit-frame => nil)
          (stub run-with-idle-timer => nil)
          (let (anything-test-mode (anything-pattern ,pattern))
            (anything-update))))

;;;; unit test
;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
(dont-compile
  (when (fboundp 'expectations)
    (expectations
      (desc "anything-current-buffer")
      (expect "__a_buffer"
        (with-current-buffer (get-buffer-create "__a_buffer")
          (anything-test-candidates '(((name . "FOO"))) "")
          (prog1
              (buffer-name anything-current-buffer)
            (kill-buffer "__a_buffer")
            )))
      (desc "anything-buffer-file-name")
      (expect (regexp "/__a_file__")
        (with-current-buffer (get-buffer-create "__a_file__")
          (setq buffer-file-name "/__a_file__")
          (anything-test-candidates '(((name . "FOO"))) "")
          (prog1
              anything-buffer-file-name
            ;;(kill-buffer "__a_file__")
            )))
      (desc "anything-interpret-value")
      (expect "literal"
        (anything-interpret-value "literal"))
      (expect "lambda"
        (anything-interpret-value (lambda () "lambda")))
      (expect "lambda with source name"
        (let ((source '((name . "lambda with source name"))))
          (anything-interpret-value (lambda () anything-source-name) source)))
      (expect "function symbol"
        (flet ((f () "function symbol"))
          (anything-interpret-value 'f)))
      (expect "variable symbol"
        (let ((v "variable symbol"))
          (anything-interpret-value 'v)))
      (expect (error error *)
        (anything-interpret-value 'unbounded-1))
      (desc "anything-compile-sources")
      (expect '(((name . "foo")))
        (anything-compile-sources '(((name . "foo"))) nil)
        )
      (expect '(((name . "foo") (type . test) (action . identity)))
        (let ((anything-type-attributes '((test (action . identity)))))
          (anything-compile-sources '(((name . "foo") (type . test)))
                                    '(anything-compile-source--type))))
      (desc "anything-sources accepts symbols")
      (expect '(((name . "foo")))
        (let* ((foo '((name . "foo"))))
          (anything-compile-sources '(foo) nil)))
      (desc "anything-get-sources action")
      (expect '(((name . "Actions") (candidates . actions)))
        (stub anything-action-window => t)
        (let (anything-compiled-sources
              (anything-sources '(((name . "Actions") (candidates . actions)))))
          (anything-get-sources)))
      (desc "get-buffer-create candidates-buffer")
      (expect '(((name . "many") (init . many-init)
                 (candidates-in-buffer . anything-candidates-in-buffer)
                 (candidates . anything-candidates-in-buffer)
                 (volatile) (match identity)))
        (anything-compile-sources
         '(((name . "many") (init . many-init)
            (candidates-in-buffer . anything-candidates-in-buffer)))
         '(anything-compile-source--candidates-in-buffer)))
      (expect '(((name . "many") (init . many-init)
                 (candidates-in-buffer)
                 (candidates . anything-candidates-in-buffer)
                 (volatile) (match identity)))
        (anything-compile-sources
         '(((name . "many") (init . many-init)
            (candidates-in-buffer)))
         '(anything-compile-source--candidates-in-buffer)))
      (expect '(((name . "many") (init . many-init)
                 (candidates-in-buffer)
                 (type . test)
                 (action . identity)
                 (candidates . anything-candidates-in-buffer)
                 (volatile) (match identity)))
        (let ((anything-type-attributes '((test (action . identity)))))
          (anything-compile-sources
           '(((name . "many") (init . many-init)
              (candidates-in-buffer)
              (type . test)))
           '(anything-compile-source--type
             anything-compile-source--candidates-in-buffer))))

      (desc "anything-get-candidates")
      (expect '("foo" "bar")
        (anything-get-candidates '((name . "foo") (candidates "foo" "bar"))))
      (expect '("FOO" "BAR")
        (anything-get-candidates '((name . "foo") (candidates "foo" "bar")
                                   (candidate-transformer
                                    . (lambda (cands) (mapcar 'upcase cands))))))
      (expect '("foo" "bar")
        (anything-get-candidates '((name . "foo")
                                   (candidates . (lambda () '("foo" "bar"))))))
      (expect '("foo" "bar")
        (let ((var '("foo" "bar")))
          (anything-get-candidates '((name . "foo")
                                     (candidates . var)))))
      (expect (error error *)
        (anything-get-candidates '((name . "foo")
                                   (candidates . "err"))))
      (expect (error error *)
        (let ((var "err"))
          (anything-get-candidates '((name . "foo")
                                     (candidates . var)))))
      (desc "anything-compute-matches")
      (expect '("foo" "bar")
        (let ((anything-pattern ""))
          (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
      (expect '("foo")
        (let ((anything-pattern "oo"))
          (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
      (expect '("bar")
        (let ((anything-pattern "^b"))
          (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
      (expect '("a" "b")
        (let ((anything-pattern "")
              (anything-candidate-number-limit 2))
          (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
      (expect '("a" "b")
        (let ((anything-pattern ".")
              (anything-candidate-number-limit 2))
          (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
      (expect '("a" "b" "c")
        (let ((anything-pattern "")
              anything-candidate-number-limit)
          (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
      (expect '("a" "b" "c")
        (let ((anything-pattern "[abc]")
              anything-candidate-number-limit)
          (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
      ;; using anything-test-candidate-list
      (desc "anything-test-candidates")
      (expect '(("FOO" ("foo" "bar")))
        (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")))))
      (expect '(("FOO" ("bar")))
        (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar"))) "ar"))
      (expect '(("T1" ("hoge" "aiue"))
                ("T2" ("test" "boke")))
        (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
                                    ((name . "T2") (candidates "test" "boke")))))
      (expect '(("T1" ("hoge"))
                ("T2" ("boke")))
        (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
                                    ((name . "T2") (candidates "test" "boke"))) "o"))
      (desc "requires-pattern attribute")
      (expect nil
        (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
                                     (requires-pattern . 1)))))
      (expect '(("FOO" ("bar")))
        (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
                                     (requires-pattern . 1))) "b"))
      (desc "delayed attribute(for test)")
      (expect '(("T2" ("boke"))
                ("T1" ("hoge")))
        (anything-test-candidates
         '(((name . "T1") (candidates "hoge" "aiue") (delayed))
           ((name . "T2") (candidates "test" "boke")))
         "o"))
      (desc "match attribute(prefix search)")
      (expect '(("FOO" ("bar")))
        (anything-test-candidates
         '(((name . "FOO") (candidates "foo" "bar")
            (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
         "ba"))
      (expect nil
        (anything-test-candidates
         '(((name . "FOO") (candidates "foo" "bar")
            (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
         "ar"))
      (expect "TestSource"
        (let (x)
          (anything-test-candidates
           '(((name . "TestSource") (candidates "a")
              (match (lambda (c) (setq x anything-source-name)))))
           "a")
          x))
      (desc "init attribute")
      (expect '(("FOO" ("bar")))
        (let (v)
          (anything-test-candidates
           '(((name . "FOO") (init . (lambda () (setq v '("foo" "bar"))))
              (candidates . v)))
           "ar")))
      (desc "candidate-transformer attribute")
      (expect '(("FOO" ("BAR")))
        (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
                                     (candidate-transformer
                                      . (lambda (cands) (mapcar 'upcase cands)))))
                                  "ar"))
      (desc "filtered-candidate-transformer attribute")
      ;; needs more tests
      (expect '(("FOO" ("BAR")))
        (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
                                     (filtered-candidate-transformer
                                      . (lambda (cands src) (mapcar 'upcase cands)))))
                                  "ar"))
      (desc "anything-candidates-in-buffer-1")
      (expect nil
        (anything-candidates-in-buffer-1 nil))
      (expect '("foo+" "bar+" "baz+")
        (with-temp-buffer
          (insert "foo+\nbar+\nbaz+\n")
          (let ((anything-candidate-number-limit 5))
            (anything-candidates-in-buffer-1 (current-buffer) ""))))
      (expect '("foo+" "bar+")
        (with-temp-buffer
          (insert "foo+\nbar+\nbaz+\n")
          (let ((anything-candidate-number-limit 2))
            (anything-candidates-in-buffer-1 (current-buffer) ""))))
      (expect '("foo+")
        (with-temp-buffer
          (insert "foo+\nbar+\nbaz+\n")
          (anything-candidates-in-buffer-1 (current-buffer) "oo\\+")))
      (expect '("foo+")
        (with-temp-buffer
          (insert "foo+\nbar+\nbaz+\n")
          (anything-candidates-in-buffer-1 
           (current-buffer) "oo+"
           #'buffer-substring-no-properties '(search-forward))))
      (expect '(("foo+" "FOO+"))
        (with-temp-buffer
          (insert "foo+\nbar+\nbaz+\n")
          (anything-candidates-in-buffer-1
           (current-buffer) "oo\\+"
           (lambda (s e)
             (let ((l (buffer-substring-no-properties s e)))
               (list l (upcase l)))))))
      (desc "anything-candidates-in-buffer")
      (expect '(("TEST" ("foo+" "bar+" "baz+")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "foo+\nbar+\nbaz+\n"))))
            (candidates . anything-candidates-in-buffer)
            (match identity)
            (volatile)))))
      (expect '(("TEST" ("foo+" "bar+" "baz+")))
        (let (anything-candidate-number-limit)
          (anything-test-candidates
           '(((name . "TEST")
              (init
               . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                              (insert "foo+\nbar+\nbaz+\n"))))
              (candidates . anything-candidates-in-buffer)
              (match identity)
              (volatile))))))
      (expect '(("TEST" ("foo+")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "foo+\nbar+\nbaz+\n"))))
            (candidates . anything-candidates-in-buffer)
            (match identity)
            (volatile)))
         "oo\\+"))
      (desc "search attribute")
      (expect '(("TEST" ("foo+")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "foo+\nbar+\nbaz+\nooo\n"))))
            (search search-forward)
            (candidates . anything-candidates-in-buffer)
            (match identity)
            (volatile)))
         "oo+"))
      (expect '(("TEST" ("foo+" "ooo")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "foo+\nbar+\nbaz+\nooo\n"))))
            (search search-forward re-search-forward)
            (candidates . anything-candidates-in-buffer)
            (match identity)
            (volatile)))
         "oo+"))
      (expect '(("TEST" ("foo+" "ooo")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "foo+\nbar+\nbaz+\nooo\n"))))
            (search re-search-forward search-forward)
            (candidates . anything-candidates-in-buffer)
            (match identity)
            (volatile)))
         "oo+"))
      (expect '(("TEST" ("ooo" "foo+")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "bar+\nbaz+\nooo\nfoo+\n"))))
            (search re-search-forward search-forward)
            (candidates . anything-candidates-in-buffer)
            (match identity)
            (volatile)))
         "oo+"))
      ;; faster exact match
      (expect '(("TEST" ("bar+")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "bar+\nbaz+\nooo\nfoo+\n"))))
            (search (lambda (pattern &rest _)
                      (and (search-forward (concat "\n" pattern "\n") nil t)
                           (forward-line -1))))
            (candidates . anything-candidates-in-buffer)
            (match identity)
            (volatile)))
         "bar+"))
      ;; faster prefix match
      (expect '(("TEST" ("bar+")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "bar+\nbaz+\nooo\nfoo+\n"))))
            (search (lambda (pattern &rest _)
                      (search-forward (concat "\n" pattern) nil t)))
            (candidates . anything-candidates-in-buffer)
            (match identity)
            (volatile)))
         "ba"))
      (desc "anything-current-buffer-is-modified")
      (expect '(("FOO" ("modified")))
        (let ((sources '(((name . "FOO")
                          (candidates
                           . (lambda ()
                               (if (anything-current-buffer-is-modified)
                                   '("modified")
                                 '("unmodified"))))))))
          (with-temp-buffer
            (clrhash anything-tick-hash)
            (insert "1")
            (anything-test-candidates sources))))
      (expect '(("FOO" ("unmodified")))
        (let ((sources '(((name . "FOO")
                          (candidates
                           . (lambda ()
                               (if (anything-current-buffer-is-modified)
                                   '("modified")
                                 '("unmodified"))))))))
          (with-temp-buffer
            (clrhash anything-tick-hash)
            (insert "1")
            (anything-test-candidates sources)
            (anything-test-candidates sources))))
      (expect '(("FOO" ("modified")))
        (let ((sources '(((name . "FOO")
                          (candidates
                           . (lambda ()
                               (if (anything-current-buffer-is-modified)
                                   '("modified")
                                 '("unmodified"))))))))
          (with-temp-buffer
            (clrhash anything-tick-hash)
            (insert "1")
            (anything-test-candidates sources)
            (insert "2")
            (anything-test-candidates sources))))
      (expect '(("BAR" ("modified")))
        (let ((sources1 '(((name . "FOO")
                           (candidates
                            . (lambda ()
                                (if (anything-current-buffer-is-modified)
                                    '("modified")
                                  '("unmodified")))))))
              (sources2 '(((name . "BAR")
                           (candidates
                            . (lambda ()
                                (if (anything-current-buffer-is-modified)
                                    '("modified")
                                  '("unmodified"))))))))
          (with-temp-buffer
            (clrhash anything-tick-hash)
            (insert "1")
            (anything-test-candidates sources1)
            (anything-test-candidates sources2))))
      (expect '(("FOO" ("unmodified")))
        (let ((sources1 '(((name . "FOO")
                           (candidates
                            . (lambda ()
                                (if (anything-current-buffer-is-modified)
                                    '("modified")
                                  '("unmodified")))))))
              (sources2 '(((name . "BAR")
                           (candidates
                            . (lambda ()
                                (if (anything-current-buffer-is-modified)
                                    '("modified")
                                  '("unmodified"))))))))
          (with-temp-buffer
            (clrhash anything-tick-hash)
            (insert "1")
            (anything-test-candidates sources1)
            (anything-test-candidates sources2)
            (anything-test-candidates sources1))))
      (expect '(("BAR" ("unmodified")))
        (let ((sources1 '(((name . "FOO")
                           (candidates
                            . (lambda ()
                                (if (anything-current-buffer-is-modified)
                                    '("modified")
                                  '("unmodified")))))))
              (sources2 '(((name . "BAR")
                           (candidates
                            . (lambda ()
                                (if (anything-current-buffer-is-modified)
                                    '("modified")
                                  '("unmodified"))))))))
          (with-temp-buffer
            (clrhash anything-tick-hash)
            (insert "1")
            (anything-test-candidates sources1)
            (anything-test-candidates sources2)
            (anything-test-candidates sources2))))
      (expect '(("BAR" ("modified")))
        (let ((sources1 '(((name . "FOO")
                           (candidates
                            . (lambda ()
                                (if (anything-current-buffer-is-modified)
                                    '("modified")
                                  '("unmodified")))))))
              (sources2 '(((name . "BAR")
                           (candidates
                            . (lambda ()
                                (if (anything-current-buffer-is-modified)
                                    '("modified")
                                  '("unmodified"))))))))
          (with-temp-buffer
            (clrhash anything-tick-hash)
            (insert "1")
            (anything-test-candidates sources1)
            (anything-test-candidates sources2)
            (with-temp-buffer
              (anything-test-candidates sources2)))))
      (desc "anything-source-name")
      (expect "FOO"
        (let (v)
          (anything-test-candidates '(((name . "FOO")
                                       (init
                                        . (lambda () (setq v anything-source-name)))
                                       (candidates "ok"))))
          v))
      (expect "FOO"
        (let (v)
          (anything-test-candidates '(((name . "FOO")
                                       (candidates
                                        . (lambda ()
                                            (setq v anything-source-name)
                                            '("ok"))))))
          v))
      (expect "FOO"
        (let (v)
          (anything-test-candidates '(((name . "FOO")
                                       (candidates "ok")
                                       (candidate-transformer
                                        . (lambda (c)
                                            (setq v anything-source-name)
                                            c)))))
          v))
      (expect "FOO"
        (let (v)
          (anything-test-candidates '(((name . "FOO")
                                       (candidates "ok")
                                       (filtered-candidate-transformer
                                        . (lambda (c s)
                                            (setq v anything-source-name)
                                            c)))))
          v))
      (expect "FOO"
        (let (v)
          (anything-test-candidates '(((name . "FOO")
                                       (candidates "ok")
                                       (display-to-real
                                        . (lambda (c)
                                            (setq v anything-source-name)
                                            c))
                                       (action . identity))))
          (anything-execute-selection-action)
          v))
      (desc "anything-candidate-buffer create")
      (expect " *anything candidates:FOO*"
        (let* (anything-candidate-buffer-alist
               (anything-source-name "FOO")
               (buf (anything-candidate-buffer 'global)))
          (prog1 (buffer-name buf)
            (kill-buffer buf))))
      (expect " *anything candidates:FOO*aTestBuffer"
        (let* (anything-candidate-buffer-alist
               (anything-source-name "FOO")
               (anything-current-buffer (get-buffer-create "aTestBuffer"))
               (buf (anything-candidate-buffer 'local)))
          (prog1 (buffer-name buf)
            (kill-buffer anything-current-buffer)
            (kill-buffer buf))))
      (expect 0
        (let (anything-candidate-buffer-alist
              (anything-source-name "FOO") buf)
          (with-current-buffer  (anything-candidate-buffer 'global)
            (insert "1"))
          (setq buf  (anything-candidate-buffer 'global))
          (prog1 (buffer-size buf)
            (kill-buffer buf))))
      (desc "anything-candidate-buffer get-buffer")
      (expect " *anything candidates:FOO*"
        (let* (anything-candidate-buffer-alist
               (anything-source-name "FOO")
               (buf (anything-candidate-buffer 'global)))
          (prog1 (buffer-name (anything-candidate-buffer))
            (kill-buffer buf))))
      (expect " *anything candidates:FOO*aTestBuffer"
        (let* (anything-candidate-buffer-alist
               (anything-source-name "FOO")
               (anything-current-buffer (get-buffer-create "aTestBuffer"))
               (buf (anything-candidate-buffer 'local)))
          (prog1 (buffer-name (anything-candidate-buffer))
            (kill-buffer anything-current-buffer)
            (kill-buffer buf))))
      (expect " *anything candidates:FOO*"
        (let* (anything-candidate-buffer-alist
               (anything-source-name "FOO")
               (buf-local (anything-candidate-buffer 'local))
               (buf-global (anything-candidate-buffer 'global)))
          (prog1 (buffer-name (anything-candidate-buffer))
            (kill-buffer buf-local)
            (kill-buffer buf-global))))
      (expect " *anything candidates:FOO*aTestBuffer"
        (let* (anything-candidate-buffer-alist
               (anything-source-name "FOO")
               (anything-current-buffer (get-buffer-create "aTestBuffer"))
               (buf-global (anything-candidate-buffer 'global))
               (buf-local (anything-candidate-buffer 'local)))
          (prog1 (buffer-name (anything-candidate-buffer))
            (kill-buffer buf-local)
            (kill-buffer buf-global))))
      (expect nil
        (let* (anything-candidate-buffer-alist
               (anything-source-name "NOP__"))
          (anything-candidate-buffer)))
      (desc "anything-candidate-buffer register-buffer")
      (expect " *anything test candidates*"
        (let (anything-candidate-buffer-alist
              (buf (get-buffer-create " *anything test candidates*")))
          (with-current-buffer buf
            (insert "1\n2\n")
            (prog1 (buffer-name (anything-candidate-buffer buf))
              (kill-buffer (current-buffer))))))
      (expect " *anything test candidates*"
        (let (anything-candidate-buffer-alist
              (buf (get-buffer-create " *anything test candidates*")))
          (with-current-buffer buf
            (insert "1\n2\n")
            (anything-candidate-buffer buf)
            (prog1 (buffer-name (anything-candidate-buffer))
              (kill-buffer (current-buffer))))))
      (expect "1\n2\n"
        (let (anything-candidate-buffer-alist
              (buf (get-buffer-create " *anything test candidates*")))
          (with-current-buffer buf
            (insert "1\n2\n")
            (anything-candidate-buffer buf)
            (prog1 (buffer-string)
              (kill-buffer (current-buffer))))))
      (expect "buf1"
        (let (anything-candidate-buffer-alist
              (anything-source-name "foo")
              (buf1 (get-buffer-create "buf1"))
              (buf2 (get-buffer-create "buf2")))
          (anything-candidate-buffer buf1)
          (anything-candidate-buffer buf2)
          (prog1 (buffer-name (anything-candidate-buffer buf1))
            (kill-buffer buf1)
            (kill-buffer buf2))))
      (desc "action attribute")
      (expect "foo"
        (anything-test-candidates
         '(((name . "TEST")
            (candidates "foo")
            (action ("identity" . identity)))))
        (anything-execute-selection-action))
      (expect "foo"
        (anything-test-candidates
         '(((name . "TEST")
            (candidates "foo")
            (action ("identity" . (lambda (c) (identity c)))))))
        (anything-execute-selection-action))
      (desc "anything-execute-selection-action")
      (expect "FOO"
        (anything-execute-selection-action
         "foo" '(("upcase" . upcase))  nil))
      (expect "FOO"
        (anything-execute-selection-action
         "foo" '(("upcase" . (lambda (c) (upcase c)))) nil))
      (desc "display-to-real attribute")
      (expect "FOO"
        (anything-test-candidates
         '(((name . "TEST")
            (candidates "foo")
            (display-to-real . upcase)
            (action ("identity" . identity)))))
        (anything-execute-selection-action))
      (desc "cleanup test")
      (expect 'cleaned
        (let (v)
          (anything-test-candidates
           '(((name . "TEST")
              (cleanup . (lambda () (setq v 'cleaned))))))
          v))
      (desc "anything-get-current-source")
      ;; in init/candidates/action/candidate-transformer/filtered-candidate-transformer
      ;; display-to-real/cleanup function
      (expect "FOO"
        (assoc-default
         'name
         (anything-funcall-with-source '((name . "FOO")) 'anything-get-current-source)))
      ;; init
      (expect "FOO"
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (init . (lambda () (setq v (anything-get-current-source)))))))
          (assoc-default 'name v)))
      ;; candidates
      (expect "FOO"
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (candidates . (lambda () (setq v (anything-get-current-source)) '("a"))))))
          (assoc-default 'name v)))
      ;; action
      (expect "FOO"
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (candidates "a")
              (action
               . (lambda (c) (setq v (anything-get-current-source)) c)))))
          (anything-execute-selection-action)
          (assoc-default 'name v)))
      ;; candidate-transformer
      (expect "FOO"
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (candidates "a")
              (candidate-transformer
               . (lambda (c) (setq v (anything-get-current-source)) c)))))
          (assoc-default 'name v)))
      ;; filtered-candidate-transformer
      (expect "FOO"
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (candidates "a")
              (filtered-candidate-transformer
               . (lambda (c s) (setq v (anything-get-current-source)) c)))))
          (assoc-default 'name v)))
      ;; action-transformer
      (expect "FOO"
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (candidates "a")
              (action-transformer
               . (lambda (a c) (setq v (anything-get-current-source)) a))
              (action . identity))))
          (anything-execute-selection-action)
          (assoc-default 'name v)))
      ;; display-to-real
      (expect "FOO"
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (init . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                                   (insert "a\n"))))
              (candidates-in-buffer)
              (display-to-real
               . (lambda (c) (setq v (anything-get-current-source)) c))
              (action . identity))))
          (anything-execute-selection-action)
          (assoc-default 'name v)))
      ;; cleanup
      (expect "FOO"
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (candidates "a")
              (cleanup
               . (lambda () (setq v (anything-get-current-source)))))))
          (assoc-default 'name v)))
      ;; candidates are displayed
      (expect "TEST"
        (anything-test-candidates
         '(((name . "TEST")
            (candidates "foo")
            (action ("identity" . identity)))))
        (assoc-default 'name (anything-get-current-source)))
      (desc "anything-attr")
      (expect "FOO"
        (anything-funcall-with-source
         '((name . "FOO"))
         (lambda ()
           (anything-attr 'name))))
      (expect 'fuga
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (hoge . fuga)
              (init . (lambda () (setq v (anything-attr 'hoge))))
              (candidates "a"))))
          v))
      (expect nil
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (init . (lambda () (setq v (anything-attr 'hoge))))
              (candidates "a"))))
          v))
      (expect nil
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (hoge)                    ;INCOMPATIBLE!
              (init . (lambda () (setq v (anything-attr 'hoge))))
              (candidates "a"))))
          v))
      (desc "anything-attr-defined")
      (expect (non-nil)
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (hoge)
              (init . (lambda () (setq v (anything-attr-defined 'hoge))))
              (candidates "a"))))
          v))      
      (expect nil
        (let (v)
          (anything-test-candidates
           '(((name . "FOO")
              (init . (lambda () (setq v (anything-attr-defined 'hoge))))
              (candidates "a"))))
          v))      
      (desc "anything-attrset")
      (expect '((name . "FOO") (hoge . 77))
        (let ((src '((name . "FOO") (hoge))))
          (anything-attrset 'hoge 77 src)
          src))
      (expect 77
        (anything-attrset 'hoge 77 '((name . "FOO") (hoge))))

      (expect '((name . "FOO") (hoge . 77))
        (let ((src '((name . "FOO") (hoge . 1))))
          (anything-attrset 'hoge 77 src)
          src))

      (expect '((name . "FOO") (hoge . 77) (x))
        (let ((src '((name . "FOO") (x))))
          (anything-attrset 'hoge 77 src)
          src))
      (expect 77
        (anything-attrset 'hoge 77 '((name . "FOO"))))
      (desc "anything-preselect")
      ;; entire candidate
      (expect "foo"
        (with-current-buffer (anything-create-anything-buffer t)
          (let ((anything-pattern "")
                (anything-test-mode t))
            (anything-process-source '((name . "test")
                                       (candidates "hoge" "foo" "bar")))
            (anything-preselect "foo")
            (anything-get-selection))))
      ;; regexp
      (expect "foo"
        (with-current-buffer (anything-create-anything-buffer t)
          (let ((anything-pattern "")
                (anything-test-mode t))
            (anything-process-source '((name . "test")
                                       (candidates "hoge" "foo" "bar")))
            (anything-preselect "fo+")
            (anything-get-selection))))
      ;; no match -> first entry
      (expect "hoge"
        (with-current-buffer (anything-create-anything-buffer t)
          (let ((anything-pattern "")
                (anything-test-mode t))
            (anything-process-source '((name . "test")
                                       (candidates "hoge" "foo" "bar")))
            (anything-preselect "not found")
            (anything-get-selection))))
      (desc "anything-check-new-input")
      (expect "newpattern"
        (stub anything-update)
        (stub anything-action-window)
        (let ((anything-pattern "pattern"))
          (anything-check-new-input "newpattern")
          anything-pattern))
      ;; anything-input == nil when action window is available
      (expect nil
        (stub anything-update)
        (stub anything-action-window => t)
        (let ((anything-pattern "pattern")
              anything-input)
          (anything-check-new-input "newpattern")
          anything-input))
      ;; anything-input == anything-pattern unless action window is available
      (expect "newpattern"
        (stub anything-update)
        (stub anything-action-window => nil)
        (let ((anything-pattern "pattern")
              anything-input)
          (anything-check-new-input "newpattern")
          anything-input))
      (expect (mock (anything-update))
        (stub anything-action-window)
        (let (anything-pattern)
          (anything-check-new-input "foo")))
      (desc "anything-update")
      (expect (mock (anything-process-source '((name . "1"))))
        (anything-test-update '(((name . "1"))) ""))
      ;; (find-function 'anything-update)
      ;; TODO el-mock.el should express 2nd call of function.
      ;;     (expect (mock (anything-process-source '((name . "2"))))
      ;;       (stub anything-get-sources => '(((name . "1")) ((name . "2"))))
      ;;       (stub run-hooks)
      ;;       (stub anything-maybe-fit-frame)
      ;;       (stub run-with-idle-timer)
      ;;       (anything-update))
      (expect (mock (run-with-idle-timer * nil 'anything-process-delayed-sources
                                         '(((name . "2") (delayed)))))
        (stub anything-get-sources => '(((name . "1"))
                                        ((name . "2") (delayed))))
        (stub run-hooks)
        (stub anything-maybe-fit-frame)
        (let ((anything-pattern "") anything-test-mode)
          (anything-update)))

      (desc "requires-pattern attribute")
      (expect (not-called anything-process-source)
        (anything-test-update '(((name . "1") (requires-pattern))) ""))
      (expect (not-called anything-process-source)
        (anything-test-update '(((name . "1") (requires-pattern . 3))) "xx"))

      (desc "delay")
      (expect (mock (sit-for 0.25))
        (stub with-current-buffer)
        (let ((anything-idle-delay 1.0)
              (anything-input-idle-delay 0.75))
          (anything-process-delayed-sources t)))
      (expect (mock (sit-for 0.0))
        (stub with-current-buffer)
        (let ((anything-idle-delay 0.2)
              (anything-input-idle-delay 0.5))
          (anything-process-delayed-sources t)))    
      (expect (mock (sit-for 0.5))
        (stub with-current-buffer)
        (let ((anything-idle-delay 0.5)
              (anything-input-idle-delay nil))
          (anything-process-delayed-sources t)))
      (desc "anything-normalize-sources")
      (expect '(anything-c-source-test)
        (anything-normalize-sources 'anything-c-source-test))
      (expect '(anything-c-source-test)
        (anything-normalize-sources '(anything-c-source-test)))
      (expect '(anything-c-source-test)
        (let ((anything-sources '(anything-c-source-test)))
          (anything-normalize-sources nil)))
      (expect '(((name . "test")))
        (anything-normalize-sources '((name . "test"))))
      (expect '(((name . "test")))
        (anything-normalize-sources '(((name . "test")))))
      (desc "anything-get-action")
      (expect '(("identity" . identity))
        (stub buffer-size => 1)
        (stub anything-get-current-source => '((name . "test")
                                               (action ("identity" . identity))))
        (anything-get-action))
      (expect '((("identity" . identity)) "action-transformer is called")
        (stub buffer-size => 1)
        (stub anything-get-current-source
              => '((name . "test")
                   (action ("identity" . identity))
                   (action-transformer
                    . (lambda (actions selection)
                        (list actions selection)))))
        (stub anything-get-selection => "action-transformer is called")
        (anything-get-action))
      (desc "anything-select-nth-action")
      (expect "selection"
        (stub anything-get-selection => "selection")
        (stub anything-exit-minibuffer)
        (let (anything-saved-selection)
          (anything-select-nth-action 1)
          anything-saved-selection))
      (expect 'cadr
        (stub anything-get-action => '(("0" . car) ("1" . cdr) ("2" . cadr)))
        (stub anything-exit-minibuffer)
        (stub anything-get-selection => "selection")
        (let (anything-saved-action)
          (anything-select-nth-action 2)
          anything-saved-action))
      (desc "anything-funcall-foreach")
      (expect (mock (upcase "foo"))
        (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
        (anything-funcall-foreach 'init))
      (expect (mock (downcase "bar"))
        (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))
                                        ((init . (lambda () (downcase "bar"))))))
        (anything-funcall-foreach 'init))
      (expect (not-called anything-funcall-with-source)
        (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
        (anything-funcall-foreach 'not-found))
      ;; TODO anything-select-with-digit-shortcut test
      (desc "anything-get-cached-candidates")
      (expect '("cached" "version")
        (let ((anything-candidate-cache '(("test" "cached" "version"))))
          (anything-get-cached-candidates '((name . "test")
                                            (candidates "new")))))
      (expect '("new")
        (let ((anything-candidate-cache '(("other" "cached" "version"))))
          (anything-get-cached-candidates '((name . "test")
                                            (candidates "new")))))
      (expect '(("test" "new")
                ("other" "cached" "version"))
        (let ((anything-candidate-cache '(("other" "cached" "version"))))
          (anything-get-cached-candidates '((name . "test")
                                            (candidates "new")))
          anything-candidate-cache))
      (expect '(("other" "cached" "version"))
        (let ((anything-candidate-cache '(("other" "cached" "version"))))
          (anything-get-cached-candidates '((name . "test")
                                            (candidates "new")
                                            (volatile)))
          anything-candidate-cache))
      ;; TODO when candidates == process
      ;; TODO anything-output-filter
      (desc "candidate-number-limit attribute")
      (expect '("a" "b")
        (let ((anything-pattern "")
              (anything-candidate-number-limit 20))
          (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
                                      (candidate-number-limit . 2) (volatile)))))
      (expect '("a" "b")
        (let ((anything-pattern "[abc]")
              (anything-candidate-number-limit 20))
          (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
                                      (candidate-number-limit . 2) (volatile)))))
      (expect '("a" "b" "c" "d")
        (let ((anything-pattern "[abcd]")
              (anything-candidate-number-limit 2))
          (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c" "d")
                                      (candidate-number-limit) (volatile)))))
      (expect '(("TEST" ("a" "b" "c")))
        (let ((anything-candidate-number-limit 2))
          (anything-test-candidates
           '(((name . "TEST")
              (init
               . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                              (insert "a\nb\nc\nd\n"))))
              (candidates . anything-candidates-in-buffer)
              (match identity)
              (candidate-number-limit . 3)
              (volatile))))))
      (expect '(("TEST" ("a" "b" "c")))
        (let ((anything-candidate-number-limit 2))
          (anything-test-candidates
           '(((name . "TEST")
              (init
               . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                              (insert "a\nb\nc\nd\n"))))
              (candidates . anything-candidates-in-buffer)
              (match identity)
              (candidate-number-limit . 3)
              (volatile)))
           ".")))
      (desc "multiple init")
      (expect '(1 . 2)
        (let (a b)
          (anything-test-candidates
           '(((name . "test")
              (init (lambda () (setq a 1))
                    (lambda () (setq b 2))))))
          (cons a b)))
      (expect 1
        (let (a)
          (anything-test-candidates
           '(((name . "test")
              (init (lambda () (setq a 1))))))
          a))
      (desc "multiple cleanup")
      (expect '(1 . 2)
        (let (a b)
          (anything-test-candidates
           '(((name . "test")
              (cleanup (lambda () (setq a 1))
                       (lambda () (setq b 2))))))
          (cons a b)))
      (desc "anything-mklist")
      (expect '(1)
        (anything-mklist 1))
      (expect '(2)
        (anything-mklist '(2)))
      (expect '((lambda ()))
        (anything-mklist (lambda ())))
      (desc "anything-before-initialize-hook")
      (expect 'called
        (let ((anything-before-initialize-hook '((lambda () (setq v 'called))))
              v)
          (anything-initialize)
          v))
      (desc "anything-after-initialize-hook")
      (expect '(b a)
        (let ((anything-before-initialize-hook
               '((lambda () (setq v '(a)))))
              (anything-after-initialize-hook
               '((lambda () (setq v (cons 'b v)))))
              v)
          (anything-initialize)
          v))
      (expect 0
        (let ((anything-after-initialize-hook
               '((lambda () (setq v (buffer-size (get-buffer anything-buffer))))))
              v)
          (anything-initialize)
          v))
      (desc "get-line attribute")
      (expect '(("TEST" ("FOO+")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "foo+\nbar+\nbaz+\n"))))
            (candidates-in-buffer)
            (get-line . (lambda (s e) (upcase (buffer-substring-no-properties s e))))))
         "oo\\+"))
      (desc "with-anything-restore-variables")
      (expect '(7 8)
        (let ((a 7) (b 8)
              (anything-restored-variables '(a b)))
          (with-anything-restore-variables
            (setq a 0 b 0))
          (list a b)))
      (desc "anything-cleanup-hook")
      (expect 'called
        (let ((anything-cleanup-hook
               '((lambda () (setq v 'called))))
              v)
          (anything-cleanup)
          v))
      (desc "with-anything-display-same-window")
      (expect (non-nil)
        (save-window-excursion
          (delete-other-windows)
          (split-window)
          
          (let ((buf (get-buffer-create " tmp"))
                (win (selected-window)))
            (with-anything-display-same-window
              (display-buffer buf)
              (eq win (get-buffer-window buf))))))
      (expect (non-nil)
        (save-window-excursion
          (delete-other-windows)
          (split-window)
          
          (let ((buf (get-buffer-create " tmp"))
                (win (selected-window)))
            (with-anything-display-same-window
              (pop-to-buffer buf)
              (eq win (get-buffer-window buf))))))
      (expect (non-nil)
        (save-window-excursion
          (delete-other-windows)
          (split-window)
          
          (let ((buf (get-buffer-create " tmp"))
                (win (selected-window)))
            (with-anything-display-same-window
              (switch-to-buffer buf)
              (eq win (get-buffer-window buf))))))
      (expect (non-nil)
        (save-window-excursion
          (delete-other-windows)
          (let ((buf (get-buffer-create " tmp"))
                (win (selected-window)))
            (with-anything-display-same-window
              (display-buffer buf)
              (eq win (get-buffer-window buf))))))
      (expect (non-nil)
        (save-window-excursion
          (delete-other-windows)
          (let ((buf (get-buffer-create " tmp"))
                (win (selected-window)))
            (with-anything-display-same-window
              (pop-to-buffer buf)
              (eq win (get-buffer-window buf))))))
      (desc "search-from-end attribute")
      (expect '(("TEST" ("baz+" "bar+" "foo+")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "foo+\nbar+\nbaz+\n"))))
            (candidates-in-buffer)
            (search-from-end)))))
      (expect '(("TEST" ("baz+" "bar+" "foo+")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "foo+\nbar+\nbaz+\n"))))
            (candidates-in-buffer)
            (search-from-end)))
         "\\+"))
      (expect '(("TEST" ("baz+" "bar+")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "foo+\nbar+\nbaz+\n"))))
            (candidates-in-buffer)
            (search-from-end)
            (candidate-number-limit . 2)))))
      (expect '(("TEST" ("baz+" "bar+")))
        (anything-test-candidates
         '(((name . "TEST")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (insert "foo+\nbar+\nbaz+\n"))))
            (candidates-in-buffer)
            (search-from-end)
            (candidate-number-limit . 2)))
         "\\+"))

      (desc "header-name attribute")
      (expect "original is transformed"
        (anything-test-update '(((name . "original")
                                 (candidates "1")
                                 (header-name
                                  . (lambda (name)
                                      (format "%s is transformed" name)))))
                              "")
        (with-current-buffer (anything-buffer-get)
          (buffer-string)
          (overlay-get (car (overlays-at (1+(point-min)))) 'display)))
      (desc "volatile and match attribute")
      ;; candidates function is called once per `anything-process-delayed-sources'
      (expect 1
        (let ((v 0))
          (anything-test-candidates '(((name . "test")
                                       (candidates . (lambda () (incf v) '("ok")))
                                       (volatile)
                                       (match identity identity identity)))
                                    "o")
          v))
      (desc "accept-empty attribute")
      (expect nil
        (anything-test-candidates
         '(((name . "test") (candidates "") (action . identity))))
        (anything-execute-selection-action))
      (expect ""
        (anything-test-candidates
         '(((name . "test") (candidates "") (action . identity) (accept-empty))))
        (anything-execute-selection-action))
      (desc "anything-tick-hash")
      (expect nil
        (with-current-buffer (get-buffer-create " *00create+*")
          (puthash " *00create+*/xxx" 1 anything-tick-hash)
          (kill-buffer (current-buffer)))
        (gethash " *00create+*/xxx" anything-tick-hash))
      (desc "anything-execute-action-at-once-if-once")
      (expect "HOGE"
        (let ((anything-execute-action-at-once-if-one t))
          (anything '(((name . "one test1")
                       (candidates "hoge")
                       (action . upcase))))))
      (expect "ANY"
        (let ((anything-execute-action-at-once-if-one t))
          (anything '(((name . "one test2")
                       (candidates "hoge" "any")
                       (action . upcase)))
                    "an")))
      ;; candidates > 1
      (expect (mock (read-string "word: " nil))
        (let ((anything-execute-action-at-once-if-one t))
          (anything '(((name . "one test3")
                       (candidates "hoge" "foo" "bar")
                       (action . identity)))
                    nil "word: ")))
      (desc "anything-quit-if-no-candidate")
      (expect nil
        (let ((anything-quit-if-no-candidate t))
          (anything '(((name . "zero test1") (candidates) (action . upcase))))))
      (expect 'called
        (let (v (anything-quit-if-no-candidate (lambda () (setq v 'called))))
          (anything '(((name . "zero test2") (candidates) (action . upcase))))
          v))
      (desc "real-to-display attribute")
      (expect '(("test" (("DDD" . "ddd"))))
        (anything-test-candidates '(((name . "test")
                                     (candidates "ddd")
                                     (real-to-display . upcase)
                                     (action . identity)))))
      (expect '(("test" (("DDD" . "ddd"))))
        (anything-test-candidates '(((name . "test")
                                     (candidates ("ignored" . "ddd"))
                                     (real-to-display . upcase)
                                     (action . identity)))))
      (expect '(("Commands" (("xxxhoge" . "hoge") ("xxxboke" . "boke"))))
        (anything-test-candidates '(((name . "Commands")
                                     (candidates
                                      "hoge" "boke")
                                     (real-to-display . (lambda (x) (concat "xxx" x)))
                                     (action . identity)))
                                   "xxx"))
      (expect "test\nDDD\n"
        (anything-test-update '(((name . "test")
                                 (candidates "ddd")
                                 (real-to-display . upcase)
                                 (action . identity)))
                               "")
        (with-current-buffer (anything-buffer-get) (buffer-string)))
      (desc "real-to-display and candidate-transformer attribute")
      (expect '(("test" (("DDD" . "ddd"))))
        (anything-test-candidates
         '(((name . "test")
            (candidates "ddd")
            (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c)) cands)))
            (real-to-display . upcase)
            (action . identity)))))
      (expect "test\nDDD\n"
        (anything-test-update
         '(((name . "test")
            (candidates "ddd")
            (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c)) cands)))
            (real-to-display . upcase)
            (action . identity)))
                              "")
        (with-current-buffer (anything-buffer-get) (buffer-string)))
      (desc "real-to-display and candidates-in-buffer")
      (expect '(("test" (("A" . "a") ("B" . "b"))))
        (anything-test-candidates
         '(((name . "test")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (erase-buffer)
                            (insert "a\nb\n"))))
            (candidates-in-buffer)
            (real-to-display . upcase)
            (action . identity)))))
      (expect "test\nA\nB\n"
        (stub read-string)
        (anything
         '(((name . "test")
            (init
             . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                            (erase-buffer)
                            (insert "a\nb\n"))))
            (candidates-in-buffer)
            (real-to-display . upcase)
            (action . identity))))
        (with-current-buffer (anything-buffer-get) (buffer-string)))
      (desc "Symbols are acceptable as candidate.")
      (expect '(("test" (sym "str")))
        (anything-test-candidates
         '(((name . "test")
            (candidates sym "str")))))
      (expect '(("test" ((sym . realsym) ("str" . "realstr"))))
        (anything-test-candidates
         '(((name . "test")
            (candidates (sym . realsym) ("str" . "realstr"))))))
      (expect '(("test" (sym)))
        (anything-test-candidates
         '(((name . "test")
            (candidates sym "str")))
         "sym"))
      (expect '(("test" ("str")))
        (anything-test-candidates
         '(((name . "test")
            (candidates sym "str")))
         "str"))
      (expect '(("test" ((sym . realsym))))
        (anything-test-candidates
         '(((name . "test")
            (candidates (sym . realsym) ("str" . "realstr"))))
         "sym"))
      (expect '(("test" (("str" . "realstr"))))
        (anything-test-candidates
         '(((name . "test")
            (candidates (sym . realsym) ("str" . "realstr"))))
         "str"))
      (desc "multiple transformers")
      (expect '(("test" ("<FOO>")))
        (anything-test-candidates
         '(((name . "test")
            (candidates "foo")
            (candidate-transformer
             . (lambda (cands)
                 (anything-compose (list cands)
                                   (list (lambda (c) (mapcar 'upcase c))
                                         (lambda (c) (list (concat "<" (car c) ">")))))))))))
      (expect '("<FOO>")
        (anything-composed-funcall-with-source
         '((name . "test"))
         (list (lambda (c) (mapcar 'upcase c))
               (lambda (c) (list (concat "<" (car c) ">"))))
         '("foo"))
        )
      (expect '(("test" ("<FOO>")))
        (anything-test-candidates
         '(((name . "test")
            (candidates "foo")
            (candidate-transformer
             (lambda (c) (mapcar 'upcase c))
             (lambda (c) (list (concat "<" (car c) ">"))))))))
      (expect '(("test" ("<BAR>")))
        (anything-test-candidates
         '(((name . "test")
            (candidates "bar")
            (filtered-candidate-transformer
             (lambda (c s) (mapcar 'upcase c))
             (lambda (c s) (list (concat "<" (car c) ">"))))))))
      (expect '(("find-file" . find-file)
                ("view-file" . view-file))
        (stub zerop => nil)
        (stub anything-get-current-source
              => '((name . "test")
                   (action)
                   (action-transformer
                    . (lambda (a s)
                        (anything-compose
                         (list a s)
                         (list (lambda (a s) (push '("view-file" . view-file) a))
                               (lambda (a s) (push '("find-file" . find-file) a))))))))
        (anything-get-action))
      (expect '(("find-file" . find-file)
                ("view-file" . view-file))
        (stub zerop => nil)
        (stub anything-get-current-source
              => '((name . "test")
                   (action)
                   (action-transformer
                    (lambda (a s) (push '("view-file" . view-file) a))
                    (lambda (a s) (push '("find-file" . find-file) a)))))
        (anything-get-action))
      (desc "define-anything-type-attribute")
      (expect '((file (action . find-file)))
        (let (anything-type-attributes)
          (define-anything-type-attribute 'file '((action . find-file)))
          anything-type-attributes))
      (expect '((file (action . find-file)))
        (let ((anything-type-attributes '((file (action . view-file)))))
          (define-anything-type-attribute 'file '((action . find-file)))
          anything-type-attributes))
      (expect '((file (action . find-file))
                (buffer (action . switch-to-buffer)))
        (let (anything-type-attributes)
          (define-anything-type-attribute 'buffer '((action . switch-to-buffer)))
          (define-anything-type-attribute 'file '((action . find-file)))
          anything-type-attributes))
      (desc "anything-approximate-candidate-number")
      (expect 0
        (with-temp-buffer
          (let ((anything-buffer (current-buffer)))
            (anything-approximate-candidate-number))))
      (expect 1
        (with-temp-buffer
          (let ((anything-buffer (current-buffer)))
            (insert "Title\n"
                    "candiate1\n")
            (anything-approximate-candidate-number))))
      (expect t
        (with-temp-buffer
          (let ((anything-buffer (current-buffer)))
            (insert "Title\n"
                    "candiate1\n"
                    "candiate2\n")
            (<= 2 (anything-approximate-candidate-number)))))
      (expect 1
        (with-temp-buffer
          (let ((anything-buffer (current-buffer)))
            (insert "Title\n"
                    (propertize "multi\nline\n" 'anything-multiline t))
            (anything-approximate-candidate-number))))
      (expect t
        (with-temp-buffer
          (let ((anything-buffer (current-buffer))
                (anything-candidate-separator "-----"))
            (insert "Title\n"
                    (propertize "multi\nline1\n" 'anything-multiline t)
                    "-----\n"
                    (propertize "multi\nline2\n" 'anything-multiline t))
            (<= 2 (anything-approximate-candidate-number)))))
      (desc "delayed-init attribute")
      (expect 0
        (let ((value 0))
          (anything-test-candidates '(((name . "test")
                                       (delayed-init . (lambda () (incf value)))
                                       (candiates "abc")
                                       (requires-pattern . 2)))
                                    "")
          value))
      (expect 1
        (let ((value 0))
          (anything-test-candidates '(((name . "test")
                                       (delayed-init . (lambda () (incf value)))
                                       (candiates "abc")
                                       (requires-pattern . 2)))
                                    "abc")
          value))
      (expect 2
        (let ((value 0))
          (anything-test-candidates '(((name . "test")
                                       (delayed-init (lambda () (incf value))
                                                     (lambda () (incf value)))
                                       (candiates "abc")
                                       (requires-pattern . 2)))
                                    "abc")
          value))
      (expect t
        (let (value)
          (with-temp-buffer
            (anything-test-candidates '(((name . "test")
                                         (delayed-init
                                          . (lambda () (setq value
                                                             (eq anything-current-buffer (current-buffer)))))
                                         (candiates "abc")
                                         (requires-pattern . 2)))
                                      "abc")
            value)))
      (desc "pattern-transformer attribute")
      (expect '(("test2" ("foo")) ("test3" ("bar")))
        (anything-test-candidates '(((name . "test1")
                                     (candidates "foo" "bar"))
                                    ((name . "test2")
                                     (pattern-transformer . (lambda (pat) (substring pat 1)))
                                     (candidates "foo" "bar"))
                                    ((name . "test3")
                                     (pattern-transformer . (lambda (pat) "bar"))
                                     (candidates "foo" "bar")))
                                  "xfoo"))
      (expect '(("test2" ("foo")) ("test3" ("bar")))
        (anything-test-candidates '(((name . "test1")
                                     (candidates "foo" "bar"))
                                    ((name . "test2")
                                     (pattern-transformer (lambda (pat) (substring pat 1)))
                                     (candidates "foo" "bar"))
                                    ((name . "test3")
                                     (pattern-transformer (lambda (pat) "bar"))
                                     (candidates "foo" "bar")))
                                  "xfoo"))
      (expect '(("test2" ("foo")) ("test3" ("bar")))
        (anything-test-candidates '(((name . "test1")
                                     (init
                                      . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                                                     (insert "foo\nbar\n"))))
                                     (candidates-in-buffer))
                                    ((name . "test2")
                                     (pattern-transformer . (lambda (pat) (substring pat 1)))
                                     (init
                                      . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                                                     (insert "foo\nbar\n"))))
                                     (candidates-in-buffer))
                                    ((name . "test3")
                                     (pattern-transformer . (lambda (pat) "bar"))
                                     (init
                                      . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
                                                     (insert "foo\nbar\n"))))
                                     (candidates-in-buffer)))
                                  "xfoo"))
      (desc "anything-recent-push")
      (expect '("foo" "bar" "baz")
        (let ((lst '("bar" "baz")))
          (anything-recent-push "foo" 'lst)))
      (expect '("foo" "bar" "baz")
        (let ((lst '("foo" "bar" "baz")))
          (anything-recent-push "foo" 'lst)))
      (expect '("foo" "bar" "baz")
        (let ((lst '("bar" "foo" "baz")))
          (anything-recent-push "foo" 'lst)))
      (desc "anything-require-at-least-version")
      (expect nil
        (anything-require-at-least-version "1.1"))
      (expect nil
        (anything-require-at-least-version "1.200"))
      (expect nil
        (anything-require-at-least-version
         (and (string-match "1\.\\([0-9]+\\)" anything-version)
              (match-string 0 anything-version))))
      (expect (error)
        (anything-require-at-least-version "1.999"))
      (expect (error)
        (anything-require-at-least-version "1.2000"))
      (desc "anything-once")
      (expect 2
        (let ((i 0))
          (anything-test-candidates
           '(((name . "1")
              (init . (lambda () (incf i))))
             ((name . "2")
              (init . (lambda () (incf i))))))
          i))
      (expect 1
        (let ((i 0))
          (anything-test-candidates
           '(((name . "1")
              (init . (lambda () (anything-once (lambda () (incf i))))))
             ((name . "2")
              (init . (lambda () (anything-once (lambda () (incf i))))))))
          i))
      (expect 1
        (let ((i 0))
          (flet ((init1 () (anything-once (lambda () (incf i)))))
            (anything-test-candidates
             '(((name . "1")
                (init . init1))
               ((name . "2")
                (init . init1)))))
          i))
      (desc "anything-marked-candidates")
      (expect '("mark3" "mark1")
        (let* ((source '((name . "mark test")))
               (anything-marked-candidates
                `((,source . "mark1")
                  (((name . "other")) . "mark2")
                  (,source . "mark3"))))
          (stub anything-get-current-source => source)
          (anything-marked-candidates)))
      (expect '("current")
        (let* ((source '((name . "mark test")))
               (anything-marked-candidates nil))
          (stub anything-get-current-source => source)
          (stub anything-get-selection => "current")
          (anything-marked-candidates)))
      )))


(provide 'anything)
;; How to save (DO NOT REMOVE!!)
;; (progn (magit-push) (emacswiki-post "anything.el"))
;;; anything.el ends here