File: modes.texi

package info (click to toggle)
elisp-manual-ja 20-2.5-jp-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,996 kB
  • ctags: 239
  • sloc: lisp: 2,837; perl: 182; makefile: 45; sh: 16
file content (3362 lines) | stat: -rw-r--r-- 156,254 bytes parent folder | download | duplicates (2)
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
@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc. 
@c See the file elisp.texi for copying conditions.
@setfilename ../info/modes
@node Modes, Documentation,  Keymaps, Top
@c @chapter Major and Minor Modes
@chapter $B%a%8%c!<%b!<%I$H%^%$%J%b!<%I(B
@c @cindex mode
@cindex $B%b!<%I(B

@c   A @dfn{mode} is a set of definitions that customize Emacs and can be
@c turned on and off while you edit.  There are two varieties of modes:
@c @dfn{major modes}, which are mutually exclusive and used for editing
@c particular kinds of text, and @dfn{minor modes}, which provide features
@c that users can enable individually.
@dfn{$B%b!<%I(B}$B!J(Bmode$B!K$H$O!"(BEmacs$B$r%+%9%?%^%$%:$9$kDj5A$N=8$^$j$G$"$j!"(B
$BFI<T$OJT=8Cf$K$=$l$r%*%s!?%*%U$G$-$^$9!#(B
$B%b!<%I$K$O(B2$B<oN`$"$j$^$9!#(B
@dfn{$B%a%8%c!<%b!<%I(B}$B!J(Bmajor mode$B!K$O!"8_$$$KGSB>E*$G!"(B
$BFCDj<oN`$N%F%-%9%H$NJT=8$K;H$$$^$9!#(B
@dfn{$B%^%$%J%b!<%I(B}$B!J(Bminor mode$B!K$O!"(B
$B%f!<%6!<$,$=$l$>$l$rFHN)$K%*%s$K$G$-$k5!G=$rDs6!$7$^$9!#(B

@c   This chapter describes how to write both major and minor modes, how to
@c indicate them in the mode line, and how they run hooks supplied by the
@c user.  For related topics such as keymaps and syntax tables, see
@c @ref{Keymaps}, and @ref{Syntax Tables}.
$BK\>O$G$O!"%a%8%c!<%b!<%I$d%^%$%J%b!<%I$N=q$-J}!"(B
$B$=$l$i$r%b!<%I9T$KI=<($9$kJ}K!!"(B
$B%f!<%6!<$,;XDj$7$?%U%C%/$r%b!<%I$,$I$N$h$&$K<B9T$9$k$+$K$D$$$F=R$Y$^$9!#(B
$B%-!<%^%C%W$d9=J8%F!<%V%k$J$I$N4XO";v9`$K$D$$$F$O!"(B
@ref{Keymaps}$B$d(B@ref{Syntax Tables}$B$r;2>H$7$F$/$@$5$$!#(B

@menu
* Major Modes::        Defining major modes.
* Minor Modes::        Defining minor modes.
* Mode Line Format::   Customizing the text that appears in the mode line.
* Imenu::              How a mode can provide a menu
                         of definitions in the buffer.
* Font Lock Mode::     How modes can highlight text according to syntax.
* Hooks::              How to use hooks; how to write code that provides hooks.
@end menu

@node Major Modes
@c @section Major Modes
@section $B%a%8%c!<%b!<%I(B
@c @cindex major mode
@c @cindex Fundamental mode
@cindex $B%a%8%c!<%b!<%I(B
@cindex $B4pK\!J(Bfundamental$B!K%b!<%I(B

@c   Major modes specialize Emacs for editing particular kinds of text.
@c Each buffer has only one major mode at a time.
$B%a%8%c!<%b!<%I$O!"FCDj<oN`$N%F%-%9%H$NJT=88~$1$K(BEmacs$B$rFC2=$7$^$9!#(B
$B3F%P%C%U%!$K$O!"$"$k;~E@$G$O(B1$B$D$N%a%8%c!<%b!<%I$7$+$"$j$^$;$s!#(B

@c   The least specialized major mode is called @dfn{Fundamental mode}.
@c This mode has no mode-specific definitions or variable settings, so each
@c Emacs command behaves in its default manner, and each option is in its
@c default state.  All other major modes redefine various keys and options.
@c For example, Lisp Interaction mode provides special key bindings for
@c @kbd{C-j} (@code{eval-print-last-sexp}), @key{TAB}
@c (@code{lisp-indent-line}), and other keys.
$B$b$C$H$bFC2=$5$l$F$$$J$$%a%8%c!<%b!<%I$O!"(B
@dfn{$B4pK\!J(Bfundamental$B!K%b!<%I(B}$B$G$9!#(B
$B$3$N%b!<%I$K$O!"%b!<%I$K8GM-$JDj5A$dJQ?t$N@_Dj$,$"$j$^$;$s!#(B
$B$=$N$?$a!"(BEmacs$B$N3F%3%^%s%I$O%G%U%)%k%H$N$U$k$^$$$r$7!"(B
$B3F%*%W%7%g%s$b%G%U%)%k%H$N>uBV$G$9!#(B
$BB>$N$9$Y$F$N%a%8%c!<%b!<%I$G$O!"$5$^$6$^$J%-!<$d%*%W%7%g%s$r:FDj5A$7$^$9!#(B
$B$?$H$($P!"(Blisp$BBPOC%b!<%I$G$O!"(B
@kbd{C-j}$B!J(B@code{eval-print-last-sexp}$B!K$d(B
@key{TAB}$B!J(B@code{lisp-indent-line}$B!K$J$IB>$N%-!<$KBP$7$F$b(B
$BFCJL$J%-!<%P%$%s%G%#%s%0$,$"$j$^$9!#(B

@c   When you need to write several editing commands to help you perform a
@c specialized editing task, creating a new major mode is usually a good
@c idea.  In practice, writing a major mode is easy (in contrast to
@c writing a minor mode, which is often difficult).
$BFI<T$NFCJL$JJT=8:n6H$rJd:4$9$k$?$a$K0l72$NJT=8%3%^%s%I$r=q$/I,MW$,$"$k>l9g!"(B
$B?7$?$J%a%8%c!<%b!<%I$r:n$k$3$H$O0lHL$K$O$h$$$3$H$G$9!#(B
$B<B:]!"%a%8%c!<%b!<%I$r=q$/$3$H$O(B
$B!J%^%$%J%b!<%I$r=q$/$3$H$O$7$P$7$PFq$7$/$J$k$,!"(B
$B$=$l$KBPHf$9$l$P!K4JC1$G$9!#(B

@c   If the new mode is similar to an old one, it is often unwise to modify
@c the old one to serve two purposes, since it may become harder to use and
@c maintain.  Instead, copy and rename an existing major mode definition
@c and alter the copy---or define a @dfn{derived mode} (@pxref{Derived
@c Modes}).  For example, Rmail Edit mode, which is in
@c @file{emacs/lisp/rmailedit.el}, is a major mode that is very similar to
@c Text mode except that it provides three additional commands.  Its
@c definition is distinct from that of Text mode, but was derived from it.
$B?7$?$J%b!<%I$,4{B8$N%b!<%I$KN`;w$7$F$$$F$b!"(B
$B4{B8$N%b!<%I$r(B2$B$D$NL\E*$r2L$?$9$h$&$K=$@5$9$k$N$O(B
$B8-$$$3$H$G$O$"$j$^$;$s!#(B
$B$=$N$h$&$K$9$k$H!";H$$Fq$/J]<i$7Fq$/$J$k$+$i$G$9!#(B
$B$=$N$+$o$j$K!"4{B8$N%a%8%c!<%b!<%I$NDj5A$r%3%T!<$7L>A0JQ$($F$+$i!"(B
$B%3%T!<$rJQ99$7$^$9!#(B
$B$"$k$$$O!"(B@dfn{$BGI@8%b!<%I(B} $B!J(Bderived mode$B!K(B
$B!J(B@pxref{Derived Modes}$B!K$rDj5A$7$^$9!#(B
$B$?$H$($P!"(B@file{emacs/lisp/rmailedit.el}$B$K$"$k(Brmail$BJT=8%b!<%I$O!"(B
$B%F%-%9%H!J(Btext$B!K%b!<%I$KHs>o$K$h$/;w$?%a%8%c!<%b!<%I$G$9$,!"(B
$BDI2C%3%^%s%I$,(B3$B$D$"$j$^$9!#(B
$B$=$N$h$&$JDj5A$,%F%-%9%H!J(Btext$B!K%b!<%I$H$N0c$$$K$J$k$N$G$9$,!"(B
rmail$BJT=8%b!<%I$O%F%-%9%H!J(Btext$B!K%b!<%I$+$iGI@8$7$?$b$N$G$9!#(B

@c   Rmail Edit mode offers an example of changing the major mode
@c temporarily for a buffer, so it can be edited in a different way (with
@c ordinary Emacs commands rather than Rmail commands).  In such cases, the
@c temporary major mode usually has a command to switch back to the
@c buffer's usual mode (Rmail mode, in this case).  You might be tempted to
@c present the temporary redefinitions inside a recursive edit and restore
@c the usual ones when the user exits; but this is a bad idea because it
@c constrains the user's options when it is done in more than one buffer:
@c recursive edits must be exited most-recently-entered first.  Using an
@c alternative major mode avoids this limitation.  @xref{Recursive
@c Editing}.
rmail$BJT=8%b!<%I$O!"%P%C%U%!$N%a%8%c!<%b!<%I$r0l;~E*$KJQ99$7$F(B
$B%P%C%U%!$rJL$NJ}K!!J(Brmail$B$N%3%^%s%I$G$O$J$/(B
Emacs$B$NIaDL$N%3%^%s%I!K$GJT=8$G$-$k$h$&$K$9$kNcBj$G$9!#(B
$B$=$N$h$&$J>l9g!"0l;~E*$J%a%8%c!<%b!<%I$K$O!"IaDL!"(B
$B%P%C%U%!$NDL>o$N%b!<%I!J$3$N>l9g$K$O(Brmail$B%b!<%I!K$KLa$k(B
$B%3%^%s%I$,$"$j$^$9!#(B
$BFI<T$O!":F5"JT=8$NCf$G0l;~E*$K:FDj5A$7!"(B
$B%f!<%6!<$,:F5"JT=8$rH4$1$k$H$b$H$KLa$9J}K!$KL%N;$5$l$k$+$b$7$l$^$;$s!#(B
$B$7$+$7!"$3$l$rJ#?t$N%P%C%U%!$G9T$&$H!"(B
$B:F5"JT=8$O$b$C$H$b:G6a$KF~$C$?:F5"$+$i$^$:H4$1$k$N$G!"(B
$B%f!<%6!<$NA*Br$K@)Ls$r2]$9$3$H$K$J$j0-$$J}K!$G$9!#(B
$BJL$N%a%8%c!<%b!<%I$r;H$($P$3$N$h$&$J@)Ls$r2sHr$G$-$^$9!#(B
@xref{Recursive Editing}$B!#(B

@c   The standard GNU Emacs Lisp library directory contains the code for
@c several major modes, in files such as @file{text-mode.el},
@c @file{texinfo.el}, @file{lisp-mode.el}, @file{c-mode.el}, and
@c @file{rmail.el}.  You can study these libraries to see how modes are
@c written.  Text mode is perhaps the simplest major mode aside from
@c Fundamental mode.  Rmail mode is a complicated and specialized mode.
$BI8=`$N(BGNU Emacs Lisp$B$N%i%$%V%i%j$N%G%#%l%/%H%j$K$O!"(B
@file{text-mode.el}$B!"(B@file{texinfo.el}$B!"(B@file{lisp-mode.el}$B!"(B
@file{c-mode.el}$B!"(B@file{rmail.el}$B$J$I$N%U%!%$%k$K(B
$B$$$/$D$+$N%a%8%c!<%b!<%I$N%3!<%I$,<}$a$F$"$j$^$9!#(B
$B%b!<%I$N=q$-J}$rM}2r$9$k$?$a$K$3$l$i$N%i%$%V%i%j$rD4$Y$i$l$^$9!#(B
$B%F%-%9%H!J(Btext$B!K%b!<%I$O!"4pK\!J(Bfundamental$B!K%b!<%I$K$D$$$G!"(B
$B$b$C$H$bC1=c$J%a%8%c!<%b!<%I$G$9!#(B
rmail$B%b!<%I$OJ#;($JFC2=$5$l$?%b!<%I$G$9!#(B

@menu
* Major Mode Conventions::  Coding conventions for keymaps, etc.
* Example Major Modes::     Text mode and Lisp modes.
* Auto Major Mode::         How Emacs chooses the major mode automatically.
* Mode Help::               Finding out how to use a mode.
* Derived Modes::           Defining a new major mode based on another major 
                              mode.
@end menu

@node Major Mode Conventions
@c @subsection Major Mode Conventions
@subsection $B%a%8%c!<%b!<%I$N47=,(B

@c   The code for existing major modes follows various coding conventions,
@c including conventions for local keymap and syntax table initialization,
@c global names, and hooks.  Please follow these conventions when you
@c define a new major mode:
$B4{B8$N%a%8%c!<%b!<%I$N%3!<%I$G$O!"(B
$B%m!<%+%k%-!<%^%C%W$d9=J8%F!<%V%k$N=i4|2=!"%0%m!<%P%k$JL>A0!"%U%C%/$J$I$N(B
$B$5$^$6$^$J%3!<%G%#%s%0>e$N47=,$rF'=1$7$F$$$^$9!#(B
$BFI<T$,?7$?$J%a%8%c!<%b!<%I$rDj5A$9$k$H$-$K$O!"(B
$B$3$l$i$N47=,$K=>$C$F$/$@$5$$!#(B

@itemize @bullet
@item
@c Define a command whose name ends in @samp{-mode}, with no arguments,
@c that switches to the new mode in the current buffer.  This command
@c should set up the keymap, syntax table, and buffer-local variables in an
@c existing buffer, without changing the buffer's contents.
$B%+%l%s%H%P%C%U%!$K$*$$$F?7$7$$%b!<%I$K@Z$jBX$($k(B
$B0z?t$J$7$N%3%^%s%I$rDj5A$7!"$=$NL>A0$O(B@samp{-mode}$B$G=*$k$3$H!#(B
$B$3$N%3%^%s%I$,!"%-!<%^%C%W!"9=J8%F!<%V%k!"(B
$B4{B8%P%C%U%!$K%P%C%U%!%m!<%+%k$JJQ?t$r@_Dj$9$k$,!"(B
$B%P%C%U%!$NFbMF$OJQ99$7$J$$$3$H!#(B

@item
@c Write a documentation string for this command that describes the
@c special commands available in this mode.  @kbd{C-h m}
@c (@code{describe-mode}) in your mode will display this string.
$B$3$N%b!<%I$G;H$($kFCJL$J%3%^%s%I$K4X$7$F5-=R$7$?(B
$B$3$N%3%^%s%I$KBP$9$k@bL@J8;zNs$r=q$/!#(B
$BFI<T$N%b!<%I$G(B@kbd{C-h m}$B!J(B@code{describe-mode}$B!K$r;H$&$H!"(B
$B$3$N@bL@J8;zNs$rI=<($9$k!#(B

@c The documentation string may include the special documentation
@c substrings, @samp{\[@var{command}]}, @samp{\@{@var{keymap}@}}, and
@c @samp{\<@var{keymap}>}, that enable the documentation to adapt
@c automatically to the user's own key bindings.  @xref{Keys in
@c Documentation}.
$B@bL@J8;zNs$G$O!"(B@samp{\[@var{command}]}$B!"(B@samp{\@{@var{keymap}@}}$B!"(B
@samp{\<@var{keymap}>}$B$NFCJL$J=q$-J}$r;H$(!"(B
$B$3$l$i$O%f!<%6!<FH<+$N%-!<%P%$%s%G%#%s%0$K<+F0E*$KCV$-49$($i$l$k!#(B
@pxref{Keys in Documentation}$B!#(B

@item
@c The major mode command should start by calling
@c @code{kill-all-local-variables}.  This is what gets rid of the
@c buffer-local variables of the major mode previously in effect.
$B%a%8%c!<%b!<%I%3%^%s%I$O!"(B
@code{kill-all-local-variables}$B$N8F$S=P$7$+$i;O$a$k$3$H!#(B
$B$=$l0JA0$KM-8z$G$"$C$?%a%8%c!<%b!<%I$N%P%C%U%!%m!<%+%k$JJQ?t$K(B
$BBP=h$9$k$?$a$G$"$k!#(B

@item
@c The major mode command should set the variable @code{major-mode} to the
@c major mode command symbol.  This is how @code{describe-mode} discovers
@c which documentation to print.
$B%a%8%c!<%b!<%I%3%^%s%I$O!"(B
$BJQ?t(B@code{major-mode}$B$K%a%8%c!<%b!<%I%3%^%s%I$N%7%s%\%k$r@_Dj$9$k$3$H!#(B
$B$3$l$K$h$j!"(B@code{describe-mode}$B$,I=<($9$Y$-@bL@J8$rA\$7=P$9!#(B

@item
@c The major mode command should set the variable @code{mode-name} to the
@c ``pretty'' name of the mode, as a string.  This string appears in the
@c mode line.
$B%a%8%c!<%b!<%I%3%^%s%I$O!"(B
$BJQ?t(B@code{mode-name}$B$K%b!<%I$N!X0&>N!Y$rJ8;zNs$H$7$F@_Dj$9$k$3$H!#(B
$B$3$NJ8;zNs$,%b!<%I9T$K8=$l$k!#(B

@item
@c @cindex functions in modes
@cindex $B%b!<%I$N4X?t72(B
@cindex $B4X?t72!"%b!<%I(B
@c Since all global names are in the same name space, all the global
@c variables, constants, and functions that are part of the mode should
@c have names that start with the major mode name (or with an abbreviation
@c of it if the name is long).  @xref{Coding Conventions}.
$B$9$Y$F$N%0%m!<%P%k$JL>A0$OF10l$NL>A06u4V$K$"$k$N$G!"(B
$B%b!<%I$N9=@.MWAG$G$"$k$9$Y$F$N%0%m!<%P%kJQ?t!"Dj?t!"4X?t$O!"(B
$B%a%8%c!<%b!<%IL>!JL>A0$,D9$1$l$P!"$=$N>JN,!K$G;O$^$k$3$H!#(B
@pxref{Coding Conventions}$B!#(B

@item
@c @cindex keymaps in modes
@cindex $B%b!<%I$N%-!<%^%C%W(B
@cindex $B%-!<%^%C%W!"%b!<%I(B
@c The major mode should usually have its own keymap, which is used as the
@c local keymap in all buffers in that mode.  The major mode command should
@c call @code{use-local-map} to install this local map.  @xref{Active
@c Keymaps}, for more information.
$B%a%8%c!<%b!<%I$K$O!"DL>o!"$=$lFH<+$N%-!<%^%C%W$,$"$k$O$:$G!"(B
$BEv3:%b!<%I$N$9$Y$F$N%P%C%U%!$G%m!<%+%k%-!<%^%C%W$H$7$F;H$o$l$k!#(B
$B%a%8%c!<%b!<%I%3%^%s%I$O!"(B@code{use-local-map}$B$r8F$S=P$7$F!"(B
$B$=$N%m!<%+%k%-!<%^%C%W$r@_Dj$9$k$3$H!#(B
$B>\$7$/$O!"(B@pxref{Active Keymaps}$B!#(B

@c This keymap should be stored permanently in a global variable named
@c @code{@var{modename}-mode-map}.  Normally the library that defines the
@c mode sets this variable.
$B$3$N%-!<%^%C%W$O!"(B@code{@var{modename}-mode-map}$B$H$$$&L>A0$N(B
$B%0%m!<%P%kJQ?t$K915WE*$KJ];}$9$k$3$H!#(B
$BDL>o!"%b!<%I$rDj5A$9$k%i%$%V%i%j$G$3$NJQ?t$K@_Dj$9$k!#(B

@c @xref{Tips for Defining}, for advice about how to write the code to set
@c up the mode's keymap variable.
$B%b!<%I$N%-!<%^%C%WJQ?t$K@_Dj$9$k%3!<%I$N=q$-J}$K4X$9$k=u8@$K$D$$$F$O(B
@pxref{Tips for Defining}$B!#(B

@item
@c The key sequences bound in a major mode keymap should usually start with
@c @kbd{C-c}, followed by a control character, a digit, or @kbd{@{},
@c @kbd{@}}, @kbd{<}, @kbd{>}, @kbd{:} or @kbd{;}.  The other punctuation
@c characters are reserved for minor modes, and ordinary letters are
@c reserved for users.
$B%a%8%c!<%b!<%I$N%-!<%^%C%W$G%P%$%s%I$5$l$?%-!<Ns$O!"(B
$BDL>o!"(B@kbd{C-c}$B$G;O$^$j!"%3%s%H%m!<%kJ8;z!"?t;zJ8;z!"(B@kbd{@{}$B!"(B
@kbd{@}}$B!"(B@kbd{<}$B!"(B@kbd{>}$B!"(B@kbd{:}$B!"(B@kbd{;}$B$N$$$:$l$+$,B3$/$h$&$K$9$k!#(B
$B$=$NB>$N6gFIE@J8;z$O%^%$%J%b!<%I8~$1$KM=Ls$5$l$F$$$k!#(B
$B$^$?!"DL>o$N1QJ8;z$O%f!<%6!<8~$1$KM=Ls$5$l$F$$$k!#(B

@c It is reasonable for a major mode to rebind a key sequence with a
@c standard meaning, if it implements a command that does ``the same job''
@c in a way that fits the major mode better.  For example, a major mode for
@c editing a programming language might redefine @kbd{C-M-a} to ``move to
@c the beginning of a function'' in a way that works better for that
@c language.
$B%a%8%c!<%b!<%I$K$*$$$F$O!"$=$N%b!<%I$K$h$/E,9g$7$?7A$G(B
$B!XF1$8;E;v!Y$r9T$&%3%^%s%I$G$"$k$J$i$P!"(B
$BI8=`E*$J0UL#$r;}$D%-!<Ns$KEv3:%3%^%s%I$r:F%P%$%s%I$7$F$b9gM}E*$G$"$k!#(B
$B$?$H$($P!"%W%m%0%i%`8@8lJT=8MQ$N%a%8%c!<%b!<%I$G$O!"(B
@kbd{C-M-a}$B$rEv3:8@8l$K$&$^$/E,9g$7$?J}K!$G(B
$B!X4X?t$N@hF,$X0\F0$9$k!Y%3%^%s%I$K:FDj5A$9$k!#(B

@c Major modes such as Dired or Rmail that do not allow self-insertion of
@c text can reasonably redefine letters and other printing characters as
@c editing commands.  Dired and Rmail both do this.
$B%F%-%9%HA^F~$r5v$5$J$$(Bdired$B$d(Brmail$B$J$I$N%a%8%c!<%b!<%I$G$O!"(B
$B1QJ8;z$dB>$N0u;zJ8;z$rJT=8%3%^%s%I$H$7$F:FDj5A$9$k$N$b9gM}E*$G$"$k!#(B
dired$B$b(Brmail$B$b$3$&$7$F$$$k!#(B

@item
@c @cindex syntax tables in modes
@cindex $B%b!<%I$N9=J8%F!<%V%k(B
@cindex $B9=J8%F!<%V%k!"%b!<%I(B
@c The mode may have its own syntax table or may share one with other
@c related modes.  If it has its own syntax table, it should store this in
@c a variable named @code{@var{modename}-mode-syntax-table}.  @xref{Syntax
@c Tables}.
$B%b!<%I$G$O!"FH<+$N9=J8%F!<%V%k$rMQ0U$9$k$+!"(B
$BB>$N4XO"$9$k%b!<%I$H9=J8%F!<%V%k$r6&M-$9$k!#(B
$BFH<+$N9=J8%F!<%V%k$rMQ0U$9$k>l9g$K$O!"(B
@code{@var{modename}-mode-syntax-table}$B$H$$$&L>A0$NJQ?t$KJ];}$9$k$3$H!#(B
@pxref{Syntax Tables}$B!#(B

@item
@c If the mode handles a language that has a syntax for comments, it should
@c set the variables that define the comment syntax.  @xref{Options for
@c Comments,, Options Controlling Comments, emacs, The GNU Emacs Manual}.
$B%3%a%s%H$r=q$1$k8@8l$r07$&%b!<%I$G$O!"(B
$B%3%a%s%H$N9=J8$rDj5A$9$kJQ?t$K@_Dj$9$k$3$H!#(B
@pxref{Options for Comments,, $B%3%a%s%H$r@)8f$9$k%*%W%7%g%s(B, emacs,
GNU Emacs $B%^%K%e%"%k(B}$B!#(B

@item
@c @cindex abbrev tables in modes
@cindex $B%b!<%I$NN,8lI=(B
@cindex $BN,8lI=!"%b!<%I(B
@c The mode may have its own abbrev table or may share one with other
@c related modes.  If it has its own abbrev table, it should store this in
@c a variable named @code{@var{modename}-mode-abbrev-table}.  @xref{Abbrev
@c Tables}.
$B%b!<%I$G$O!"FH<+$NN,8lI=$rMQ0U$9$k$+!"(B
$BB>$N4XO"$9$k%b!<%I$HN,8lI=$r6&M-$9$k!#(B
$BFH<+$NN,8lI=$rMQ0U$9$k>l9g$K$O!"(B
@code{@var{modename}-mode-abbrev-table}$B$H$$$&L>A0$NJQ?t$KJ];}$9$k$3$H!#(B
@pxref{Abbrev Tables}$B!#(B

@item
@c The mode should specify how to do highlighting for Font Lock mode, by
@c setting up a buffer-local value for the variable
@c @code{font-lock-defaults} (@pxref{Font Lock Mode}).
$B%b!<%I$G$O!"(B
$B%P%C%U%!%m!<%+%k$JJQ?t(B@code{font-lock-defaults}
$B!J(B@pxref{Font Lock Mode}$B!K$K@_Dj$7$F!"(B
$B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I$KBP$7$F6/D4I=<($NJ}K!$r;XDj$9$k$3$H!#(B

@item
@c The mode should specify how Imenu should find the definitions or
@c sections of a buffer, by setting up a buffer-local value for the
@c variable @code{imenu-generic-expression} or
@c @code{imenu-create-index-function} (@pxref{Imenu}).
$B%b!<%I$G$O!"(B
$B%P%C%U%!%m!<%+%k$JJQ?t(B@code{imenu-generic-expression}$B$+(B
@code{imenu-create-index-function}$B!J(B@pxref{Imenu}$B!K$K@_Dj$7$F!"(B
i$B%a%K%e!<$,$I$N$h$&$K%P%C%U%!Fb$NDj5A$d@a$rC5$9$Y$-$+$r;XDj$9$k$3$H!#(B

@item
@c Use @code{defvar} or @code{defcustom} to set mode-related variables, so
@c that they are not reinitialized if they already have a value.  (Such
@c reinitialization could discard customizations made by the user.)
$B%b!<%I$K4XO"$9$kJQ?t$N@_Dj$K$O(B@code{defvar}$B$+(B@code{defcustom}$B$r;H$$!"(B
$B$=$l$i$KCM$,@_Dj$5$l$F$$$k>l9g$K$O:F=i4|2=$7$J$$$h$&$K$9$k!#(B
$B!J:F=i4|2=$9$k$H%f!<%6!<$N%+%9%?%^%$%:$rGQ4~$7$F$7$^$&!#!K(B

@item
@c @cindex buffer-local variables in modes
@cindex $B%b!<%I$N%P%C%U%!%m!<%+%k$JJQ?t(B
@cindex $B%P%C%U%!%m!<%+%k$JJQ?t!"%b!<%I(B
@c To make a buffer-local binding for an Emacs customization variable, use
@c @code{make-local-variable} in the major mode command, not
@c @code{make-variable-buffer-local}.  The latter function would make the
@c variable local to every buffer in which it is subsequently set, which
@c would affect buffers that do not use this mode.  It is undesirable for a
@c mode to have such global effects.  @xref{Buffer-Local Variables}.
Emacs$B$N%+%9%?%^%$%:JQ?t$KBP$9$k%P%C%U%!%m!<%+%k$JB+G{$O!"(B
$B%a%8%c!<%b!<%I%3%^%s%I$K$*$$$F(B
@code{make-variable-buffer-local}$B$G$O$J$/(B
@code{make-local-variable}$B$G9T$&!#(B
$BA0<T$N4X?t$O!"$9$Y$F$N%P%C%U%!$K$*$$$F$=$l0J9_$K@_Dj$5$l$kEv3:JQ?t$r(B
$B%P%C%U%!%m!<%+%k$K$7$F$7$^$$!"(B
$B$3$N%b!<%I$r;H$o$J$$%P%C%U%!$K$b1F6A$9$k!#(B
$B%b!<%I$K$=$N$h$&$JBg6IE*$J8z2L$,$"$k$N$OK>$^$7$/$J$$!#(B
@pxref{Buffer-Local Variables}$B!#(B

@c It's OK to use @code{make-variable-buffer-local}, if you wish, for a
@c variable used only within a single Lisp package.
$BC10l$N(BLisp$B%Q%C%1!<%8Fb$N$_$K$*$$$F;H$o$l$kJQ?t$KBP$7$F$O!"(B
$BI,MW$J$i$P!"(B@code{make-variable-buffer-local}$B$r;H$C$F$b$h$$!#(B

@item
@c @cindex mode hook
@c @cindex major mode hook
@cindex $B%b!<%I%U%C%/(B
@cindex $B%a%8%c!<%b!<%I%U%C%/(B
@c Each major mode should have a @dfn{mode hook} named
@c @code{@var{modename}-mode-hook}.  The major mode command should run that
@c hook, with @code{run-hooks}, as the very last thing it
@c does.  @xref{Hooks}.
$B3F%a%8%c!<%b!<%I$K$O!"(B
@code{@var{modename}-mode-hook}$B$H$$$&L>A0$N(B
@dfn{$B%b!<%I%U%C%/(B}$B!J(Bmode hook$B!K$,$"$k$3$H!#(B
$B%b!<%I%3%^%s%I$O!":G8e$K(B@code{run-hooks}$B$rMQ$$$F%U%C%/$r<B9T$9$k$3$H!#(B
@pxref{Hooks}$B!#(B

@item
@c The major mode command may also run the hooks of some more basic modes.
@c For example, @code{indented-text-mode} runs @code{text-mode-hook} as
@c well as @code{indented-text-mode-hook}.  It may run these other hooks
@c immediately before the mode's own hook (that is, after everything else),
@c or it may run them earlier.
$B%a%8%c!<%b!<%I%3%^%s%I$O!"$h$j4pK\E*$J%b!<%I$N%U%C%/$r<B9T$7$F$b$h$$!#(B
$B$?$H$($P!"(B@code{indented-text-mode}$B$O!"(B
@code{indented-text-mode-hook}$B$K2C$($F(B@code{text-mode-hook}$B$b<B9T$9$k!#(B
$B<+A0$N%U%C%/$r<B9T$9$kD>A0!J$D$^$j@_Dj$,=*$C$?$"$H!K(B
$B$K$3$l$i$NB>$N%U%C%/$r<B9T$9$k$+!"$h$j=i4|$NCJ3,$G<B9T$7$F$b$h$$!#(B

@item
@c If something special should be done if the user switches a buffer from
@c this mode to any other major mode, this mode can set up a buffer-local
@c value for @code{change-major-mode-hook} (@pxref{Creating Buffer-Local}).
$B%f!<%6!<$,%P%C%U%!$r$3$N%b!<%I$+$iJL$N%a%8%c!<%b!<%I$K@Z$jBX$($?$H$-$K(B
$BFCJL$J$3$H$r9T$&I,MW$,$"$k>l9g!"(B
$B$3$N%b!<%I$G$O!"(B@code{change-major-mode-hook}$B!J(B@pxref{Creating Buffer-Local}$B!K(B
$B$N%P%C%U%!%m!<%+%k$JCM$r@_Dj$7$F$*$/!#(B

@item
@c If this mode is appropriate only for specially-prepared text, then the
@c major mode command symbol should have a property named @code{mode-class}
@c with value @code{special}, put on as follows:
$B$3$N%b!<%I$,FCJL$K=`Hw$7$?%F%-%9%H$KBP$7$F$N$_M-8z$J>l9g$K$O!"(B
$B%a%8%c!<%b!<%I%3%^%s%I$N%7%s%\%k$K$O!"(B
$B$D$.$N$h$&$KB0@-(B@code{mode-class}$B$KCM(B@code{special}$B$r@_Dj$7$F$*$/$3$H!#(B

@c @cindex @code{mode-class} property
@cindex @code{mode-class}$BB0@-(B
@cindex $BB0@-(B@code{mode-class}
@cindex @code{special}
@example
(put 'funny-mode 'mode-class 'special)
@end example

@noindent
@c This tells Emacs that new buffers created while the current buffer has
@c Funny mode should not inherit Funny mode.  Modes such as Dired, Rmail,
@c and Buffer List use this feature.
$B$3$l$O!"%+%l%s%H%P%C%U%!$,(Bfunny$B%b!<%I$N$H$-$K?7$?$J%P%C%U%!$r(B
$B:n@.$7$F$b!"?7$7$$%P%C%U%!$G$O(Bfunny$B%b!<%I$r7Q>5$7$J$$$h$&$K(BEmacs$B$K;X<($9$k!#(B
dired$B!"(Brmail$B!"%P%C%U%!0lMw$J$I$N%b!<%I$G$O$3$N5!G=$r;H$C$F$$$k!#(B

@item
@c If you want to make the new mode the default for files with certain
@c recognizable names, add an element to @code{auto-mode-alist} to select
@c the mode for those file names.  If you define the mode command to
@c autoload, you should add this element in the same file that calls
@c @code{autoload}.  Otherwise, it is sufficient to add the element in the
@c file that contains the mode definition.  @xref{Auto Major Mode}.
$B?7$7$$%b!<%I$r<1JL2DG=$JFCDj$NL>A0$N%U%!%$%k$KBP$9$k%G%U%)%k%H$K$7$?$$(B
$B>l9g$K$O!"$=$N$h$&$JL>A0$N%U%!%$%k$KBP$7$FEv3:%b!<%I$rA*Br$9$k$?$a$N(B
$BMWAG$r(B@code{auto-mode-alist}$B$KDI2C$9$k!#(B
$B%b!<%I%3%^%s%I$r<+F0%m!<%I$HDj5A$9$k>l9g!"(B
@code{autoload}$B$r8F$S=P$7$F$$$kF1$8%U%!%$%k$K(B
$B$=$N$h$&$JMWAG$rDI2C$7$F$*$/$3$H!#(B
$B$=$&$G$J$1$l$P!"%b!<%IDj5A$r<}$a$?%U%!%$%k$KEv3:MWAG$rF~$l$k$@$1$G==J,$G$"$k!#(B
@pxref{Auto Major Mode}$B!#(B

@item
@c @cindex @file{.emacs} customization
@cindex @file{.emacs}$B$N%+%9%?%^%$%:(B
@cindex $B%+%9%?%^%$%:!"(B@file{.emacs}
@c In the documentation, you should provide a sample @code{autoload} form
@c and an example of how to add to @code{auto-mode-alist}, that users can
@c include in their @file{.emacs} files.
$B@bL@J8$K$O!"%f!<%6!<$,8D?M$N%U%!%$%k(B@file{.emacs}$B$K=q$1$k$h$&$K!"(B
@code{autoload}$B$NNc!"(B
@code{auto-mode-alist}$B$X$NDI2CJ}K!$NNc$r5-:\$9$k$3$H!#(B

@item
@c @cindex mode loading
@cindex $B%b!<%I$N%m!<%I(B
@cindex $B%m!<%I!"%b!<%I(B
@c The top-level forms in the file defining the mode should be written so
@c that they may be evaluated more than once without adverse consequences.
@c Even if you never load the file more than once, someone else will.
$B%b!<%I$rDj5A$9$k%U%!%$%k$N%H%C%W%l%Y%k$N%U%)!<%`$O!"(B
$B$=$l$i$rJ#?t2sI>2A$7$F$bITMx$J7k2L$K$J$i$J$$$h$&$K=q$$$F$*$/$3$H!#(B
$BFI<T$,Ev3:%U%!%$%k$rJ#?t2s%m!<%I$7$J$/$F$b!"C/$+$,$d$k$+$b$7$l$J$$!#(B
@end itemize

@node Example Major Modes
@c @subsection Major Mode Examples
@subsection $B%a%8%c!<%b!<%I$NNc(B

@c   Text mode is perhaps the simplest mode besides Fundamental mode.
@c Here are excerpts from  @file{text-mode.el} that illustrate many of
@c the conventions listed above:
$B4pK\!J(Bfundamental$B!K%b!<%I$r=|$/$H!"(B
$B%F%-%9%H!J(Btext$B!K%b!<%I$O$b$C$H$bC1=c$J%b!<%I$G$9!#(B
$B>e$K=R$Y$?47=,$NNc<($H$7$F!"(B@file{text-mode.el}$B$NH4?h$r$"$2$F$*$-$^$9!#(B

@smallexample
@group
@c ;; @r{Create mode-specific tables.}
;; @r{$B%b!<%I8GM-$N9=J8%F!<%V%k$r:n$k(B}
(defvar text-mode-syntax-table nil 
  "Syntax table used while in text mode.")
@end group

@group
(if text-mode-syntax-table
@c     ()              ; @r{Do not change the table if it is already set up.}
    ()              ; @r{$B9=J8%F!<%V%k$,4{B8$J$i$PJQ99$7$J$$(B}
  (setq text-mode-syntax-table (make-syntax-table))
  (modify-syntax-entry ?\" ".   " text-mode-syntax-table)
  (modify-syntax-entry ?\\ ".   " text-mode-syntax-table)
  (modify-syntax-entry ?' "w   " text-mode-syntax-table))
@end group

@group
(defvar text-mode-abbrev-table nil
  "Abbrev table used while in text mode.")
(define-abbrev-table 'text-mode-abbrev-table ())
@end group

@group
@c (defvar text-mode-map nil)   ; @r{Create a mode-specific keymap.}
(defvar text-mode-map nil)   ; @r{$B%b!<%I8GM-$N%-!<%^%C%W$r:n$k(B}

(if text-mode-map
@c     ()              ; @r{Do not change the keymap if it is already set up.}
    ()              ; @r{$B%-!<%^%C%W$,4{B8$J$i$PJQ99$7$J$$(B}
  (setq text-mode-map (make-sparse-keymap))
  (define-key text-mode-map "\t" 'indent-relative)
  (define-key text-mode-map "\es" 'center-line)
  (define-key text-mode-map "\eS" 'center-paragraph))
@end group
@end smallexample

@c   Here is the complete major mode function definition for Text mode:
$B$D$.$O!"%F%-%9%H!J(Btext$B!K%b!<%I$N%a%8%c!<%b!<%I4X?t$N40A4$JDj5A$G$9!#(B

@smallexample
@group
(defun text-mode ()
  "Major mode for editing text intended for humans to read@enddots{}
 Special commands: \\@{text-mode-map@}
@end group
@group
Turning on text-mode runs the hook `text-mode-hook'."
  (interactive)
  (kill-all-local-variables)
  (use-local-map text-mode-map)
@end group
@group
  (setq local-abbrev-table text-mode-abbrev-table)
  (set-syntax-table text-mode-syntax-table)
@end group
@group
  (make-local-variable 'paragraph-start)
  (setq paragraph-start (concat "[ \t]*$\\|" page-delimiter))
  (make-local-variable 'paragraph-separate)
  (setq paragraph-separate paragraph-start)
@end group
@group
  (setq mode-name "Text")
  (setq major-mode 'text-mode)
@c   (run-hooks 'text-mode-hook))      ; @r{Finally, this permits the user to}
@c                                     ;   @r{customize the mode with a hook.}
  (run-hooks 'text-mode-hook))      ; @r{$B:G8e$K!"%U%C%/$K$h$k%b!<%I$N(B}
                                    ;   @r{$B%+%9%?%^%$%:$r%f!<%6!<$K5v$9(B}
@end group
@end smallexample

@cindex @file{lisp-mode.el}
@c   The three Lisp modes (Lisp mode, Emacs Lisp mode, and Lisp
@c Interaction mode) have more features than Text mode and the code is
@c correspondingly more complicated.  Here are excerpts from
@c @file{lisp-mode.el} that illustrate how these modes are written.
3$B$D$N(Blisp$B%b!<%I!J(Blisp$B%b!<%I!"(Bemacs-lisp$B%b!<%I!"(Blisp$BBPOC%b!<%I!K$K$O!"(B
$B%F%-%9%H!J(Btext$B!K%b!<%I$h$jB?$/$N5!G=$,$"$j!"(B
$B$=$l$K1~$8$F%3!<%I$b$h$jJ#;($G$9!#(B
$B$3$l$i$N%b!<%I$N=q$-J}$rNc<($9$k(B
@file{lisp-mode.el}$B$+$i$NH4?h$r$"$2$F$*$-$^$9!#(B

@c @cindex syntax table example
@cindex $B9=J8%F!<%V%k$NNc(B
@cindex $BNc!"9=J8%F!<%V%k(B
@smallexample
@group
@c ;; @r{Create mode-specific table variables.}
;; @r{$B%b!<%I8GM-$N9=J8%F!<%V%k$r:n@.$9$k(B}
(defvar lisp-mode-syntax-table nil "")  
(defvar emacs-lisp-mode-syntax-table nil "")
(defvar lisp-mode-abbrev-table nil "")
@end group

@group
@c (if (not emacs-lisp-mode-syntax-table) ; @r{Do not change the table}
@c                                        ;   @r{if it is already set.}
(if (not emacs-lisp-mode-syntax-table) ; @r{$B9=J8%F!<%V%k$,4{B8$J$i$P(B}
                                       ;   @r{$BJQ99$7$J$$(B}
    (let ((i 0))
      (setq emacs-lisp-mode-syntax-table (make-syntax-table))
@end group

@group
@c       ;; @r{Set syntax of chars up to 0 to class of chars that are}
@c       ;;   @r{part of symbol names but not words.}
@c       ;;   @r{(The number 0 is @code{48} in the @sc{ASCII} character set.)}
      ;; @r{0$B$^$G$NJ8;z$K!"C18l9=@.J8;z$G$O$J$$$,(B}
      ;; @r{$B%7%s%\%kL>9=@.J8;z$G$"$k%/%i%9$r@_Dj$9$k(B}
      ;; @r{($BJ8;z(B0$B$O!"(B@sc{ASCII}$BJ8;z=89g$G$O(B@code{48})}
      (while (< i ?0) 
        (modify-syntax-entry i "_   " emacs-lisp-mode-syntax-table)
        (setq i (1+ i)))
      @dots{}
@end group
@group
@c       ;; @r{Set the syntax for other characters.}
      ;; @r{$BB>$NJ8;z$N9=J8$r@_Dj$9$k(B}
      (modify-syntax-entry ?  "    " emacs-lisp-mode-syntax-table)
      (modify-syntax-entry ?\t "    " emacs-lisp-mode-syntax-table)
      @dots{}
@end group
@group
      (modify-syntax-entry ?\( "()  " emacs-lisp-mode-syntax-table)
      (modify-syntax-entry ?\) ")(  " emacs-lisp-mode-syntax-table)
      @dots{}))
@c ;; @r{Create an abbrev table for lisp-mode.}
;; @r{lisp$B%b!<%I8~$1$NN,8lI=$r:n$k(B}
(define-abbrev-table 'lisp-mode-abbrev-table ())
@end group
@end smallexample

@c   Much code is shared among the three Lisp modes.  The following
@c function sets various variables; it is called by each of the major Lisp
@c mode functions:
3$B$D$N(Blisp$B%b!<%I$OB?$/$N%3!<%I$r6&M-$7$F$$$^$9!#(B
$B$D$.$N4X?t$O$5$^$6$^$JJQ?t$K@_Dj$7$^$9!#(B
lisp$B%b!<%I$N3F%a%8%c!<%b!<%I4X?t$,8F$S=P$7$^$9!#(B

@smallexample
@group
(defun lisp-mode-variables (lisp-syntax)
  (cond (lisp-syntax
	  (set-syntax-table lisp-mode-syntax-table)))
  (setq local-abbrev-table lisp-mode-abbrev-table)
  @dots{}
@end group
@end smallexample

@c   Functions such as @code{forward-paragraph} use the value of the
@c @code{paragraph-start} variable.  Since Lisp code is different from
@c ordinary text, the @code{paragraph-start} variable needs to be set
@c specially to handle Lisp.  Also, comments are indented in a special
@c fashion in Lisp and the Lisp modes need their own mode-specific
@c @code{comment-indent-function}.  The code to set these variables is the
@c rest of @code{lisp-mode-variables}.
@code{forward-paragraph}$B$J$I$N4X?t$O!"(B
$BJQ?t(B@code{paragraph-start}$B$NCM$r;H$$$^$9!#(B
Lisp$B$N%3!<%I$OIaDL$N%F%-%9%H$H$O0[$J$k$N$G!"(B
Lisp$B$r07$($k$h$&$KJQ?t(B@code{paragraph-start}$B$rFCJL$K@_Dj$9$kI,MW$,$"$j$^$9!#(B
$B$^$?!"(BLisp$B$G$O%3%a%s%H$N;z2<$2$OFC<l$J7A$J$N$G!"(B
$B3F(Blisp$B%b!<%I$K$OFH<+$N%b!<%I8GM-$N(B@code{comment-indent-function}$B$,I,MW$G$9!#(B
$B$3$l$i$NJQ?t$K@_Dj$9$k%3!<%I$,!"(B
@code{lisp-mode-variables}$B$N;D$j$NItJ,$G$9!#(B

@smallexample
@group
  (make-local-variable 'paragraph-start)
  (setq paragraph-start (concat page-delimiter "\\|$" ))
  (make-local-variable 'paragraph-separate)
  (setq paragraph-separate paragraph-start)
  @dots{}
@end group
@group
  (make-local-variable 'comment-indent-function)
  (setq comment-indent-function 'lisp-comment-indent))
@end group
@end smallexample

@c   Each of the different Lisp modes has a slightly different keymap.  For
@c example, Lisp mode binds @kbd{C-c C-z} to @code{run-lisp}, but the other
@c Lisp modes do not.  However, all Lisp modes have some commands in
@c common.  The following code sets up the common commands:
$B3F(Blisp$B%b!<%I$G$O!"%-!<%^%C%W$,B?>/0[$J$j$^$9!#(B
$B$?$H$($P!"(Blisp$B%b!<%I$G$O(B@kbd{C-c C-z}$B$r(B@code{run-lisp}$B$K%P%$%s%I$7$^$9$,!"(B
$BB>$N(Blisp$B%b!<%I$G$O$=$&$7$^$;$s!#(B
$B$D$.$N%3!<%I$O!"6&DL$9$k%3%^%s%I$r@_Dj$7$^$9!#(B

@smallexample
@group
(defvar shared-lisp-mode-map ()
  "Keymap for commands shared by all sorts of Lisp modes.")

(if shared-lisp-mode-map
    ()
   (setq shared-lisp-mode-map (make-sparse-keymap))
   (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp)
   (define-key shared-lisp-mode-map "\177"
               'backward-delete-char-untabify))
@end group
@end smallexample

@noindent
@c And here is the code to set up the keymap for Lisp mode:
$B$D$.$O(Blisp$B%b!<%I8~$1$N%-!<%^%C%W$r@_Dj$9$k%3!<%I$G$9!#(B

@smallexample
@group
(defvar lisp-mode-map ()
  "Keymap for ordinary Lisp mode@enddots{}")

(if lisp-mode-map
    ()
  (setq lisp-mode-map (make-sparse-keymap))
  (set-keymap-parent lisp-mode-map shared-lisp-mode-map)
  (define-key lisp-mode-map "\e\C-x" 'lisp-eval-defun)
  (define-key lisp-mode-map "\C-c\C-z" 'run-lisp))
@end group
@end smallexample

@c   Finally, here is the complete major mode function definition for
@c Emacs Lisp mode.  
$B:G8e$K!"(Bemacs-lisp$B%b!<%I$N%a%8%c!<%b!<%I4X?t$N40A4$JDj5A$r<($7$^$9!#(B

@smallexample
@group
(defun lisp-mode ()
  "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp.
Commands:
Delete converts tabs to spaces as it moves back.
Blank lines separate paragraphs.  Semicolons start comments.
\\@{lisp-mode-map@}
Note that `run-lisp' may be used either to start an inferior Lisp job
or to switch back to an existing one.
@end group

@group
Entry to this mode calls the value of `lisp-mode-hook'
if that value is non-nil."
  (interactive)
  (kill-all-local-variables)
@end group
@group
@c   (use-local-map lisp-mode-map)          ; @r{Select the mode's keymap.}
@c   (setq major-mode 'lisp-mode)           ; @r{This is how @code{describe-mode}}
@c                                          ;   @r{finds out what to describe.}
@c   (setq mode-name "Lisp")                ; @r{This goes into the mode line.}
@c   (lisp-mode-variables t)                ; @r{This defines various variables.}
  (use-local-map lisp-mode-map)          ; @r{$B%b!<%I$N%-!<%^%C%W$rA*Br$9$k(B}
  (setq major-mode 'lisp-mode)           ; @r{$B$3$l$K$h$j(B@code{describe-mode}$B$O(B}
                                         ; @r{$B@bL@J8$rC5$7=P$;$k(B}
  (setq mode-name "Lisp")                ; @r{$B%b!<%I9T$KI=<($5$l$k(B}
  (lisp-mode-variables t)                ; @r{$B$5$^$6$^$JJQ?t$rDj5A$9$k(B}
@end group
@group
  (setq imenu-case-fold-search t)
  (set-syntax-table lisp-mode-syntax-table)
@c   (run-hooks 'lisp-mode-hook))           ; @r{This permits the user to use a}
@c                                          ;   @r{hook to customize the mode.}
  (run-hooks 'lisp-mode-hook))           ; @r{$B%U%C%/$K$h$k%b!<%I$N(B}
                                         ; @r{$B%+%9%?%^%$%:$r%f!<%6!<$K5v$9(B}
@end group
@end smallexample

@node Auto Major Mode
@c @subsection How Emacs Chooses a Major Mode
@subsection $B%a%8%c!<%b!<%I$NA*BrJ}K!(B

@c   Based on information in the file name or in the file itself, Emacs
@c automatically selects a major mode for the new buffer when a file is
@c visited.  It also processes local variables specified in the file text.
Emacs$B$O!"%U%!%$%kL>$d%U%!%$%k<+BN$N>pJs$r$b$H$K!"(B
$BEv3:%U%!%$%k$rK,Ld$9$k$H$-$N?7$7$$%P%C%U%!$KBP$9$k(B
$B%a%8%c!<%b!<%I$r<+F0E*$KA*Br$7$^$9!#(B
$B$^$?!"%U%!%$%kFb$N%F%-%9%H$G;XDj$5$l$?%m!<%+%kJQ?t$b=hM}$7$^$9!#(B

@c @deffn Command fundamental-mode
@deffn $B%3%^%s%I(B fundamental-mode
@c   Fundamental mode is a major mode that is not specialized for anything
@c in particular.  Other major modes are defined in effect by comparison
@c with this one---their definitions say what to change, starting from
@c Fundamental mode.  The @code{fundamental-mode} function does @emph{not}
@c run any hooks; you're not supposed to customize it.  (If you want Emacs
@c to behave differently in Fundamental mode, change the @emph{global}
@c state of Emacs.)
$B4pK\!J(Bfundamental$B!K%b!<%I$O!"FC2=$7$F$J$$%a%8%c!<%b!<%I$G$"$k!#(B
$BB>$N%a%8%c!<%b!<%I$O!"<B<AE*$K$O!"$3$N%b!<%I$H$NBPHf$GDj5A$5$l$F$$$k!#(B
$B$D$^$j!"4pK\!J(Bfundamental$B!K%b!<%I$+$i;O$a$F!"(B
$B$=$l$i$N%a%8%c!<%b!<%I$G$O$J$K$rJQ99$9$k$+$rDj5A$7$F$$$k!#(B
$B4X?t(B@code{fundamental-mode}$B$O%U%C%/$r<B9T(B@emph{$B$7$J$$(B}$B$?$a!"(B
$BFI<T$O%+%9%?%^%$%:$G$-$J$$!#(B
$B!J(BEmacs$B$N4pK\!J(Bfundamental$B!K%b!<%I$N$U$k$^$$$rJQ$($?$1$l$P!"(B
Emacs$B$N(B@emph{$BBg6IE*$J(B}$B>uBV$rJQ$($kI,MW$,$"$k!#!K(B
@end deffn

@c @deffn Command normal-mode &optional find-file
@deffn $B%3%^%s%I(B normal-mode &optional find-file
@c This function establishes the proper major mode and buffer-local variable
@c bindings for the current buffer.  First it calls @code{set-auto-mode},
@c then it runs @code{hack-local-variables} to parse, and bind or
@c evaluate as appropriate, the file's local variables.
$B$3$N4X?t$O!"%+%l%s%H%P%C%U%!$KBP$7$F(B
$BE,@Z$J%a%8%c!<%b!<%I$H%P%C%U%!%m!<%+%k$JJQ?t$r3NN)$9$k!#(B
$B$3$N4X?t$O$^$:(B@code{set-auto-mode}$B$r8F$S=P$7!"(B
$BB3$$$F!"%U%!%$%k$N%m!<%+%kJQ?t$rI,MW$K1~$8$F2r@O!"B+G{!"I>2A$9$k$?$a$K(B
@code{hack-local-variables}$B$r<B9T$9$k!#(B

@c If the @var{find-file} argument to @code{normal-mode} is non-@code{nil},
@c @code{normal-mode} assumes that the @code{find-file} function is calling
@c it.  In this case, it may process a local variables list at the end of
@c the file and in the @samp{-*-} line.  The variable
@c @code{enable-local-variables} controls whether to do so.  @xref{File
@c variables, , Local Variables in Files, emacs, The GNU Emacs Manual}, for
@c the syntax of the local variables section of a file.
@code{normal-mode}$B$KBP$9$k0z?t(B@var{find-file}$B$,(B@code{nil}$B0J30$G$"$k$H!"(B
@code{normal-mode}$B$O(B@code{find-file}$B$+$i8F$S=P$5$l$?$H2>Dj$9$k!#(B
$B$=$N>l9g!"%U%!%$%k$NKvHx$d(B@samp{-*-}$B$N7A<0$N9T$K$"$k(B
$B%m!<%+%kJQ?t%j%9%H$r=hM}$9$k$3$H$b$"$k!#(B
$BJQ?t(B@code{enable-local-variables}$B$O!"$3$N=hM}$r9T$&$+$I$&$+$r@)8f$9$k!#(B
$B%U%!%$%kFb$G$N%m!<%+%kJQ?t%j%9%H$N9=J8$K$D$$$F$O!"(B
@xref{File Variables,, $B%U%!%$%k$K%m!<%+%k$JJQ?t(B, emacs, GNU Emacs $B%^%K%e%"%k(B}$B!#(B

@c If you run @code{normal-mode} interactively, the argument
@c @var{find-file} is normally @code{nil}.  In this case,
@c @code{normal-mode} unconditionally processes any local variables list.
$BFI<T$,BPOCE*$K(B@code{normal-mode}$B$r<B9T$9$k$H(B
$B0z?t(B@var{find-file}$B$ODL>o(B@code{nil}$B$G$"$k!#(B
$B$=$N>l9g!"(B@code{normal-mode}$B$O!"%m!<%+%kJQ?t%j%9%H$rL5>r7o$K=hM}$9$k!#(B

@c @cindex file mode specification error
@cindex $B%U%!%$%k%b!<%I;XDj$N%(%i!<(B
@c @code{normal-mode} uses @code{condition-case} around the call to the
@c major mode function, so errors are caught and reported as a @samp{File
@c mode specification error},  followed by the original error message.
@code{normal-mode}$B$O!"%a%8%c!<%b!<%I4X?t$r8F$S=P$9<~$j$G$O(B
@code{condition-case}$B$r;H$&$N$G!"%(%i!<$rJdB-$7$F(B
@samp{File mode specification error}$B$K$b$H$N%(%i!<%a%C%;!<%8$rB3$1$F(B
$B%(%i!<$rJs9p$9$k!#(B
@end deffn

@defopt enable-local-variables
@c This variable controls processing of local variables lists in files
@c being visited.  A value of @code{t} means process the local variables
@c lists unconditionally; @code{nil} means ignore them; anything else means
@c ask the user what to do for each file.  The default value is @code{t}.
$B$3$NJQ?t$O!"K,Ld$7$?%U%!%$%kFb$N%m!<%+%kJQ?t%j%9%H$r=hM}$9$k$+$I$&$+$r(B
$B@)8f$9$k!#(B
$BCM(B@code{t}$B$O!"%m!<%+%kJQ?t%j%9%H$rL5>r7o$K=hM}$9$k$3$H$r0UL#$9$k!#(B
@code{nil}$B$O!"$=$l$i$rL5;k$9$k$3$H$r0UL#$9$k!#(B
$B$=$l0J30$NCM$G$"$k$H!"3F%U%!%$%k$4$H$K%f!<%6!<$KLd$$9g$o$;$k!#(B
$B%G%U%)%k%HCM$O(B@code{t}$B$G$"$k!#(B
@end defopt

@defvar ignored-local-variables
@c This variable holds a list of variables that should not be
@c set by a file's local variables list.  Any value specified
@c for one of these variables is ignored.
$B$3$NJQ?t$O!"%U%!%$%k$N%m!<%+%kJQ?t%j%9%H$G@_Dj$7$F$O$J$i$J$$(B
$BJQ?t$N%j%9%H$rJ];}$9$k!#(B
$B$=$l$i$NJQ?t$KBP$7$F;XDj$7$?CM$OL5;k$5$l$k!#(B
@end defvar

@c In addition to this list, any variable whose name has a non-@code{nil}
@c @code{risky-local-variable} property is also ignored.
$B$3$N%j%9%H$K2C$($F!"(B
$BB0@-(B@code{risky-local-variable}$B$,(B@code{nil}$B0J30$NCM$G$"$kJQ?t$bL5;k$5$l$^$9!#(B

@defopt enable-local-eval
@c This variable controls processing of @samp{Eval:} in local variables
@c lists in files being visited.  A value of @code{t} means process them
@c unconditionally; @code{nil} means ignore them; anything else means ask
@c the user what to do for each file.  The default value is @code{maybe}.
$B$3$NJQ?t$O!"K,Ld$7$?%U%!%$%kFb$N%m!<%+%kJQ?t%j%9%H$N(B@samp{Eval:}$B$r(B
$B=hM}$9$k$+$I$&$+$r@)8f$9$k!#(B
$BCM(B@code{t}$B$O!"$=$l$i$rL5>r7o$K=hM}$9$k$3$H$r0UL#$9$k!#(B
@code{nil}$B$O!"$=$l$i$rL5;k$9$k$3$H$r0UL#$9$k!#(B
$B$=$l0J30$NCM$G$"$k$H!"3F%U%!%$%k$4$H$K%f!<%6!<$KLd$$9g$o$;$k!#(B
$B%G%U%)%k%HCM$O(B@code{maybe}$B$G$"$k!#(B
@end defopt

@defun set-auto-mode
@c @cindex visited file mode
@cindex $BK,Ld$7$?%U%!%$%k$N%b!<%I(B
@cindex $B%b!<%I!"K,Ld$7$?%U%!%$%k(B
@c   This function selects the major mode that is appropriate for the
@c current buffer.  It may base its decision on the value of the @w{@samp{-*-}}
@c line, on the visited file name (using @code{auto-mode-alist}), on the
@c @w{@samp{#!}} line (using @code{interpreter-mode-alist}), or on the
@c file's local variables list.  However, this function does not look for
@c the @samp{mode:} local variable near the end of a file; the
@c @code{hack-local-variables} function does that.  @xref{Choosing Modes, ,
@c How Major Modes are Chosen, emacs, The GNU Emacs Manual}.
$B$3$N4X?t$O!"%+%l%s%H%P%C%U%!$KBP$7$FE,@Z$J%a%8%c!<%b!<%I$rA*Br$9$k!#(B
@w{@samp{-*-}}$B9T$NCM!"(B
$B!J(B@code{auto-mode-alist}$B$r;H$C$F!KK,Ld$7$?%U%!%$%k$NL>A0!"(B
$B!J(B@code{interpreter-mode-alist}$B$r;H$C$F!K(B@w{@samp{#!}}$B9T!"(B
$B%U%!%$%k$N%m!<%+%kJQ?t%j%9%H$r$b$H$K7hDj$9$k!#(B
$B$7$+$7!"$3$N4X?t$O%U%!%$%k$NKvHxIU6a$K$"$k(B
$B%m!<%+%kJQ?t(B@samp{mode:}$B$OD4$Y$J$$$,!"(B
$B4X?t(B@code{hack-local-variables}$B$OD4$Y$k!#(B
@xref{Choosing Modes,, $B%a%8%c!<%b!<%I$NA*BrJ}<0(B, emacs,
GNU Emacs $B%^%K%e%"%k(B}$B!#(B
@end defun

@defopt default-major-mode 
@c This variable holds the default major mode for new buffers.  The
@c standard value is @code{fundamental-mode}.
$B$3$NJQ?t$O!"?7$?$J%P%C%U%!$KBP$9$k%G%U%)%k%H$N%a%8%c!<%b!<%I$rJ];}$9$k!#(B
$BI8=`CM$O(B@code{fundamental-mode}$B$G$"$k!#(B

@c If the value of @code{default-major-mode} is @code{nil}, Emacs uses
@c the (previously) current buffer's major mode for the major mode of a new
@c buffer.  However, if that major mode symbol has a @code{mode-class}
@c property with value @code{special}, then it is not used for new buffers;
@c Fundamental mode is used instead.  The modes that have this property are
@c those such as Dired and Rmail that are useful only with text that has
@c been specially prepared.
@code{default-major-mode}$B$NCM$,(B@code{nil}$B$G$"$k$H!"(B
Emacs$B$O!J0JA0$N!K%+%l%s%H%P%C%U%!$N%a%8%c!<%b!<%I$r(B
$B?7$?$J%P%C%U%!$N%a%8%c!<%b!<%I$H$9$k!#(B
$B$7$+$7!"%a%8%c!<%b!<%I%3%^%s%I$N%7%s%\%k$NB0@-(B@code{mode-class}$B$N(B
$BCM$,(B@code{special}$B$G$"$k$H!"?7$?$J%P%C%U%!$N%a%8%c!<%b!<%I$K$O$;$:!"(B
$B$+$o$j$K4pK\!J(Bfundamental$B!K%b!<%I$r;H$&!#(B
$B$3$NB0@-$r;}$D%b!<%I$O!"(B
$BFCJL$K=`Hw$7$?%F%-%9%H$KBP$7$F$N$_M-MQ$G$"$k(Bdired$B$d(Brmail$B$J$I$G$"$k!#(B
@end defopt

@defun set-buffer-major-mode buffer
@c This function sets the major mode of @var{buffer} to the value of
@c @code{default-major-mode}.  If that variable is @code{nil}, it uses
@c the current buffer's major mode (if that is suitable).
$B$3$N4X?t$O%P%C%U%!(B@var{buffer}$B$N%a%8%c!<%b!<%I$r(B
@code{default-major-mode}$B$NCM$H$9$k!#(B
$B$3$NJQ?t$,(B@code{nil}$B$G$"$k$H!"(B
$B!JE,@Z$J$i$P!K%+%l%s%H%P%C%U%!$N%a%8%c!<%b!<%I$r;H$&!#(B

@c The low-level primitives for creating buffers do not use this function,
@c but medium-level commands such as @code{switch-to-buffer} and
@c @code{find-file-noselect} use it whenever they create buffers.
$B%P%C%U%!$r:n@.$9$kDc%l%Y%k$N4pK\4X?t$G$O$3$N4X?t$r;H$o$J$$$,!"(B
@code{switch-to-buffer}$B$d(B@code{find-file-noselect}$B$J$I$N(B
$BCf%l%Y%k$N%3%^%s%I$G$O%P%C%U%!$r:n@.$9$k$H$-$K$3$N%3%^%s%I$r;H$&!#(B
@end defun

@defvar initial-major-mode
@cindex @samp{*scratch*}
@c The value of this variable determines the major mode of the initial
@c @samp{*scratch*} buffer.  The value should be a symbol that is a major
@c mode command.  The default value is @code{lisp-interaction-mode}.
$B$3$NJQ?t$NCM$O!":G=i$N%P%C%U%!(B@samp{*scratch*}$B$N%a%8%c!<%b!<%I$r7hDj$9$k!#(B
$BCM$O!"%a%8%c!<%b!<%I%3%^%s%I$N%7%s%\%k$G$"$k$3$H!#(B
$B%G%U%)%k%HCM$O!"(B@code{lisp-interaction-mode}$B$G$"$k!#(B
@end defvar

@defvar auto-mode-alist
@c This variable contains an association list of file name patterns
@c (regular expressions; @pxref{Regular Expressions}) and corresponding
@c major mode commands.  Usually, the file name patterns test for suffixes,
@c such as @samp{.el} and @samp{.c}, but this need not be the case.  An
@c ordinary element of the alist looks like @code{(@var{regexp} .
@c @var{mode-function})}.
$B$3$NJQ?t$O!"%U%!%$%kL>$N%Q%?!<%s!J@55,I=8=!"(B@pxref{Regular Expressions}$B!K$H(B
$BBP1~$9$k%a%8%c!<%b!<%I$NO"A[%j%9%H$rJ];}$9$k!#(B
$BDL>o!"%U%!%$%kL>%Q%?!<%s$G$O(B@samp{.el}$B$d(B@samp{.c}$B$J$I$N@\Hx<-$rD4$Y$k$,!"(B
$B$=$&$G$J$/$F$b$h$$!#(B
$BO"A[%j%9%H$NDL>o$NMWAG$O(B
@code{(@var{regexp} . @var{mode-function})}$B$N7A$G$"$k!#(B

@c For example,
$B$?$H$($P$D$.$N$H$*$j!#(B

@smallexample
@group
(("\\`/tmp/fol/" . text-mode)
 ("\\.texinfo\\'" . texinfo-mode)
 ("\\.texi\\'" . texinfo-mode)
@end group
@group
 ("\\.el\\'" . emacs-lisp-mode)
 ("\\.c\\'" . c-mode) 
 ("\\.h\\'" . c-mode)
 @dots{})
@end group
@end smallexample

@c When you visit a file whose expanded file name (@pxref{File Name
@c Expansion}) matches a @var{regexp}, @code{set-auto-mode} calls the
@c corresponding @var{mode-function}.  This feature enables Emacs to select
@c the proper major mode for most files.
$BE83+$7$?%U%!%$%kL>!J(B@pxref{File Name Expansion}$B!K$,(B@var{regexp}$B$K0lCW$9$k(B
$B%U%!%$%k$rK,Ld$9$k$H!"(B
@code{set-auto-mode}$B$OBP1~$9$k(B@var{mode-function}$B$r8F$S=P$9!#(B
$B$3$N5!G=$K$h$j!"(BEmacs$B$O$[$H$s$I$N%U%!%$%k$KBP$7$F(B
$BE,@Z$J%a%8%c!<%b!<%I$rA*Br$9$k!#(B

@c If an element of @code{auto-mode-alist} has the form @code{(@var{regexp}
@c @var{function} t)}, then after calling @var{function}, Emacs searches
@c @code{auto-mode-alist} again for a match against the portion of the file
@c name that did not match before.  This feature is useful for
@c uncompression packages: an entry of the form @code{("\\.gz\\'"
@c @var{function} t)} can uncompress the file and then put the uncompressed
@c file in the proper mode according to the name sans @samp{.gz}.
@code{auto-mode-alist}$B$NMWAG$,(B@code{(@var{regexp} @var{function} t)}$B$N(B
$B7A$G$"$k$H!"(B@var{function}$B$r8F$S=P$7$?$"$H$G!"(B
Emacs$B$O%U%!%$%kL>$N$=$l$^$G0lCW$7$J$+$C$?ItJ,$K$D$$$F(B@code{auto-mode-alist}$B$r(B
$B:FEYC5:w$9$k!#(B
$B$3$N5!G=$O2rE`%Q%C%1!<%8$K$OM-MQ$G$"$k!#(B
@code{("\\.gz\\'" @var{function} t)}$B$N7A$NMWAG$G!"(B
$B%U%!%$%k$r2rE`$7!"(B@samp{.gz}$B$r=|$$$?%U%!%$%kL>$K=>$C$F(B
$B2rE`:Q$_%U%!%$%k$rE,@Z$J%b!<%I$K$G$-$k!#(B

@c Here is an example of how to prepend several pattern pairs to
@c @code{auto-mode-alist}.  (You might use this sort of expression in your
@c @file{.emacs} file.)
@code{auto-mode-alist}$B$K$$$/$D$+$N%Q%?!<%sBP$rDI2C$9$kJ}K!$r<($9!#(B
$B!J$3$N<o$N<0$rFI<T$N%U%!%$%k(B@file{.emacs}$B$K;H$($k!#!K(B

@smallexample
@group
(setq auto-mode-alist
  (append 
@c    ;; @r{File name (within directory) starts with a dot.}
   ;; @r{$B%I%C%H$G;O$^$k!J%G%#%l%/%H%jL>IU$-$N!K%U%!%$%kL>(B}
   '(("/\\.[^/]*\\'" . fundamental-mode)  
@c      ;; @r{File name has no dot.}
     ;; @r{$B%I%C%H$N$J$$%U%!%$%kL>(B}
     ("[^\\./]*\\'" . fundamental-mode)   
@c      ;; @r{File name ends in @samp{.C}.}
     ;; @r{@samp{.C}$B$G=*$k%U%!%$%kL>(B}
     ("\\.C\\'" . c++-mode))
   auto-mode-alist))
@end group
@end smallexample
@end defvar

@defvar interpreter-mode-alist
@c This variable specifies major modes to use for scripts that specify a
@c command interpreter in an @samp{#!} line.  Its value is a list of
@c elements of the form @code{(@var{interpreter} . @var{mode})}; for
@c example, @code{("perl" . perl-mode)} is one element present by default.
@c The element says to use mode @var{mode} if the file specifies
@c an interpreter which matches @var{interpreter}.  The value of
@c @var{interpreter} is actually a regular expression.
$B$3$NJQ?t$O!"(B@samp{#!}$B9T$G%3%^%s%I%$%s%?!<%W%j%?$r;XDj$7$F$$$k(B
$B%9%/%j%W%H$KBP$7$FMQ$$$k%a%8%c!<%b!<%I$r;XDj$9$k!#(B
$B$3$NCM$O!"(B@code{(@var{interpreter} . @var{mode})}$B$N7A$NMWAG$+$i@.$k(B
$B%j%9%H$G$"$k$3$H!#(B
$B$?$H$($P!"%G%U%)%k%H$K$O(B@code{("perl" . perl-mode)}$B$NMWAG$,$"$k!#(B
$B3FMWAG$O!"%U%!%$%k$,;XDj$9$k%$%s%?!<%W%j%?$,(B@var{interpreter}$B$K(B
$B0lCW$7$?$i%b!<%I(B@var{mode}$B$r;H$&$3$H$r0UL#$9$k!#(B
@var{interpreter}$B$NCM$O!"<B:]$K$O@55,I=8=$G$"$k!#(B

@c This variable is applicable only when the @code{auto-mode-alist} does
@c not indicate which major mode to use.
@code{auto-mode-alist}$B$,;HMQ$9$Y$-%a%8%c!<%b!<%I$,(B
$B;XDj$7$J$+$C$?>l9g$K$N$_$3$NJQ?t$r;H$&!#(B
@end defvar

@defun hack-local-variables &optional force
@c This function parses, and binds or evaluates as appropriate, any local
@c variables specified by the contents of the current buffer.
$B$3$N4X?t$O!"%+%l%s%H%P%C%U%!$NFbMF$K;XDj$5$l$?%m!<%+%kJQ?t$r(B
$BI,MW$K1~$8$F!"2r@O!"B+G{!"I>2A$9$k!#(B

@c The handling of @code{enable-local-variables} documented for
@c @code{normal-mode} actually takes place here.  The argument @var{force}
@c usually comes from the argument @var{find-file} given to
@c @code{normal-mode}.
@code{normal-mode}$B$G=R$Y$?(B@code{enable-local-variables}$B$N=hM}$O!"(B
$B<B:]$K$O$3$3$G9T$&!#(B
$B0z?t(B@var{force}$B$O!"DL>o!"(B
@code{normal-mode}$B$KM?$($i$l$?0z?t(B@var{find-file}$B$+$i$/$k!#(B
@end defun

@node Mode Help
@c @subsection Getting Help about a Major Mode
@subsection $B%a%8%c!<%b!<%I$K4X$9$k%X%k%W(B
@c @cindex mode help
@c @cindex help for major mode
@c @cindex documentation for major mode
@cindex $B%b!<%I%X%k%W(B
@cindex $B%a%8%c!<%b!<%I$K$D$$$F$N%X%k%W(B
@cindex $B%X%k%W!"%a%8%c!<%b!<%I(B
@cindex $B%a%8%c!<%b!<%I$N@bL@J8(B
@cindex $B@bL@J8!"%a%8%c!<%b!<%I(B

@c   The @code{describe-mode} function is used to provide information
@c about major modes.  It is normally called with @kbd{C-h m}.  The
@c @code{describe-mode} function uses the value of @code{major-mode},
@c which is why every major mode function needs to set the
@c @code{major-mode} variable.
$B4X?t(B@code{describe-mode}$B$O!"%a%8%c!<%b!<%I$K4X$9$k>pJs$r(B
$BF@$k$?$a$K;H$$$^$9!#(B
$BDL>o!"(B@kbd{C-h m}$B$G8F$S=P$5$l$^$9!#(B
$B4X?t(B@code{describe-mode}$B$O(B@code{major-mode}$B$NCM$r;H$$$^$9$,!"(B
$B$=$N$?$a$K3F%a%8%c!<%b!<%I4X?t$,(B
$BJQ?t(B@code{major-mode}$B$K@_Dj$9$kI,MW$,$"$k$N$G$9!#(B

@c @deffn Command describe-mode
@deffn $B%3%^%s%I(B describe-mode
@c This function displays the documentation of the current major mode.
$B$3$N4X?t$O!"8=:_$N%a%8%c!<%b!<%I$N@bL@J8$rI=<($9$k!#(B

@c The @code{describe-mode} function calls the @code{documentation}
@c function using the value of @code{major-mode} as an argument.  Thus, it
@c displays the documentation string of the major mode function.
@c (@xref{Accessing Documentation}.)
$B4X?t(B@code{describe-mode}$B$O!"(B@code{major-mode}$B$NCM$r0z?t$H$7$F(B
$B4X?t(B@code{documentation}$B$r8F$S=P$9!#(B
$B$=$&$7$F!"%a%8%c!<%b!<%I4X?t$N@bL@J8;zNs$rI=<($9$k!#(B
$B!J(B@pxref{Accessing Documentation}$B!#!K(B
@end deffn

@defvar major-mode
@c This variable holds the symbol for the current buffer's major mode.
@c This symbol should have a function definition that is the command to
@c switch to that major mode.  The @code{describe-mode} function uses the
@c documentation string of the function as the documentation of the major
@c mode.
$B$3$NJQ?t$O!"%+%l%s%H%P%C%U%!$N%a%8%c!<%b!<%I$KBP$9$k%7%s%\%k$rJ];}$9$k!#(B
$B$3$N%7%s%\%k$O!"Ev3:%a%8%c!<%b!<%I$K@Z$jBX$($k$?$a$N%3%^%s%I$r(B
$B4X?tDj5A$H$7$F;}$D$3$H!#(B
$B4X?t(B@code{describe-mode}$B$O!"(B
$B%a%8%c!<%b!<%I$N@bL@J8$H$7$FEv3:4X?t$N@bL@J8;zNs$r;H$&!#(B
@end defvar

@node Derived Modes
@c @subsection Defining Derived Modes
@subsection $BGI@8%b!<%I$NDj5A(B

@c   It's often useful to define a new major mode in terms of an existing
@c one.  An easy way to do this is to use @code{define-derived-mode}.
$B4{B8$N%a%8%c!<%b!<%I$rMQ$$$F?7$?$J%a%8%c!<%b!<%I$rDj5A$G$-$k$HJXMx$G$9!#(B
$B$3$l$r9T$&4JC1$JJ}K!$O(B@code{define-derived-mode}$B$r;H$&$3$H$G$9!#(B

@defmac define-derived-mode variant parent name docstring body@dots{}
@c This construct defines @var{variant} as a major mode command, using
@c @var{name} as the string form of the mode name.
$B$3$l$O!"(B@var{name}$B$r%b!<%IL>$rI=$9J8;zNs$H$7$F;H$C$F(B
@var{variant}$B$r%a%8%c!<%b!<%I%3%^%s%I$H$7$FDj5A$9$k!#(B

@c The new command @var{variant} is defined to call the function
@c @var{parent}, then override certain aspects of that parent mode:
$B?7$?$J%3%^%s%I(B@var{variant}$B$O!"4X?t(B@var{parent}$B$r8F$S=P$7$F$+$i(B
$B?F%b!<%I$NFCDj$N5!G=$rL58z$K$9$k$h$&$KDj5A$5$l$k!#(B

@itemize @bullet 
@item
@c The new mode has its own keymap, named @code{@var{variant}-map}.
@c @code{define-derived-mode} initializes this map to inherit from
@c @code{@var{parent}-map}, if it is not already set.
$B?7$?$J%b!<%I$O!"(B@code{@var{variant}-map}$B$H$$$&L>A0$N(B
$BFH<+$N%-!<%^%C%W$r;}$D!#(B
@code{define-derived-mode}$B$O!"(B
$B$3$N%-!<%^%C%W$,Dj5A:Q$_$G$J$1$l$P!"(B
@code{@var{parent}-map}$B$+$i7Q>5$9$k$h$&$K$3$N%-!<%^%C%W$r=i4|2=$9$k!#(B

@item
@c The new mode has its own syntax table, kept in the variable
@c @code{@var{variant}-syntax-table}.
@c @code{define-derived-mode} initializes this variable by copying 
@c @code{@var{parent}-syntax-table}, if it is not already set.
$B?7$?$J%b!<%I$G$O!"JQ?t$K(B@code{@var{variant}-syntax-table}$B$K(B
$BFH<+$N9=J8%F!<%V%k$rJ];}$9$k!#(B
$B$3$NJQ?t$,Dj5A:Q$_$G$J$1$l$P!"(B
@code{@var{parent}-syntax-table}$B$r%3%T!<$7$F$3$NJQ?t$r=i4|2=$9$k!#(B

@item
@c The new mode has its own abbrev table, kept in the variable
@c @code{@var{variant}-abbrev-table}.
@c @code{define-derived-mode} initializes this variable by copying 
@c @code{@var{parent}-abbrev-table}, if it is not already set.
$B?7$?$J%b!<%I$G$O!"JQ?t$K(B@code{@var{variant}-abbrev-table}$B$K(B
$BFH<+$NN,8lI=$rJ];}$9$k!#(B
$B$3$NJQ?t$,Dj5A:Q$_$G$J$1$l$P!"(B
@code{@var{parent}-abbrev-table}$B$r%3%T!<$7$F$3$NJQ?t$r=i4|2=$9$k!#(B

@item
@c The new mode has its own mode hook, @code{@var{variant}-hook},
@c which it runs in standard fashion as the very last thing that it does.
@c (The new mode also runs the mode hook of @var{parent} as part 
@c of calling @var{parent}.)
$B?7$?$J%b!<%I$K$OFH<+$N%b!<%I%U%C%/(B@code{@var{variant}-hook}$B$,$"$j!"(B
$BDL>o$I$*$j:G8e$K$3$l$r<B9T$9$k!#(B
$B!J?7$?$J%b!<%I$G$O!"(B@var{parent}$B$r8F$S=P$9$3$H$N0lIt$H$7$F(B
@var{parent}$B$N%b!<%I%U%C%/$b<B9T$9$k!#!K(B
@end itemize

@c In addition, you can specify how to override other aspects of
@c @var{parent} with @var{body}.  The command @var{variant}
@c evaluates the forms in @var{body} after setting up all its usual 
@c overrides, just before running @code{@var{variant}-hook}.
$B$5$i$K!"(B@var{body}$B$G(B@var{parent}$B$NB>$NItJ,$rL58z$K$9$kJ}K!$r;XDj$G$-$k!#(B
$B%3%^%s%I(B@var{variant}$B$O!"(B@code{@var{variant}-hook}$B$r8F$S=P$9D>A0!"(B
$BDL>o$NL58z2==hM}$r=*$($F$+$i(B@var{body}$B$N%U%)!<%`$rI>2A$9$k!#(B

@c The argument @var{docstring} specifies the documentation string for the
@c new mode.  If you omit @var{docstring}, @code{define-derived-mode}
@c generates a documentation string.
$B0z?t(B@var{docstring}$B$O!"?7$?$J%b!<%I$KBP$9$k@bL@J8;zNs$r;XDj$9$k!#(B
@var{docstring}$B$r>JN,$9$k$H!"(B
@code{define-derived-mode}$B$O@bL@J8;zNs$r@8@.$9$k!#(B

@c Here is a hypothetical example:
$B2>A[E*$JNc$r<($9!#(B

@example
(define-derived-mode hypertext-mode
  text-mode "Hypertext"
  "Major mode for hypertext.
\\@{hypertext-mode-map@}"
  (setq case-fold-search nil))

(define-key hypertext-mode-map
  [down-mouse-3] 'do-hyper-link)
@end example
@end defmac

@node Minor Modes
@c @section Minor Modes
@section $B%^%$%J%b!<%I(B
@c @cindex minor mode
@cindex $B%^%$%J%b!<%I(B

@c   A @dfn{minor mode} provides features that users may enable or disable
@c independently of the choice of major mode.  Minor modes can be enabled
@c individually or in combination.  Minor modes would be better named
@c ``generally available, optional feature modes,'' except that such a name
@c would be unwieldy.
@dfn{$B%^%$%J%b!<%I(B}$B!J(Bminor mode$B!K$O!"%a%8%c!<%b!<%I$NA*Br$H$OFHN)$K(B
$B%f!<%6!<$,%*%s!?%*%U$G$-$k5!G=$rDs6!$7$^$9!#(B
$B%^%$%J%b!<%I$O!"8DJL$K$bAH$_9g$o$;$F$b%*%s$K$G$-$^$9!#(B
$B%^%$%J%b!<%I$O!"D9$9$.$^$9$,!XHFMQE*$K;H$($k%*%W%7%g%s5!G=$N%b!<%I!Y$H(B
$BL?L>$7$?$h$&$,$h$$$+$b$7$l$^$;$s!#(B

@c   A minor mode is not usually a modification of single major mode.  For
@c example, Auto Fill mode works with any major mode that permits text
@c insertion.  To be general, a minor mode must be effectively independent
@c of the things major modes do.
$B%^%$%J%b!<%I$O!"IaDL!"(B1$B$D$N%a%8%c!<%b!<%I$rJQ99$9$k$@$1$G$O$"$j$^$;$s!#(B
$B$?$H$($P!"<+F05M$a9~$_%b!<%I!J(Bauto-fill$B%b!<%I!K$O!"(B
$B%F%-%9%HA^F~$r5v$9G$0U$N%a%8%c!<%b!<%I$G;H$($^$9!#(B
$BHFMQE*$G$"$k$?$a$K$O!"%^%$%J%b!<%I$O(B
$B%a%8%c!<%b!<%I$,9T$&$3$H$H$O<B<AE*$KFHN)$G$"$kI,MW$,$"$j$^$9!#(B

@c   A minor mode is often much more difficult to implement than a major
@c mode.  One reason is that you should be able to activate and deactivate
@c minor modes in any order.  A minor mode should be able to have its
@c desired effect regardless of the major mode and regardless of the other
@c minor modes in effect.
$B%^%$%J%b!<%I$O!"%a%8%c!<%b!<%I$KHf$Y$F!"<BAu$9$k$N$,$7$P$7$P:$Fq$G$9!#(B
1$B$D$NM}M3$O!"G$0U$N=g$G%^%$%J%b!<%I$r%*%s!?%*%U$G$-$k$h$&$K$9$k(B
$BI,MW$,$"$k$+$i$G$9!#(B
$B%^%$%J%b!<%I$O!"%a%8%c!<%b!<%I$dB>$N%*%s$K$J$C$F$$$k%^%$%J%b!<%I$H$O(B
$BL54X78$K$=$NK>$_$N8z2L$rH/4x$G$-$kI,MW$,$"$j$^$9!#(B

@c   Often the biggest problem in implementing a minor mode is finding a
@c way to insert the necessary hook into the rest of Emacs.  Minor mode
@c keymaps make this easier than it used to be.
$B$7$P$7$P!"%^%$%J%b!<%I$r<BAu$9$k$&$($G$b$C$H$bBg$-$JLdBj$O!"(B
Emacs$B$N;D$j$NItJ,$KBP$7$FI,MW$J%U%C%/$rC5$9$3$H$G$9!#(B
$B%^%$%J%b!<%I%-!<%^%C%W$K$h$j!"=>Mh$KHf$Y$F4JC1$K$J$j$^$9!#(B

@menu
* Minor Mode Conventions::      Tips for writing a minor mode.
* Keymaps and Minor Modes::     How a minor mode can have its own keymap.
* Easy-Mmode::                  A convenient facility for defining minor modes.
@end menu

@node Minor Mode Conventions
@c @subsection Conventions for Writing Minor Modes
@subsection $B%^%$%J%b!<%I$r=q$/$?$a$N47=,(B
@c @cindex minor mode conventions
@c @cindex conventions for writing minor modes
@cindex $B%^%$%J%b!<%I$N47=,(B
@cindex $B%^%$%J%b!<%I$r=q$/$?$a$N47=,(B

@c   There are conventions for writing minor modes just as there are for
@c major modes.  Several of the major mode conventions apply to minor
@c modes as well: those regarding the name of the mode initialization
@c function, the names of global symbols, and the use of keymaps and
@c other tables.
$B%a%8%c!<%b!<%I$KBP$9$k$N$HF1$8$h$&$K!"(B
$B%^%$%J%b!<%I$r=q$/$&$($G$N47=,$,$"$j$^$9!#(B
$B%a%8%c!<%b!<%I$N47=,$K$O!"%^%$%J%b!<%I$K$bE,MQ$5$l$k$b$N$,$"$j$^$9!#(B
$B$D$^$j!"%b!<%I$r=i4|2=$9$k4X?t$NL>A0!"(B
$B%0%m!<%P%k%7%s%\%k$NL>A0!"%-!<%^%C%W$d$=$NB>$N%F!<%V%k$dI=$N;H$$J}$G$9!#(B

@c   In addition, there are several conventions that are specific to
@c minor modes.
$B$=$l$i$K2C$($F!"%^%$%J%b!<%I$K8GM-$J47=,$b$"$j$^$9!#(B

@itemize @bullet
@item
@c @cindex mode variable
@cindex $B%b!<%IJQ?t(B
@c Make a variable whose name ends in @samp{-mode} to control the minor
@c mode.  We call this the @dfn{mode variable}.  The minor mode command
@c should set this variable (@code{nil} to disable; anything else to
@c enable).
$B%^%$%J%b!<%I$r@)8f$9$kJQ?t$NL>A0$O(B@samp{-mode}$B$G=*$k$3$H!#(B
$B$3$l$r(B@dfn{$B%b!<%IJQ?t(B}$B!J(Bmode variable$B!K$H8F$V!#(B
$B%^%$%J%b!<%I%3%^%s%I$O!"$3$NJQ?t$r(B
$B!J%*%U$K$9$k$K$O(B@code{nil}$B!"%*%s$K$9$k$K$O$=$l0J30$K!K@_Dj(B
$B$9$k$3$H!#(B

@c If it is possible, implement the mode so that setting the variable
@c automatically enables or disables the mode.  Then the minor mode command
@c does not need to do anything except set the variable.
$B2DG=$J$i$P!"JQ?t$K@_Dj$9$k$H(B
$B<+F0E*$K%b!<%I$,%*%s!?%*%U$5$l$k$h$&$K%b!<%I$r<BAu$9$k!#(B
$B$=$&$9$k$H!"%^%$%J%b!<%I%3%^%s%I$O!"(B
$BJQ?t$K@_Dj$9$k0J30$K$O$J$K$b$7$J$$$G$h$/$J$k!#(B

@c This variable is used in conjunction with the @code{minor-mode-alist} to
@c display the minor mode name in the mode line.  It can also enable
@c or disable a minor mode keymap.  Individual commands or hooks can also
@c check the variable's value.
$B$3$NJQ?t$O!"%b!<%I9T$K%^%$%J%b!<%IL>$rI=<($9$k$?$a$K(B
@code{minor-mode-alist}$B$G$b;H$o$l$k!#(B
$B%^%$%J%b!<%I%-!<%^%C%W$r3h@-$K$7$?$jHs3h@-$K$7$?$j$b$9$k!#(B
$B3F%3%^%s%I$d%U%C%/$b$3$NJQ?t$NCM$r8!::$9$k!#(B

@c If you want the minor mode to be enabled separately in each buffer,
@c make the variable buffer-local.
$B3F%P%C%U%!$4$H$KJL!9$K%^%$%J%b!<%I$r%*%s$K$7$?$$>l9g$K$O!"(B
$B$3$NJQ?t$r%P%C%U%!%m!<%+%k$K$9$k!#(B

@item
@c Define a command whose name is the same as the mode variable.
@c Its job is to enable and disable the mode by setting the variable.
$B%b!<%IJQ?t$HF1$8L>A0$N%3%^%s%I$rDj5A$9$k!#(B
$B$=$N;E;v$O!"Ev3:JQ?t$K@_Dj$9$k$3$H$G%b!<%I$r%*%s!?%*%U$9$k$3$H$G$"$k!#(B

@c The command should accept one optional argument.  If the argument is
@c @code{nil}, it should toggle the mode (turn it on if it is off, and off
@c if it is on).  Otherwise, it should turn the mode on if the argument is
@c a positive integer, a symbol other than @code{nil} or @code{-}, or a
@c list whose @sc{car} is such an integer or symbol; it should turn the
@c mode off otherwise.
$BEv3:%3%^%s%I$O!">JN,2DG=$J0z?t$r(B1$B$D<u$1<h$k$3$H!#(B
$B0z?t$,(B@code{nil}$B$G$"$l$P%b!<%I$r%H%0%k(B
$B!J%*%s$G$"$l$P%*%U$K!"%*%U$G$"$l$P%*%s$K!K$9$k!#(B
$B$5$b$J$1$l$P!"0z?t$,!"@5@0?t!"(B@code{nil}$B0J30$N%7%s%\%k!"(B
@code{-}$B!"$"$k$$$O!"(B@sc{car}$B$,$=$N$h$&$J@0?t$d%7%s%\%k$G$"$k$h$&$J%j%9%H$N(B
$B>l9g$K$O%b!<%I$r%*%s$K$9$k!#(B
$B$=$l0J30$G$O%b!<%I$r%*%U$K$9$k!#(B

@c Here is an example taken from the definition of @code{transient-mark-mode}.
@c It shows the use of @code{transient-mark-mode} as a variable that enables or
@c disables the mode's behavior, and also shows the proper way to toggle,
@c enable or disable the minor mode based on the raw prefix argument value.
@code{transient-mark-mode}$B$NDj5A$+$i0zMQ$7$?Nc$r<($9!#(B
$B%b!<%I$N$U$k$^$$$r%*%s!?%*%U$9$kJQ?t$H$7$F$N(B
@code{transient-mark-mode}$B$N;H$$J}!"(B
$B$*$h$S!"@8$NA0CV0z?t$K4p$E$$$?%^%$%J%b!<%I$N(B
$B%*%s!?%*%U!?%H%0%k$N;EJ}$r<($9!#(B

@smallexample
@group
(setq transient-mark-mode
      (if (null arg) (not transient-mark-mode)
        (> (prefix-numeric-value arg) 0)))
@end group
@end smallexample

@item
@c Add an element to @code{minor-mode-alist} for each minor mode
@c (@pxref{Mode Line Variables}), if you want to indicate the minor mode in
@c the mode line.  This element should be a list of the following form:
$B%b!<%I9T$K%^%$%J%b!<%I$rI=<($7$?$$>l9g$K$O!"(B
$B3F%^%$%J%b!<%I$K$D$$$FMWAG$r(B@code{minor-mode-alist}$B$KDI2C$9$k(B
$B!J(B@pxref{Mode Line Variables}$B!K!#(B
$B$3$NMWAG$O$D$.$N7A$N%j%9%H$G$"$k$3$H!#(B

@smallexample
(@var{mode-variable} @var{string})
@end smallexample

@c Here @var{mode-variable} is the variable that controls enabling of the
@c minor mode, and @var{string} is a short string, starting with a space,
@c to represent the mode in the mode line.  These strings must be short so
@c that there is room for several of them at once.
$B$3$3$G!"(B@var{mode-variable}$B$O%^%$%J%b!<%I$N%*%s!?%*%U$r@)8f$9$kJQ?t$G$"$j!"(B
@var{string}$B$O%b!<%I9T$G%b!<%I$rI=$9C;$$6uGr$G;O$^$kJ8;zNs$G$"$k!#(B
$BF1;~$KJ#?t$N%b!<%I$rI=<($G$-$k$h$&$K!"$3$l$i$NJ8;zNs$OC;$$$3$H!#(B

@c When you add an element to @code{minor-mode-alist}, use @code{assq} to
@c check for an existing element, to avoid duplication.  For example:
@code{minor-mode-alist}$B$KMWAG$rDI2C$9$k$H$-$K$O!"(B
$B=EJ#$rKI$0$?$a$K4{B8$NMWAG$r8!::$9$k(B@code{assq}$B$r;H$&$3$H!#(B
$B$?$H$($P$D$.$N$H$*$j!#(B

@smallexample
@group
(or (assq 'leif-mode minor-mode-alist)
    (setq minor-mode-alist
          (cons '(leif-mode " Leif") minor-mode-alist)))
@end group
@end smallexample
@end itemize

@c   You can also use @code{add-to-list} to add an element to this list
@c just once (@pxref{Setting Variables}).
$B$3$N%j%9%H$KMWAG$r(B1$B2s$@$1DI2C$9$k$J$i$P(B@code{add-to-list}$B$b;H$($^$9(B
$B!J(B@pxref{Setting Variables}$B!K!#(B

@node Keymaps and Minor Modes
@c @subsection Keymaps and Minor Modes
@subsection $B%-!<%^%C%W$H%^%$%J%b!<%I(B

@c   Each minor mode can have its own keymap, which is active when the mode
@c is enabled.  To set up a keymap for a minor mode, add an element to the
@c alist @code{minor-mode-map-alist}.  @xref{Active Keymaps}.
$B3F%^%$%J%b!<%I$O!"%b!<%I$,%*%s$N$H$-$K3h@-$K$J$kFH<+$N%-!<%^%C%W$r;}$F$^$9!#(B
$B%^%$%J%b!<%I8~$1$N%-!<%^%C%W$r@_Dj$9$k$K$O!"(B
@code{minor-mode-map-alist}$B$KMWAG$rDI2C$7$^$9!#(B
@xref{Active Keymaps}$B!#(B

@c @cindex @code{self-insert-command}, minor modes
@cindex @code{self-insert-command}$B!"%^%$%J%b!<%I(B
@c   One use of minor mode keymaps is to modify the behavior of certain
@c self-inserting characters so that they do something else as well as
@c self-insert.  In general, this is the only way to do that, since the
@c facilities for customizing @code{self-insert-command} are limited to
@c special cases (designed for abbrevs and Auto Fill mode).  (Do not try
@c substituting your own definition of @code{self-insert-command} for the
@c standard one.  The editor command loop handles this function specially.)
$B%^%$%J%b!<%I%-!<%^%C%W$N(B1$B$D$NMQES$O!"(B
$B$"$k<o$N<+8JA^F~J8;z$N$U$k$^$$$rJQ99$7$F!"(B
$B<+8JA^F~$K2C$($F$J$K$+$r9T$o$;$k$h$&$K$9$k$3$H$G$9!#(B
$B0lHL$K!"(B@code{self-insert-command}$B$r%+%9%?%^%$%:$9$k5!9=$O(B
$B!JN,8l%b!<%I$d<+F05M$a9~$_%b!<%I8~$1$K@_7W$5$l$?!KFCJL$J>l9g$K8B$i$l$k$N$G!"(B
$B$3$N$h$&$J$3$H$r9T$&M#0l$NJ}K!$G$9!#(B
$B!JI8=`$N(B@code{self-insert-command}$B$NDj5A$rFI<TFH<+$NDj5A$GCV$-49$($J$$$3$H!#(B
$B%(%G%#%?%3%^%s%I%k!<%W$O$3$N4X?t$rFCJL07$$$7$F$$$k!#!K(B

@c The key sequences bound in a minor mode should consist of @kbd{C-c}
@c followed by a punctuation character @emph{other than} @kbd{@{},
@c @kbd{@}}, @kbd{<}, @kbd{>}, @kbd{:} or @kbd{;}.  (Those few punctuation
@c characters are reserved for major modes.)
$B%^%$%J%b!<%I$G%P%$%s%I$7$F$$$k%-!<Ns$O!"(B@kbd{C-c}$B$G;O$^$j!"(B
@kbd{@{}$B!"(B@kbd{@}}$B!"(B@kbd{<}$B!"(B@kbd{>}$B!"(B@kbd{:}$B!"(B@kbd{;}@emph{$B0J30(B}$B$N(B
$B6gFIE@J8;z$N(B1$B$D$,B3$/$h$&$K$7$^$9!#(B
$B!J=|30$7$?6gFIE@J8;z$O%a%8%c!<%b!<%I8~$1$KM=Ls$5$l$F$$$k!#!K(B

@node Easy-Mmode
@subsection Easy-Mmode

@c   The easy-mmode package provides a convenient way of implementing a
@c minor mode; with it, you can specify all about a simple minor mode in
@c one self-contained definition.
$B%Q%C%1!<%8(Beasy-mmode$B$O!"%^%$%J%b!<%I$r<BAu$9$kJXMx$JJ}K!$rDs6!$7$^$9!#(B
$B$3$l$r;H$&$H!"C1=c$J%^%$%J%b!<%I$r(B1$B$D$N<+8J407k$7$?Dj5A$K;XDj$G$-$^$9!#(B

@defmac easy-mmode-define-minor-mode mode doc &optional init-value mode-indicator keymap
@tindex easy-mmode-define-minor-mode
@c This macro defines a new minor mode whose name is @var{mode} (a symbol).
$B$3$N%^%/%m$O!"(B@var{mode}$B!J%7%s%\%k!K$H$$$&L>A0$N?7$7$$%^%$%J%b!<%I$rDj5A$9$k!#(B

@c This macro defines a command named @var{mode} which toggles the minor
@c mode, and has @var{doc} as its documentation string.
$B$3$N%^%/%m$O!"%^%$%J%b!<%I$r%H%0%k$9$k(B
@var{mode}$B$H$$$&L>A0$N%3%^%s%I$rDj5A$7!"(B
$B$=$N@bL@J8;zNs$r(B@var{doc}$B$H$9$k!#(B

@c It also defines a variable named @var{mode}, which is set to @code{t} or
@c @code{nil} by enabling or disabling the mode.  The variable is
@c initialized to @var{init-value}.
$B$^$?!"(B@var{mode}$B$H$$$&L>A0$NJQ?t$bDj5A$9$k!#(B
$B$3$NJQ?t$O%b!<%I$N%*%s!?%*%U$K$7$?$,$C$F(B@code{t}/@code{nil}$B$K@_Dj$5$l$k!#(B
$B$3$NJQ?t$O(B@var{init-value}$B$K=i4|2=$5$l$k!#(B

@c The string @var{mode-indicator} says what to display in the mode line
@c when the mode is enabled; if it is @code{nil}, the mode is not displayed
@c in the mode line.
$BJ8;zNs(B@var{mode-indicator}$B$O!"%b!<%I$,%*%s$N$H$-$K%b!<%I9T$K(B
$BI=<($5$l$kJ8;zNs$G$"$k!#(B
$B$=$l$,(B@code{nil}$B$G$"$k$H%b!<%I9T$K$O%b!<%I$rI=<($7$J$$!#(B

@c The optional argument @var{keymap} specifies the keymap for the minor mode.
@c It can be a variable name, whose value is the keymap, or it can be an alist
@c specifying bindings in this form:
$B>JN,2DG=$J0z?t(B@var{keymap}$B$O!"%^%$%J%b!<%I$N%-!<%^%C%W$r;XDj$9$k!#(B
$B$3$l$O!"CM$,%-!<%^%C%W$G$"$k$h$&$JJQ?t$NL>A0$+!"(B
$B$D$.$N7A$N%P%$%s%G%#%s%0$r;XDj$7$?O"A[%j%9%H$G$"$k$3$H!#(B

@example
(@var{key-sequence} . @var{definition})
@end example
@end defmac

@c   Here is an example of using @code{easy-mmode-define-minor-mode}:
@code{easy-mmode-define-minor-mode}$B$r;H$C$?Nc$r<($7$^$9!#(B

@smallexample
(easy-mmode-define-minor-mode hungry-mode
  "Toggle Hungry mode.
With no argument, this command toggles the mode. 
Non-null prefix argument turns on the mode.
Null prefix argument turns off the mode.

When Hungry mode is enabled, the control delete key
gobbles all preceding whitespace except the last.
See the command \\[hungry-electric-delete]."
@c  ;; The initial value.
 ;; $B=i4|CM(B
 nil
@c  ;; The indicator for the mode line.
 ;; $B%b!<%I9T$X$NI=<((B
 " Hungry"
@c  ;; The minor mode bindings.
 ;; $B%^%$%J%b!<%I$N%P%$%s%G%#%s%0(B
 '(("\C-\^?" . hungry-electric-delete)
   ("\C-\M-\^?"
    . (lambda () 
        (interactive)
        (hungry-electric-delete t)))))
@end smallexample

@noindent
@c This defines a minor mode named ``Hungry mode'', a command named
@c @code{hungry-mode} to toggle it, a variable named @code{hungry-mode}
@c which indicates whether the mode is enabled, and a variable named
@c @code{hungry-mode-map} which holds the keymap that is active when the
@c mode is enabled.  It initializes the keymap with key bindings for
@c @kbd{C-@key{DEL}} and @kbd{C-M-@key{DEL}}.
$B$3$l$O!"!X(Bhungry$B%b!<%I!Y$H$$$&L>A0$N%^%$%J%b!<%I$rDj5A$7$^$9!#(B
$B%b!<%I$r%H%0%k$9$k%3%^%s%I$NL>A0$O(B@code{hungry-mode}$B!"(B
$B%b!<%I$N%*%s!?%*%U$rI=$9JQ?t$NL>A0$O(B@code{hungry-mode}$B!"(B
$B%b!<%I$,%*%s$N$H$-$K3h@-$J%-!<%^%C%W$rJ];}$9$k(B
$BJQ?t$NL>A0$O(B@code{hungry-mode-map}$B$G$9!#(B
@kbd{C-@key{DEL}}$B$H(B@kbd{C-M-@key{DEL}}$B$KBP$9$k%-!<%P%$%s%G%#%s%0$G(B
$B%-!<%^%C%W$r=i4|2=$7$^$9!#(B

@node Mode Line Format
@c @section Mode Line Format
@section $B%b!<%I9T$N=q<0(B
@c @cindex mode line
@cindex $B%b!<%I9T$N=q<0(B

@c   Each Emacs window (aside from minibuffer windows) includes a mode line,
@c which displays status information about the buffer displayed in the
@c window.  The mode line contains information about the buffer, such as its
@c name, associated file, depth of recursive editing, and the major and
@c minor modes.
Emacs$B$N!J%_%K%P%C%U%!@lMQ%&%#%s%I%&$r=|$/!K3F%&%#%s%I%&$K$O%b!<%I9T$,$"$C$F!"(B
$B%&%#%s%I%&$KI=<($7$F$$$k%P%C%U%!$K4X$9$k>uBV>pJs$rI=<($7$F$$$^$9!#(B
$B%b!<%I9T$K$O!"%P%C%U%!L>!"BP1~$9$k%U%!%$%k!":F5"JT=8$N?<$5!"(B
$B%a%8%c!<%b!<%I$H%^%$%J%b!<%I$J$I$N%P%C%U%!$K4X$9$k>pJs$,4^$^$l$^$9!#(B

@c   This section describes how the contents of the mode line are
@c controlled.  We include it in this chapter because much of the
@c information displayed in the mode line relates to the enabled major and
@c minor modes.
$BK\@a$G$O!"%b!<%I9T$NFbMF$N@)8fJ}K!$K$D$$$F=R$Y$^$9!#(B
$B%b!<%I9T$KI=<($5$l$k>pJs$N$[$H$s$I$O(B
$B%*%s$K$J$C$F$$$k%a%8%c!<%b!<%I$H%^%$%J%b!<%I$K4X78$9$k$N$G!"(B
$BK\>O$K4^$a$^$9!#(B

@c   @code{mode-line-format} is a buffer-local variable that holds a
@c template used to display the mode line of the current buffer.  All
@c windows for the same buffer use the same @code{mode-line-format} and
@c their mode lines appear the same (except for scrolling percentages, and
@c line and column numbers).
@code{mode-line-format}$B$O!"%+%l%s%H%P%C%U%!$N%b!<%I9T$KI=<($9$k(B
$B?w7?$rJ];}$7$F$$$k%P%C%U%!%m!<%+%k$JJQ?t$G$9!#(B
$BF10l%P%C%U%!$KBP$9$k$9$Y$F$N%&%#%s%I%&$OF1$8(B@code{mode-line-format}$B$r;H$$!"(B
$B$=$l$i$N%b!<%I9T$O!J%9%/%m!<%k$N3d9g$d9T$d%3%i%`0LCV$r=|$$$F!K(B
$BF1$8$h$&$KI=<($5$l$^$9!#(B

@c   The mode line of a window is normally updated whenever a different
@c buffer is shown in the window, or when the buffer's modified-status
@c changes from @code{nil} to @code{t} or vice-versa.  If you modify any of
@c the variables referenced by @code{mode-line-format} (@pxref{Mode Line
@c Variables}), or any other variables and data structures that affect how
@c text is displayed (@pxref{Display}), you may want to force an update of
@c the mode line so as to display the new information or display it in
@c the new way.
$B%&%#%s%I%&$N%b!<%I9T$O!"DL>o!"%&%#%s%I%&$KJL$N%P%C%U%!$rI=<($7$?$H$-$d!"(B
$B%P%C%U%!$NJQ99>uBV$,(B@code{nil}$B$+$i(B@code{t}$B$X$"$k$$$O$=$N5U$NJQ2=$r$7$?$H$-$K(B
$B99?7$5$l$^$9!#(B
@code{mode-line-format}$B!J(B@pxref{Mode Line Variables}$B!K$,;2>H$9$k(B
$BJQ?t$r=$@5$7$?$j!"%F%-%9%H$NI=<(J}K!$K1F6A$9$k$=$NB>$NJQ?t$d%G!<%?9=B$(B
$B!J(B@pxref{Display}$B!K$rJQ99$7$?$H$-$K$O!"?7$7$$>pJs$rI=<($7$?$j(B
$B?7$?$JJ}K!$GI=<($9$k$?$a$K%b!<%I9T$N99?7$r6/@)$G$-$^$9!#(B

@c Emacs 19 feature
@defun force-mode-line-update
@c Force redisplay of the current buffer's mode line.
$B%+%l%s%H%P%C%U%!$N%b!<%I9T$N99?7$r6/@)$9$k!#(B
@end defun

@c   The mode line is usually displayed in inverse video; see
@c @code{mode-line-inverse-video} in @ref{Inverse Video}.
$B%b!<%I9T$O!"DL>o!"H?E>I=<($5$l$^$9!#(B
@ref{Inverse Video}$B$N(B@code{mode-line-inverse-video}$B$r;2>H$7$F$/$@$5$$!#(B

@menu
* Mode Line Data::        The data structure that controls the mode line.
* Mode Line Variables::   Variables used in that data structure.
* %-Constructs::          Putting information into a mode line.
@end menu

@node Mode Line Data
@c @subsection The Data Structure of the Mode Line
@subsection $B%b!<%I9T$N%G!<%?9=B$(B
@c @cindex mode line construct
@cindex $B%b!<%I9T9=@.(B

@c   The mode line contents are controlled by a data structure of lists,
@c strings, symbols, and numbers kept in the buffer-local variable
@c @code{mode-line-format}.  The data structure is called a @dfn{mode line
@c construct}, and it is built in recursive fashion out of simpler mode line
@c constructs.  The same data structure is used for constructing
@c frame titles (@pxref{Frame Titles}).
$B%b!<%I9T$NFbMF$O!"%P%C%U%!%m!<%+%k$JJQ?t(B@code{mode-line-format}$B$K(B
$BJ];}$5$l$?%j%9%H!"J8;zNs!"%7%s%\%k!"?t$+$i@.$k%G!<%?9=B$$G@)8f$5$l$^$9!#(B
$B$3$N%G!<%?9=B$$r(B@dfn{$B%b!<%I9T9=@.(B}$B!J(Bmode line construct$B!K$H8F$S$^$9!#(B
$B$3$l$OC1=c$J%b!<%I9T9=@.$+$i:F5"E*$K9=C[$7$^$9!#(B
$BF1$8%G!<%?9=B$$O%U%l!<%`%?%$%H%k!J(B@pxref{Frame Titles}$B!K$r(B
$B9=C[$9$k$?$a$K$b;H$o$l$^$9!#(B

@defvar mode-line-format
@c The value of this variable is a mode line construct with overall
@c responsibility for the mode line format.  The value of this variable
@c controls which other variables are used to form the mode line text, and
@c where they appear.
$B$3$NJQ?t$NCM$O!"%b!<%I9TA4BN$N=q<0$K@UG$$r;}$D%b!<%I9T9=@.$G$"$k!#(B
$B$3$NJQ?t$NCM$O!"%b!<%I9T$N%F%-%9%H$r:n$k$?$a$K$I$NJQ?t$r;H$&$+!"(B
$B$=$l$i$O%b!<%I9T$N$I$3$K8=$l$k$+$r@)8f$9$k!#(B
@end defvar

@c   A mode line construct may be as simple as a fixed string of text, but
@c it usually specifies how to use other variables to construct the text.
@c Many of these variables are themselves defined to have mode line
@c constructs as their values.
$B%b!<%I9T9=@.$O!"Dj$^$C$?%F%-%9%H$NJ8;zNs$N$h$&$KC1=c$G$b$+$^$$$^$;$s$,!"(B
$BIaDL$O!"%F%-%9%H$r:n$k$?$a$NJL$NJQ?t$N;H$$J}$r;XDj$7$^$9!#(B
$B$=$l$i$NJQ?t$NB?$/$O$=$l<+?H!"$=$l$i$NCM$H$7$F(B
$B%b!<%I9T9=@.$r;}$D$h$&$KDj5A$5$l$F$$$^$9!#(B

@c   The default value of @code{mode-line-format} incorporates the values
@c of variables such as @code{mode-name} and @code{minor-mode-alist}.
@c Because of this, very few modes need to alter @code{mode-line-format}
@c itself.  For most purposes, it is sufficient to alter some of the
@c variables that @code{mode-line-format} refers to.
@code{mode-line-format}$B$N%G%U%)%k%HCM$O!"(B
@code{mode-name}$B$d(B@code{minor-mode-alist}$B$J$I$NJQ?t$NCM$r;H$$$^$9!#(B
$BB?$/$NL\E*$K$O!"(B@code{mode-line-format}$B$,;2>H$9$k$$$/$D$+$NJQ?t$r(B
$BJQ$($k$@$1$G==J,$G$9!#(B

@c   A mode line construct may be a list, a symbol, or a string.  If the
@c value is a list, each element may be a list, a symbol, or a string.
$B%b!<%I9T9=@.$O!"%j%9%H!"%7%s%\%k!"J8;zNs$N$$$:$l$+$G$9!#(B
$B$=$NCM$,%j%9%H$G$"$l$P!"$=$N3FMWAG$O%j%9%H!"%7%s%\%k!"J8;zNs$N$$$:$l$+$G$9!#(B

@table @code
@c @cindex percent symbol in mode line
@cindex $B%b!<%I9T$N%Q!<%;%s%H5-9f(B
@cindex $B%Q!<%;%s%H5-9f!"%b!<%I9T(B
@item @var{string}
@c A string as a mode line construct is displayed verbatim in the mode line
@c except for @dfn{@code{%}-constructs}.  Decimal digits after the @samp{%}
@c specify the field width for space filling on the right (i.e., the data
@c is left justified).  @xref{%-Constructs}.
$B%b!<%I9T9=@.$H$7$F$NJ8;zNs$O!"(B
@dfn{@code{%}$B5-K!(B}$B$r=|$$$F!"%b!<%I9T$K$=$N$^$^I=<($5$l$k!#(B
@samp{%}$B$N$&$7$m$N(B10$B?J?t$O!"1&B&$K6uGr$rKd$a$k(B
$B!J$D$^$j%G!<%?$O:8C<$KB7$($i$l$k!K$H$-$N%U%#!<%k%II}$r;XDj$9$k!#(B
@pxref{%-Constructs}$B!#(B

@item @var{symbol}
@c A symbol as a mode line construct stands for its value.  The value of
@c @var{symbol} is used as a mode line construct, in place of @var{symbol}.
@c However, the symbols @code{t} and @code{nil} are ignored; so is any
@c symbol whose value is void.
$B%b!<%I9T9=@.$H$7$F$N%7%s%\%k$O!"$=$NCM$rI=$9!#(B
@var{symbol}$B$NCM$O!"(B@var{symbol}$B$N$+$o$j$K%b!<%I9T9=@.$H$7$F;H$o$l$k!#(B
$B$7$+$7!"(B@code{t}$B$d(B@code{nil}$B$N%7%s%\%k!"$*$h$S!"%7%s%\%k$NCM$,6u$N$b$N$O(B
$BL5;k$9$k!#(B

@c There is one exception: if the value of @var{symbol} is a string, it is
@c displayed verbatim: the @code{%}-constructs are not recognized.
$BNc30$,(B1$B$D$"$k!'(B@code{ }
@var{symbol}$B$NCM$,J8;zNs$G$"$k$H!"(B@code{%}$B5-K!$r=hM}$;$:$K(B
$BJ8;zNs$r$=$N$^$^I=<($9$k!#(B

@item (@var{string} @var{rest}@dots{}) @r{or} (@var{list} @var{rest}@dots{})
@c A list whose first element is a string or list means to process all the
@c elements recursively and concatenate the results.  This is the most
@c common form of mode line construct.
$B:G=i$NMWAG$,J8;zNs$+%j%9%H$G$"$k%j%9%H$O!"(B
$B$9$Y$F$NMWAG$r:F5"E*$K=hM}$7!"7k2L$rO"7k$9$k$3$H$r0UL#$9$k!#(B
$B$3$l$O$b$C$H$bB?MQ$5$l$k%b!<%I9T9=@.$N7A$G$"$k!#(B

@item (@var{symbol} @var{then} @var{else})
@c A list whose first element is a symbol is a conditional.  Its meaning
@c depends on the value of @var{symbol}.  If the value is non-@code{nil},
@c the second element, @var{then}, is processed recursively as a mode line
@c element.  But if the value of @var{symbol} is @code{nil}, the third
@c element, @var{else}, is processed recursively.  You may omit @var{else};
@c then the mode line element displays nothing if the value of @var{symbol}
@c is @code{nil}.
$B:G=i$NMWAG$,%7%s%\%k$G$"$k%j%9%H$O>r7o@a$G$"$j!"(B
$B$=$N0UL#$O(B@var{symbol}$B$NCM$K0MB8$9$k!#(B
$B$=$NCM$,(B@code{nil}$B0J30$G$"$k$H!"(B
2$BHVL\$NMWAG(B@var{then}$B$r%b!<%I9T9=@.$H$7$F:F5"E*$K=hM}$9$k!#(B
@var{symbol}$B$NCM$,(B@code{nil}$B$G$"$k$H!"(B
3$BHVL\$NMWAG(B@var{else}$B$r%b!<%I9T9=@.$H$7$F:F5"E*$K=hM}$9$k!#(B
@var{else}$B$O>JN,$7$F$b$h$$$,!"$=$N>l9g!"(B
@var{symbol}$B$NCM$,(B@code{nil}$B$G$"$k$H$3$m$NMWAG$O%b!<%I9T$KI=<($5$l$J$$!#(B

@item (@var{width} @var{rest}@dots{})
@c A list whose first element is an integer specifies truncation or
@c padding of the results of @var{rest}.  The remaining elements
@c @var{rest} are processed recursively as mode line constructs and
@c concatenated together.  Then the result is space filled (if
@c @var{width} is positive) or truncated (to @minus{}@var{width} columns,
@c if @var{width} is negative) on the right.
$B:G=i$NMWAG$,@0?t$G$"$k%j%9%H$O!"(B
@var{rest}$B$N7k2L$N@Z$j5M$a$d0z$-?-$7$r;XDj$9$k!#(B
$B;D$j$NMWAG(B@var{rest}$B$O%b!<%I9T9=@.$H$7$F:F5"E*$K=hM}$5$lO"7k$5$l$k!#(B
$B!J(B@var{width}$B$,@5$G$"$l$P!K7k2L$N1&C<$K6uGr$rDI2C$7$?$j!"(B
$B!J(B@var{width}$B$,Ii$G$"$l$P!K7k2L$r!J(B@minus{}@var{width}$BI}$K!K(B
$B1&C<$+$i@Z$j5M$a$k!#(B

@c For example, the usual way to show what percentage of a buffer is above
@c the top of the window is to use a list like this: @code{(-3 "%p")}.
$B$?$H$($P!"%&%#%s%I%&$N>eC<$h$j>e$K%P%C%U%!$N2?3d$,$"$k$+$rI=<($9$k$K$O!"(B
@code{(-3 "%p")}$B$N$h$&$J%j%9%H$r;H$&!#(B
@end table

@c   If you do alter @code{mode-line-format} itself, the new value should
@c use the same variables that appear in the default value (@pxref{Mode
@c Line Variables}), rather than duplicating their contents or displaying
@c the information in another fashion.  This way, customizations made by
@c the user or by Lisp programs (such as @code{display-time} and major
@c modes) via changes to those variables remain effective.
$BFI<T$,(B@code{mode-line-format}$B<+BN$rJQ99$9$k$H$-$K$O!"(B
$B?7$7$$CM$G$O!"%G%U%)%k%HCM!J(B@pxref{Mode Line Variables}$B!K$K8=$l$k(B
$B$b$N$HF1$8JQ?t$r;H$$!"$=$l$i$NCM$r%3%T!<$7$F;H$C$?$j!"(B
$BJL$N=q<0$G>pJs$rI=<($7$?$j$7$J$$$G$/$@$5$$!#(B
$B$3$&$7$F$*$1$P!"$=$l$i$NJQ?t$KBP$9$kJQ99$r2p$7$?(B
$B%f!<%6!<$d!J(B@code{display-time}$B$d%a%8%c!<%b!<%I$J$I$N!K(BLisp$B%W%m%0%i%`$,9T$C$?(B
$B%+%9%?%^%$%:$,8z2L$rH/4x$G$-$^$9!#(B

@c @cindex Shell mode @code{mode-line-format}
@cindex $B%7%'%k%b!<%I$N(B@code{mode-line-format}
@cindex @code{mode-line-format}$B!"%7%'%k%b!<%I(B
@c   Here is an example of a @code{mode-line-format} that might be
@c useful for @code{shell-mode}, since it contains the host name and default
@c directory.
$B%[%9%HL>$d%G%U%)%k%H%G%#%l%/%H%j$r4^$s$@(B
@code{shell-mode}$B$KM-MQ$J(B@code{mode-line-format}$B$NNc$r<($7$^$9!#(B

@example
@group
(setq mode-line-format
  (list "-"
   'mode-line-mule-info
   'mode-line-modified
   'mode-line-frame-identification
   "%b--" 
@end group
@group
@c    ;; @r{Note that this is evaluated while making the list.}
@c    ;; @r{It makes a mode line construct which is just a string.}
   ;; @r{$B%j%9%H$r:n$k$H$-$KI>2A$5$l$k$3$H$KCm0U(B}
   ;; @r{$BC1$J$kJ8;zNs$N%b!<%I9T9=@.$r:n$k(B}
   (getenv "HOST")
@end group
   ":" 
   'default-directory
   "   "
   'global-mode-string
   "   %[("
   'mode-name 
   'mode-line-process  
   'minor-mode-alist 
   "%n" 
   ")%]--"
@group
   '(which-func-mode ("" which-func-format "--"))
   '(line-number-mode "L%l--")
   '(column-number-mode "C%c--")
   '(-3 . "%p")
   "-%-"))
@end group
@end example

@noindent
@c (The variables @code{line-number-mode}, @code{column-number-mode}
@c and @code{which-func-mode} enable particular minor modes; as usual,
@c these variable names are also the minor mode command names.)
$B!JJQ?t(B@code{line-number-mode}$B!"(B@code{column-number-mode}$B!"(B
@code{which-func-mode}$B$OFCDj$N%^%$%J%b!<%I$r%*%s$K$9$k!#(B
$BDL>o$I$*$j!"$3$l$i$NJQ?t$NL>A0$O%^%$%J%b!<%I%3%^%s%I$NL>A0$G$b$"$k!#!K(B

@node Mode Line Variables
@c @subsection Variables Used in the Mode Line
@subsection $B%b!<%I9T$K;H$o$l$kJQ?t(B

@c   This section describes variables incorporated by the
@c standard value of @code{mode-line-format} into the text of the mode
@c line.  There is nothing inherently special about these variables; any
@c other variables could have the same effects on the mode line if
@c @code{mode-line-format} were changed to use them.
$BK\@a$G$O!"(B@code{mode-line-format}$B$NI8=`CM$G%b!<%I9T$N%F%-%9%H$K(B
$B4^$a$i$l$kJQ?t$K$D$$$F=R$Y$^$9!#(B
$B$3$l$i$NJQ?t$K4X$7$F$O!"K\MhFCJL$J$3$H$O$"$j$^$;$s!#(B
$BJL$NJQ?t$r;H$&$h$&$K(B@code{mode-line-format}$B$rJQ99$9$l$P!"(B
$BJL$NJQ?t$G$b%b!<%I9T$K$*$$$FF1$88z2L$rH/4x$7$^$9!#(B

@defvar mode-line-mule-info
@tindex mode-line-mule-info
@c This variable holds the value of the mode-line construct that displays
@c information about the language environment, buffer coding system, and
@c current input method.  @xref{Non-ASCII Characters}.
$B$3$NJQ?t$O!"8@8l4D6-!"%P%C%U%!$N%3!<%G%#%s%0%7%9%F%`!"(B
$B8=:_$NF~NOJ}<0$K4X$9$k>pJs$rI=<($9$k%b!<%I9T9=@.$NCM$rJ];}$9$k!#(B
@pxref{Non-ASCII Characters}$B!#(B
@end defvar

@defvar mode-line-modified
@c This variable holds the value of the mode-line construct that displays
@c whether the current buffer is modified.
$B$3$NJQ?t$O!"%+%l%s%H%P%C%U%!$,JQ99$5$l$?$+$I$&$+$rI=<($9$k(B
$B%b!<%I9T9=@.$NCM$rJ];}$9$k!#(B

@c The default value of @code{mode-line-modified} is @code{("%1*%1+")}.
@c This means that the mode line displays @samp{**} if the buffer is
@c modified, @samp{--} if the buffer is not modified, @samp{%%} if the
@c buffer is read only, and @samp{%*} if the buffer is read only and
@c modified.
@code{mode-line-modified}$B$N%G%U%)%k%HCM$O(B@code{("%1*%1+")}$B$G$"$k!#(B
$B$3$l$O!"%P%C%U%!$,JQ99$5$l$F$$$k$H(B@samp{**}$B$r!"(B
$BL$JQ99$J$i$P(B@samp{--}$B$r!"FI$_=P$7@lMQ$J$i$P(B@samp{%%}$B$r!"(B
$BFI$_=P$7@lMQ$G$7$+$bJQ99$5$l$F$$$l$P(B@samp{%*}$B$r(B
$B%b!<%I9T$KI=<($9$k$3$H$r0UL#$9$k!#(B

@c Changing this variable does not force an update of the mode line.
$B$3$NJQ?t$rJQ99$7$F$b%b!<%I9T$N99?7$r6/@)$7$J$$!#(B
@end defvar

@defvar mode-line-frame-identification
@tindex mode-line-frame-identification
@c This variable identifies the current frame.  The default value is
@c @code{" "} if you are using a window system which can show multiple
@c frames, or @code{"-%F "} on an ordinary terminal which shows only one
@c frame at a time.
$B$3$NJQ?t$O%+%l%s%H%U%l!<%`$r<1JL$9$k!#(B
$BJ#?t$N%U%l!<%`$rI=<($G$-$k%&%#%s%I%&%7%9%F%`$r;HMQ$7$F$$$k>l9g$K$O(B
$B%G%U%)%k%HCM$O(B@code{" "}$B$G$"$j!"(B
$B$"$k;~E@$G(B1$B$D$N%U%l!<%`$7$+I=<($G$-$J$$IaDL$NC<Kv$r;HMQ$7$F$$$k>l9g$K$O(B
@code{"-%F "}$B$G$"$k!#(B
@end defvar

@defvar mode-line-buffer-identification
@c This variable identifies the buffer being displayed in the window.  Its
@c default value is @code{("%12b")}, which displays the buffer name, padded
@c with spaces to at least 12 columns.
$B$3$NJQ?t$O%&%#%s%I%&$KI=<($7$F$$$k%P%C%U%!$r<1JL$9$k!#(B
$B%G%U%)%k%HCM$O(B@code{("%12b")}$B$G$"$j!"(B
$B6uGr$GKd$a$F:GDc(B12$B%3%i%`$G%P%C%U%!L>$rI=<($9$k!#(B
@end defvar

@defvar global-mode-string
@c This variable holds a mode line spec that appears in the mode line by
@c default, just after the buffer name.  The command @code{display-time}
@c sets @code{global-mode-string} to refer to the variable
@c @code{display-time-string}, which holds a string containing the time and
@c load information.
$B$3$NJQ?t$O!"%G%U%)%k%H$G%b!<%I9T$N%P%C%U%!L>$ND>8e$K8=$l$k(B
$B%b!<%I9T;XDj$rJ];}$9$k!#(B
$B%3%^%s%I(B@code{display-time}$B$O!"(B
@code{global-mode-string}$B$,;~9o$HIi2Y>pJs$r4^$s$@(B
$BJQ?t(B@code{display-time-string}$B$r;2>H$9$k$h$&$K@_Dj$9$k!#(B

@c The @samp{%M} construct substitutes the value of
@c @code{global-mode-string}, but that is obsolete, since the variable is
@c included in the mode line from @code{mode-line-format}.
@samp{%M}$B5-K!$O(B@code{global-mode-string}$B$NCM$r;H$&$,!"(B
$B$3$NJQ?t$O(B@code{mode-line-format}$B$G%b!<%I9T$K4^$^$l$k$?$a(B
@samp{%M}$B$OGQ$l$?5-K!$G$"$k!#(B
@end defvar

@defvar mode-name
@c This buffer-local variable holds the ``pretty'' name of the current
@c buffer's major mode.  Each major mode should set this variable so that the
@c mode name will appear in the mode line.
$B$3$N%P%C%U%!%m!<%+%k$JJQ?t$O!"(B
$B%+%l%s%H%P%C%U%!$N%a%8%c!<%b!<%I$N!X0&>N!Y$rJ];}$9$k!#(B
$B3F%a%8%c!<%b!<%I$O!"%b!<%I9T$K%b!<%IL>$,8=$l$k$h$&$K$3$NJQ?t$K@_Dj$9$k$3$H!#(B
@end defvar

@defvar minor-mode-alist
@c This variable holds an association list whose elements specify how the
@c mode line should indicate that a minor mode is active.  Each element of
@c the @code{minor-mode-alist} should be a two-element list:
$B$3$NJQ?t$O!"%b!<%I9T$K%^%$%J%b!<%I$,%*%s$G$"$k$3$H$rI=<($9$kJ}K!$r(B
$B;XDj$9$kMWAG$+$i$J$kO"A[%j%9%H$rJ];}$9$k!#(B
@code{minor-mode-alist}$B$N3FMWAG$O!"(B2$BMWAG%j%9%H$G$"$k$3$H!#(B

@example
(@var{minor-mode-variable} @var{mode-line-string})
@end example

@c More generally, @var{mode-line-string} can be any mode line spec.  It
@c appears in the mode line when the value of @var{minor-mode-variable} is
@c non-@code{nil}, and not otherwise.  These strings should begin with
@c spaces so that they don't run together.  Conventionally, the
@c @var{minor-mode-variable} for a specific mode is set to a non-@code{nil}
@c value when that minor mode is activated.
$B$h$j0lHLE*$K$O!"(B@var{mode-line-string}$B$O$I$N$h$&$J%b!<%I9T;XDj$G$b$h$$!#(B
$B$=$l$O!"(B@var{minor-mode-variable}$B$NCM$,(B@code{nil}$B0J30$N$H$-$K(B
$B%b!<%I9T$K8=$l!"$5$b$J$1$l$P8=$l$J$$!#(B
$B$3$l$i$NJ8;zNs$O!"7R$,$i$J$$$h$&$K6uGr$G;O$^$k$3$H!#(B
$B47=,E*$K$O!"FCDj%b!<%I$KBP$9$k(B@var{minor-mode-variable}$B$O!"(B
$BEv3:%^%$%J%b!<%I$,%*%s$G$"$k$H(B@code{nil}$B0J30$K@_Dj$5$l$k!#(B

@c The default value of @code{minor-mode-alist} is:
@code{minor-mode-alist}$B$N%G%U%)%k%HCM$O$D$.$N$H$*$j!#(B

@example
@group
minor-mode-alist
@result{} ((vc-mode vc-mode)
    (abbrev-mode " Abbrev") 
    (overwrite-mode overwrite-mode) 
    (auto-fill-function " Fill")         
    (defining-kbd-macro " Def")
    (isearch-mode isearch-mode))
@end group
@end example

@c @code{minor-mode-alist} itself is not buffer-local.  Each variable
@c mentioned in the alist should be buffer-local if its minor mode can be
@c enabled separately in each buffer.
@code{minor-mode-alist}$B<+BN$O%P%C%U%!%m!<%+%k$G$O$J$$!#(B
$B%^%$%J%b!<%I$,3F%P%C%U%!$4$H$K%*%s$K$G$-$k>l9g$K$O!"(B
$BO"A[%j%9%H$K;XDj$7$?BP1~$9$k3FJQ?t$O%P%C%U%!%m!<%+%k$G$"$k$3$H!#(B
@end defvar

@defvar mode-line-process
@c This buffer-local variable contains the mode line information on process
@c status in modes used for communicating with subprocesses.  It is
@c displayed immediately following the major mode name, with no intervening
@c space.  For example, its value in the @samp{*shell*} buffer is
@c @code{(":%s")}, which allows the shell to display its status along
@c with the major mode as: @samp{(Shell:@: run)}.  Normally this variable
@c is @code{nil}.
$B$3$N%P%C%U%!%m!<%+%k$JJQ?t$O!"(B
$B%5%V%W%m%;%9$H$NDL?.MQ$K;H$o$l$F$$$k%b!<%I$N=hM}>uBV$K4X$9$k(B
$B%b!<%I9T$N>pJs$rJ];}$9$k!#(B
$B%a%8%c!<%b!<%IL>$ND>8e$K6uGr$G6h@Z$i$:$KI=<($5$l$k!#(B
$B$?$H$($P!"%P%C%U%!(B@samp{*shell*}$B$K$*$1$k$3$NJQ?t$NCM$O(B@code{(":%s")}$B$G$"$j!"(B
$B%7%'%k$,$=$N>uBV$r%a%8%c!<%b!<%I$H$H$b$K(B@samp{(Shell:@: run)}$B$N$h$&$K(B
$BI=<($G$-$k!#(B
$BDL>o!"$3$NJQ?t$O(B@code{nil}$B$G$"$k!#(B
@end defvar

@defvar default-mode-line-format
@c This variable holds the default @code{mode-line-format} for buffers
@c that do not override it.  This is the same as @code{(default-value
@c 'mode-line-format)}.
$B$3$NJQ?t$O!"(B@code{mode-line-format}$B$rJQ99$7$F$$$J$$%P%C%U%!$N(B
$B%G%U%)%k%H$N(B@code{mode-line-format}$B$NCM$rJ];}$9$k!#(B
$B$3$l$O(B@code{(default-value 'mode-line-format)}$B$HF1$8$G$"$k!#(B

@c The default value of @code{default-mode-line-format} is this list:
@code{default-mode-line-format}$B$N%G%U%)%k%HCM$O$D$.$N%j%9%H$G$"$k!#(B

@example
@group
("-"
 mode-line-mule-info
 mode-line-modified
 mode-line-frame-identification
 mode-line-buffer-identification
@end group
 "   "
 global-mode-string
@group
 "   %[("
 mode-name 
 mode-line-process
 minor-mode-alist 
 "%n" 
 ")%]--"
@end group
@group
 (which-func-mode ("" which-func-format "--"))
 (line-number-mode "L%l--")
 (column-number-mode "C%c--")
 (-3 . "%p")
 "-%-")
@end group
@end example
@end defvar

@defvar vc-mode
@c The variable @code{vc-mode}, buffer-local in each buffer, records
@c whether the buffer's visited file is maintained with version control,
@c and, if so, which kind.  Its value is @code{nil} for no version control,
@c or a string that appears in the mode line.
$B3F%P%C%U%!$K$*$$$F%P%C%U%!%m!<%+%k$JJQ?t(B@code{vc-mode}$B$O!"(B
$B%P%C%U%!$GK,Ld$7$?%U%!%$%k$,HG4IM}$5$l$F$$$k$+!"(B
$B$=$&$J$i$P$=$NJ}<0$r5-O?$7$F$$$k!#(B
$BHG4IM}$5$l$F$$$J$$>l9g$O$=$NCM$O(B@code{nil}$B!"(B
$B$5$b$J$1$l$P%b!<%I9T$KI=<($5$l$kJ8;zNs$G$"$k!#(B
@end defvar

@node %-Constructs
@c @subsection @code{%}-Constructs in the Mode Line
@subsection $B%b!<%I9T$N(B@code{%}$B5-K!(B

@c   The following table lists the recognized @code{%}-constructs and what
@c they mean.  In any construct except @samp{%%}, you can add a decimal
@c integer after the @samp{%} to specify how many characters to display.
$B0J2<$O!"G'<1$5$l$k(B@code{%}$B5-K!$H$=$N0UL#$NI=$G$9!#(B
@samp{%%}$B0J30$N5-K!$G$O!"(B
$B:GBgI=<(J8;z?t$r;XDj$9$k(B10$B?J?t$r(B@samp{%}$B$N$"$H$KDI2C$G$-$^$9!#(B

@table @code
@item %b
@c The current buffer name, obtained with the @code{buffer-name} function.
@c @xref{Buffer Names}.
$B4X?t(B@code{buffer-name}$B$GF@$i$l$?%+%l%s%H%P%C%U%!L>!#(B
@pxref{Buffer Names}$B!#(B

@item %f
@c The visited file name, obtained with the @code{buffer-file-name}
@c function.  @xref{Buffer File Name}.
$B4X?t(B@code{buffer-file-name}$B$GF@$i$l$?K,Ld$7$?%U%!%$%k$NL>A0!#(B
@pxref{Buffer File Name}$B!#(B

@item %F
@c The title (only on a window system) or the name of the selected frame.
@c @xref{Window Frame Parameters}.
$BA*Br$7$F$$$k%U%l!<%`$N%?%$%H%k!J%&%#%s%I%&%7%9%F%`>e$N$_!K$+L>A0!#(B
@pxref{Window Frame Parameters}$B!#(B

@item %c
@c The current column number of point.
$B%]%$%s%H$N8=:_$N%3%i%`HV9f!#(B

@item %l
@c The current line number of point.
$B%]%$%s%H$N8=:_$N9THV9f!#(B

@item %*
@c @samp{%} if the buffer is read only (see @code{buffer-read-only}); @*
@c @samp{*} if the buffer is modified (see @code{buffer-modified-p}); @*
@c @samp{-} otherwise.  @xref{Buffer Modification}.
$B%P%C%U%!$,FI$_=P$7@lMQ$G$"$l$P(B@samp{%}$B!J(B@code{buffer-read-only}$B$r;2>H!K!"(B@*
$B%P%C%U%!$,JQ99$5$l$F$$$l$P(B@samp{*}$B!J(B@code{buffer-modified-p}$B$r;2>H!K!"(B@*
$B$5$b$J$1$l$P(B@samp{-}$B!#(B
@pxref{Buffer Modification}$B!#(B

@item %+
@c @samp{*} if the buffer is modified (see @code{buffer-modified-p}); @*
@c @samp{%} if the buffer is read only (see @code{buffer-read-only}); @*
@c @samp{-} otherwise.  This differs from @samp{%*} only for a modified
@c read-only buffer.  @xref{Buffer Modification}.
$B%P%C%U%!$,JQ99$5$l$F$$$l$P(B@samp{*}$B!J(B@code{buffer-modified-p}$B$r;2>H!K!"(B@*
$B%P%C%U%!$,FI$_=P$7@lMQ$G$"$l$P(B@samp{%}$B!J(B@code{buffer-read-only}$B$r;2>H!K!"(B@*
$B$5$b$J$1$l$P(B@samp{-}$B!#(B
@samp{%*}$B$H$N0c$$$O!"JQ99$5$l$?FI$_=P$7@lMQ%P%C%U%!$KBP$7$F$N$_$G$"$k!#(B
@pxref{Buffer Modification}$B!#(B

@item %&
@c @samp{*} if the buffer is modified, and @samp{-} otherwise.
$B%P%C%U%!$,JQ99$5$l$F$$$l$P(B@samp{*}$B!"$5$b$J$1$l$P(B@samp{-}$B$G$"$k!#(B

@item %s
@c The status of the subprocess belonging to the current buffer, obtained with
@c @code{process-status}.  @xref{Process Information}.
@code{process-status}$B$GF@$?%+%l%s%H%P%C%U%!$KB0$9$k%5%V%W%m%;%9$N>uBV!#(B
@pxref{Process Information}$B!#(B

@item %t
@c Whether the visited file is a text file or a binary file.  (This is a
@c meaningful distinction only on certain operating systems.)
$BK,Ld$7$?%U%!%$%k$,%F%-%9%H%U%!%$%k$G$"$k$+%P%$%J%j%U%!%$%k$G$"$k$+$rI=$9!#(B
$B!JFCDj$N%*%Z%l!<%F%#%s%0%7%9%F%`$G$N$_0UL#$r;}$D!#!K(B

@item %p
@c The percentage of the buffer text above the @strong{top} of window, or
@c @samp{Top}, @samp{Bottom} or @samp{All}.
$B%&%#%s%I%&$N(B@strong{$B>eC<(B}$B$N>e$K$"$k%P%C%U%!$N%F%-%9%H$N3d9g!"(B
$B$"$k$$$O!"(B@samp{Top}$B!"(B@samp{Bottom}$B!"(B@samp{All}$B$N$$$:$l$+$G$"$k!#(B

@item %P
@c The percentage of the buffer text that is above the @strong{bottom} of
@c the window (which includes the text visible in the window, as well as
@c the text above the top), plus @samp{Top} if the top of the buffer is
@c visible on screen; or @samp{Bottom} or @samp{All}.
$B%&%#%s%I%&$N(B@strong{$B2<C<(B}$B$N>e$K$"$k%P%C%U%!$N%F%-%9%H(B
$B!J%&%#%s%I%&$K8+$($F$k%F%-%9%H$H>eC<$N>e$K$"$k%F%-%9%H!K$N3d9g$K(B
$B%P%C%U%!$N@hF,$,8+$($F$$$l$P(B@samp{Top}$B$r2C$($?$b$N!"(B
$B$"$k$$$O!"(B@samp{Bottom}$B!"(B@samp{All}$B$N$$$:$l$+$G$"$k!#(B

@item %n
@c @samp{Narrow} when narrowing is in effect; nothing otherwise (see
@c @code{narrow-to-region} in @ref{Narrowing}).
$B%J%m%$%s%0$7$F$$$k$H(B@samp{Narrow}$B!"$5$b$J$1$l$P$J$K$b$J$7!#(B
$B!J(B@ref{Narrowing}$B$N(B@code{narrow-to-region}$B$r;2>H!K!#(B

@item %[
@c An indication of the depth of recursive editing levels (not counting
@c minibuffer levels): one @samp{[} for each editing level.
@c @xref{Recursive Editing}.
$B!J%_%K%P%C%U%!$N%l%Y%k$r=|$/!K:F5"JT=8%l%Y%k$N?<$5$rI=$9!#(B
$B3FJT=8%l%Y%k$4$H$K(B1$B$D$N(B@samp{[}$B!#(B
@pxref{Recursive Editing}$B!#(B

@item %]
@c One @samp{]} for each recursive editing level (not counting minibuffer
@c levels).
$B!J%_%K%P%C%U%!$N%l%Y%k$r=|$/!K3F:F5"JT=8%l%Y%k$4$H$K(B1$B$D$N(B@samp{]}$B!#(B

@item %%
@c The character @samp{%}---this is how to include a literal @samp{%} in a
@c string in which @code{%}-constructs are allowed.
$BJ8;z(B@samp{%}$B!#(B
@code{%}$B5-K!$r5v$9J8;zNs$K(B@samp{%}$B$r$=$N$^$^4^$a$k$?$a$NJ}K!$G$"$k!#(B

@item %-
@c Dashes sufficient to fill the remainder of the mode line.
$B%b!<%I9T$N;D$jItJ,$rKd$a$k$K==J,$J8D?t$N%@%C%7%e!#(B
@end table

@c The following two @code{%}-constructs are still supported, but they are
@c obsolete, since you can get the same results with the variables
@c @code{mode-name} and @code{global-mode-string}.
$B$D$.$N(B2$B$D$N(B@code{%}$B5-K!$O$^$@;H$($^$9$,!"(B
$BJQ?t(B@code{mode-name}$B$d(B@code{global-mode-string}$B$r(B
$B;H$C$FF1$88z2L$rF@$i$l$k$N$G$3$l$i$OGQ$l$?5-K!$G$9!#(B

@table @code
@item %m
@c The value of @code{mode-name}.
@code{mode-name}$B$NCM!#(B

@item %M
@c The value of @code{global-mode-string}.  Currently, only
@c @code{display-time} modifies the value of @code{global-mode-string}.
@code{global-mode-string}$B$NCM!#(B
$B8=:_!"(B@code{display-time}$B$O(B@code{global-mode-string}$B$NCM$rJQ99$9$k!#(B
@end table

@node Imenu
@c @section Imenu
@section i$B%a%K%e!<(B

@c @cindex Imenu
@cindex i$B%a%K%e!<(B
@c   @dfn{Imenu} is a feature that lets users select a definition or
@c section in the buffer, from a menu which lists all of them, to go
@c directly to that location in the buffer.  Imenu works by constructing a
@c buffer index which lists the names and positions of the definitions or
@c portions of in the buffer, so the user can pick one of them to move to.
@c This section explains how to customize Imenu for a major mode.
@dfn{i$B%a%K%e!<(B}$B!J(BImenu$B!K$H$O!"%f!<%6!<$,(B
$B%P%C%U%!Fb$NDj5A$d@a$N0lMw$+$i$=$N(B1$B$D$rA*$V$H(B
$B%P%C%U%!Fb$NEv3:2U=j$XD>@\0\F0$G$-$k5!G=$G$9!#(B
i$B%a%K%e!<$O!"(B
$B%P%C%U%!Fb$NDj5A$dItJ,$NL>A0$d0LCV$rI=$9%P%C%U%!%$%s%G%C%/%9$r(B
$B9=C[$7$F$*$/$3$H$GF0:n$7!"(B
$BEv3:2U=j$X0\F0$9$k$?$a$K%f!<%6!<$,$=$l$i$N(B1$B$D$rA*$Y$k$h$&$K$7$^$9!#(B
$BK\@a$G$O%a%8%c!<%b!<%I$KBP$9$k(Bi$B%a%K%e!<$r%+%9%?%^%$%:$9$kJ}K!$r@bL@$7$^$9!#(B

@c   The usual and simplest way is to set the variable
@c @code{imenu-generic-expression}:
$BIaDL$N$b$C$H$bC1=c$JJ}K!$O!"(B
$BJQ?t(B@code{imenu-generic-expression}$B$K@_Dj$9$k$3$H$G$9!#(B

@defvar imenu-generic-expression
@c This variable, if non-@code{nil}, specifies regular expressions for
@c finding definitions for Imenu.  In the simplest case, elements should
@c look like this:
$B$3$NJQ?t$,(B@code{nil}$B0J30$G$"$k$H!"(B
i$B%a%K%e!<8~$1$NDj5A$rC5$9$?$a$N@55,I=8=$r;XDj$9$k!#(B
$B$b$C$H$bC1=c$J>l9g!"MWAG$O$D$.$N$h$&$J7A$G$"$k!#(B

@example
(@var{menu-title} @var{regexp} @var{subexp})
@end example

@c Here, if @var{menu-title} is non-@code{nil}, it says that the matches
@c for this element should go in a submenu of the buffer index;
@c @var{menu-title} itself specifies the name for the submenu.  If
@c @var{menu-title} is @code{nil}, the matches for this element go directly
@c in the top level of the buffer index.
$B$3$3$G!"(B@var{menu-title}$B$,(B@code{nil}$B0J30$G$"$k$H!"(B
$B$3$NMWAG$K0lCW$7$?$b$N$O%P%C%U%!%$%s%G%C%/%9$N%5%V%a%K%e!<$KCV$/$3$H$r(B
$B0UL#$9$k!#(B
@var{menu-title}$B<+BN$O%5%V%a%K%e!<$NL>A0$r;XDj$9$k!#(B
@var{menu-title}$B$,(B@code{nil}$B$G$"$k$H!"(B
$B$3$NMWAG$K0lCW$7$?$b$N$O%P%C%U%!%$%s%G%C%/%9$N%a%K%e!<$KD>@\CV$+$l$k!#(B

@c The second item in the list, @var{regexp}, is a regular expression
@c (@pxref{Regular Expressions}); wherever it matches, that is a definition
@c to mention in the buffer index.  The third item, @var{subexp}, indicates
@c which subexpression in @var{regexp} matches the definition's name.
$B%j%9%H$N(B2$BHVL\$NMWAG(B@var{regexp}$B$O@55,I=8=(B
$B!J(B@pxref{Regular Expressions}$B!K$G$"$j!"(B
$B$3$l$K0lCW$7$?2U=j$,%P%C%U%!%$%s%G%C%/%9$K8=$l$kDj5A$K$J$k!#(B
3$BHVL\$NMWAG(B@var{subexp}$B$O!"(B
$BDj5A$NL>A0$K0lCW$9$k(B@var{regexp}$B$NItJ,<0$G$"$k!#(B

@c An element can also look like this:
$BMWAG$O$D$.$N7A$G$b$h$$!#(B

@example
(@var{menu-title} @var{regexp} @var{index} @var{function} @var{arguments}@dots{})
@end example

@c Each match for this element creates a special index item which, if
@c selected by the user, calls @var{function} with arguments
@c @var{item-name}, the buffer position, and @var{arguments}.
$B$3$NMWAG$K0lCW$9$k$b$N$O!"%P%C%U%!%$%s%G%C%/%9$NFCJL$J9`L\$K$J$j!"(B
$B%f!<%6!<$,Ev3:9`L\$rA*$V$H!"(B
@var{item-name}$B!"%P%C%U%!0LCV!"(B@var{arguments}$B$r0z?t$H$7$F(B
@var{function}$B$r8F$S=P$9!#(B

@c For Emacs Lisp mode, @var{pattern} could look like this:
emacs-lisp$B%b!<%I8~$1$K$O!"(B@var{pattern}$B$O$D$.$N$h$&$K$J$k!#(B

@c should probably use imenu-syntax-alist and \\sw rather than [-A-Za-z0-9+]
@example
@group
((nil "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\)\
\\s-+\\([-A-Za-z0-9+]+\\)" 2)
@end group
@group
 ("*Vars*" "^\\s-*(def\\(var\\|const\\)\
\\s-+\\([-A-Za-z0-9+]+\\)" 2)
@end group
@group
 ("*Types*"
  "^\\s-*\
(def\\(type\\|struct\\|class\\|ine-condition\\)\
\\s-+\\([-A-Za-z0-9+]+\\)" 2))
@end group
@end example

@c Setting this variable makes it buffer-local in the current buffer.
$B$3$NJQ?t$K@_Dj$9$k$H!"(B
$B%+%l%s%H%P%C%U%!$K$*$$$F%P%C%U%!%m!<%+%k$JJQ?t$K$J$k!#(B
@end defvar

@defvar imenu-case-fold-search
@c This variable controls whether matching against
@c @var{imenu-generic-expression} is case-sensitive: @code{t}, the default,
@c means matching should ignore case.
$B$3$NJQ?t$O!"(B@var{imenu-generic-expression}$B$H$N0lCW$K:]$7$F(B
$BBgJ8;z>.J8;z$r6hJL$9$k$+$I$&$+$r@)8f$9$k!#(B
$B%G%U%)%k%H$O(B@code{t}$B$G$"$j!"BgJ8;z>.J8;z$r6hJL$;$:$K0lCW$r$H$k!#(B

@c Setting this variable makes it buffer-local in the current buffer.
$B$3$NJQ?t$K@_Dj$9$k$H!"(B
$B%+%l%s%H%P%C%U%!$K$*$$$F%P%C%U%!%m!<%+%k$JJQ?t$K$J$k!#(B
@end defvar

@defvar imenu-syntax-alist
@c This variable is an alist of syntax table modifiers to use while
@c processing @code{imenu-generic-expression}, to override the syntax table
@c of the current buffer.  Each element should have this form:
$B$3$NJQ?t$O!"(B@code{imenu-generic-expression}$B$r=hM}Cf$K(B
$B%+%l%s%H%P%C%U%!$N9=J8%F!<%V%k$KM%@h$9$k(B
$B9=J8%F!<%V%k$NJQ99ItJ,$NO"A[%j%9%H$G$"$k!#(B
$B3FMWAG$O$D$.$N7A$G$"$k$3$H!#(B

@example
(@var{characters} . @var{syntax-description})
@end example

@c The @sc{car}, @var{characters}, can be either a character or a string.
@c The element says to give that character or characters the syntax
@c specified by @var{syntax-description}, which is passed to
@c @code{modify-syntax-entry} (@pxref{Syntax Table Functions}).
@sc{car}$B$N(B@var{characters}$B$O!"J8;z$+J8;zNs$G$"$k!#(B
$B$=$l$i$NJ8;z$O!";XDj$7$?9=J8(B@var{syntax-description}$B$G$"$k$3$H$r0UL#$9$k!#(B
$B$3$l$O(B@code{modify-syntax-entry}$B!J(B@pxref{Syntax Table Functions}$B!K$K(B
$BEO$5$l$k!#(B

@c This feature is typically used to give word syntax to characters which
@c normally have symbol syntax, and thus to simplify
@c @code{imenu-generic-expression} and speed up matching.
@c For example, Fortran mode uses it this way:
$B$3$N5!G=$OE57?E*$K$O!"(B
$BDL>o$N%7%s%\%k9=@.J8;z$rC18l9=@.J8;z$H$7$F07$$!"(B
@code{imenu-generic-expression}$B$rC1=c2=$70lCW=hM}$rB.$/$9$k!#(B
$B$?$H$($P!"(Bfortran$B%b!<%I$G$O$D$.$N$h$&$K;H$C$F$$$k!#(B

@example
  (setq imenu-syntax-alist '(("_$" . "w")))
@end example

@c The @code{imenu-generic-expression} patterns can then use @samp{\\sw+}
@c instead of @samp{\\(\\sw\\|\\s_\\)+}.  Note that this technique may be
@c inconvenient to use when the mode needs to limit the initial character
@c of a name to a smaller set of characters than are allowed in the rest
@c of a name.
$B$3$&$9$k$H!"(B@code{imenu-generic-expression}$B$N%Q%?!<%s$G$O!"(B
@samp{\\(\\sw\\|\\s_\\)+}$B$N$+$o$j$K(B@samp{\\sw+}$B$r;H$($k!#(B
$B$3$N5;K!$O!"L>A0$N@hF,J8;z$N=89g$rL>A0$N;D$j$NJ8;z$N=89g$h$j$b(B
$B>.$5$/@)8B$9$kI,MW$,$"$k%b!<%I$G;H$&$K$OITJX$G$"$k$3$H$KCm0U$7$F$[$7$$!#(B

@c Setting this variable makes it buffer-local in the current buffer.
$B$3$NJQ?t$K@_Dj$9$k$H!"(B
$B%+%l%s%H%P%C%U%!$K$*$$$F%P%C%U%!%m!<%+%k$JJQ?t$K$J$k!#(B
@end defvar

@c   Another way to customize Imenu for a major mode is to set the
@c variables @code{imenu-prev-index-position-function} and
@c @code{imenu-extract-index-name-function}:
$B%a%8%c!<%b!<%I$N(Bi$B%a%K%e!<$r%+%9%?%^%$%:$9$kJL$NJ}K!$O!"(B
$BJQ?t(B@code{imenu-prev-index-position-function}$B$d(B
@code{imenu-extract-index-name-function}$B$K@_Dj$9$k$3$H$G$9!#(B

@defvar imenu-prev-index-position-function
@c If this variable is non-@code{nil}, its value should be a function for
@c finding the next definition to mention in the buffer index, moving
@c backwards in the file.
$B$3$NJQ?t$,(B@code{nil}$B0J30$G$"$k$H!"$=$NCM$O!"(B
$B%P%C%U%!%$%s%G%C%/%9$KCV$/$D$.$NDj5A$r(B
$B%U%!%$%k$G8e8~$-$KC5$9$?$a$N4X?t$G$"$k$3$H!#(B

@c The function should leave point at the place to be connected to the
@c index item; it should return @code{nil} if it doesn't find another item.
$B$=$N4X?t$O!"%P%C%U%!%$%s%G%C%/%9$N9`L\$KBP1~$9$k2U=j$K%]%$%s%H$rCV$/$3$H!#(B
$B9`L\$,$_$D$+$i$J$1$l$P(B@code{nil}$B$rJV$9$3$H!#(B

@c Setting this variable makes it buffer-local in the current buffer.
$B$3$NJQ?t$K@_Dj$9$k$H!"(B
$B%+%l%s%H%P%C%U%!$K$*$$$F%P%C%U%!%m!<%+%k$JJQ?t$K$J$k!#(B
@end defvar

@defvar imenu-extract-index-name-function
@c If this variable is non-@code{nil}, its value should be a function to
@c return the name for a definition, assuming point is in that definition
@c as the @code{imenu-prev-index-position-function} function would leave
@c it.
$B$3$N4X?t$,(B@code{nil}$B0J30$G$"$k$H!"$=$NCM$O!"(B
$B%]%$%s%H$,JQ?t(B@code{imenu-prev-index-position-function}$B$,JV$7$?(B
$BDj5A$NItJ,$K$"$k$H2>Dj$7$F!"Ev3:Dj5A$NL>A0$rJV$94X?t$G$"$k$3$H!#(B

@c Setting this variable makes it buffer-local in the current buffer.
$B$3$NJQ?t$K@_Dj$9$k$H!"(B
$B%+%l%s%H%P%C%U%!$K$*$$$F%P%C%U%!%m!<%+%k$JJQ?t$K$J$k!#(B
@end defvar

@c   The last way to customize Imenu for a major mode is to set the
@c variables @code{imenu-create-index-function}:
$B%a%8%c!<%b!<%I$N(Bi$B%a%K%e!<$r%+%9%?%^%$%:$9$k:G8e$NJ}K!$O!"(B
$BJQ?t(B@code{imenu-create-index-function}$B$K@_Dj$9$k$3$H$G$9!#(B

@defvar imenu-create-index-function
@c This variable specifies the function to use for creating a buffer index.
@c The function should take no arguments, and return an index for the
@c current buffer.  It is called within @code{save-excursion}, so where it
@c leaves point makes no difference.
$B$3$N4X?t$O!"%P%C%U%!%$%s%G%C%/%9$N:n@.$K;H$&4X?t$r;XDj$9$k!#(B
$B$=$N4X?t$O0z?t$J$7$G!"%+%l%s%H%P%C%U%!$KBP$9$k%$%s%G%C%/%9$rJV$9$3$H!#(B
@code{save-excursion}$B$NFbB&$+$i8F$P$l$k$N$G!"(B
$B$=$N4X?t$,%]%$%s%H$r$I$3$KCV$3$&$H4X78$J$$!#(B

@c The default value is a function that uses
@c @code{imenu-generic-expression} to produce the index alist.  If you
@c specify a different function, then @code{imenu-generic-expression} is
@c not used.
$B%G%U%)%k%HCM$O!"%$%s%G%C%/%9$NO"A[%j%9%H$r@8@.$9$k$?$a$K(B
@code{imenu-generic-expression}$B$r;H$&4X?t$G$"$k!#(B
$BFI<T$,JL$N4X?t$r;XDj$9$l$P!"(B@code{imenu-generic-expression}$B$O;H$o$l$J$$!#(B

@c Setting this variable makes it buffer-local in the current buffer.
$B$3$NJQ?t$K@_Dj$9$k$H!"(B
$B%+%l%s%H%P%C%U%!$K$*$$$F%P%C%U%!%m!<%+%k$JJQ?t$K$J$k!#(B
@end defvar

@defvar imenu-index-alist
@c This variable holds the index alist for the current buffer.
@c Setting it makes it buffer-local in the current buffer.
$B$3$NJQ?t$O!"%+%l%s%H%P%C%U%!$KBP$9$k%$%s%G%C%/%9$NO"A[%j%9%H$rJ];}$9$k!#(B
$B$3$NJQ?t$K@_Dj$9$k$H!"(B
$B%+%l%s%H%P%C%U%!$K$*$$$F%P%C%U%!%m!<%+%k$JJQ?t$K$J$k!#(B

@c Simple elements in the alist look like @code{(@var{index-name}
@c . @var{index-position})}.  Selecting a simple element has the effect of
@c moving to position @var{index-position} in the buffer.
$BO"A[%j%9%H$NC1=c$JMWAG$O(B@code{(@var{index-name} . @var{index-position})}
$B$N$h$&$J7A$G$"$k!#(B
$B$3$N$h$&$JC1=c$JMWAG$rA*$V$H!"(B
$B%P%C%U%!Fb$G(B@var{index-position}$B$X0\F0$9$k8z2L$,$"$k!#(B

@c Special elements look like @code{(@var{index-name} @var{position}
@c @var{function} @var{arguments}@dots{})}.  Selecting a special element
@c performs
$BFCJL$JMWAG$O(B@code{(@var{index-name} @var{position}
@var{function} @var{arguments}@dots{})}$B$N$h$&$J7A$G$"$k!#(B
$B$3$N$h$&$JFCJL$JMWAG$rA*$V$H!"(B
$B$D$.$N$h$&$J%U%)!<%`$r<B9T$9$k!#(B

@example
(funcall @var{function} @var{index-name} @var{position} @var{arguments}@dots{})
@end example

@c A nested sub-alist element looks like @code{(@var{index-name}
@c @var{sub-alist})}.
$BF~$l;R$K$J$C$?ItJ,O"A[%j%9%H$NMWAG$O(B
@code{(@var{index-name}  @var{sub-alist})}$B$N$h$&$J7A$G$"$k!#(B
@end defvar

@node Font Lock Mode
@c @section Font Lock Mode
@section $B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I(B
@c @cindex Font Lock Mode
@cindex $B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I(B

@c   @dfn{Font Lock mode} is a feature that automatically attaches
@c @code{face} properties to certain parts of the buffer based on their
@c syntactic role.  How it parses the buffer depends on the major mode;
@c most major modes define syntactic criteria for which faces to use, in
@c which contexts.  This section explains how to customize Font Lock for a
@c particular language---in other words, for a particular major mode.
@dfn{$B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I(B}$B$H$O!"(B
$B%P%C%U%!Fb$NFCDjItJ,$KBP$7$F!"$=$l$i$N9=J8>e$NLr3d$K1~$8$?(B
$BB0@-(B@code{face}$B$r<+F0E*$KIU2C$9$k5!G=$N$3$H$G$9!#(B
$B%P%C%U%!$r2r@O$9$kJ}K!$O%a%8%c!<%b!<%I$K0MB8$7$^$9$,!"(B
$B$[$H$s$I$N%a%8%c!<%b!<%I$G$O!"(B
$B$I$NJ8L.$G$I$N%U%'%$%9$r;H$&$+$r;X<($9$k>r7o$rDj5A$7$^$9!#(B
$BK\@a$G$O!"FCDj$N8@8l8~$1$K!"$$$$$+$($l$P!"(B
$BFCDj$N%a%8%c!<%b!<%I8~$1$K(B
$B%U%)%s%H%m%C%/$r%+%9%?%^%$%:$9$kJ}K!$r@bL@$7$^$9!#(B

@c   Font Lock mode finds text to highlight in two ways: through syntactic
@c parsing based on the syntax table, and through searching (usually for
@c regular expressions).  Syntactic fontification happens first; it finds
@c comments and string constants, and highlights them using
@c @code{font-lock-comment-face} and @code{font-lock-string-face}
@c (@pxref{Faces for Font Lock}); search-based fontification follows.
$B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I$O!"6/D4I=<($9$Y$-%F%-%9%H$r(B
2$B$D$NJ}K!$G!"$D$^$j!"9=J8%F!<%V%k$K4p$E$$$?9=J82r@O!"$"$k$$$O!"(B
$B!JDL>o!"@55,I=8=$K$h$k!KC5:w$GC5$7$^$9!#(B
$B9=J82r@O$K$h$k=hM}$r:G=i$K9T$C$F%3%a%s%H$dJ8;zNsDj?t$rC5$7!"(B
@code{font-lock-comment-face}$B$d(B@code{font-lock-string-face}
$B!J(B@pxref{Faces for Font Lock}$B!K$r;H$C$F$=$l$i$r6/D4I=<($7$^$9!#(B
$BC5:w$K$h$k=hM}$,$3$l$KB3$-$^$9!#(B

@menu
* Font Lock Basics::
* Search-based Fontification::
* Other Font Lock Variables::
* Levels of Font Lock::
* Faces for Font Lock::
* Syntactic Font Lock::
@end menu

@node Font Lock Basics
@c @subsection Font Lock Basics
@subsection $B%U%)%s%H%m%C%/!J(Bfont-lock$B!K$N4pK\(B

@c   There are several variables that control how Font Lock mode highlights
@c text.  But major modes should not set any of these variables directly.
@c Instead, it should set @code{font-lock-defaults} as a buffer-local
@c variable.  The value assigned to this variable is used, if and when Font
@c Lock mode is enabled, to set all the other variables.
$B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I$,%F%-%9%H$r6/D4I=<($9$kJ}K!$r(B
$B@)8f$9$kJQ?t$,$$$/$D$+$"$j$^$9!#(B
$B$7$+$7!"%a%8%c!<%b!<%I$G$3$l$i$NJQ?t$rD>@\$K@_Dj$9$k$Y$-$G$O$"$j$^$;$s!#(B
$B$=$N$+$o$j$K!"%P%C%U%!%m!<%+%k$J(B
$BJQ?t(B@code{font-lock-defaults}$B$K@_Dj$9$Y$-$G$9!#(B
$B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I$,%*%s$K$J$k$H!"(B
$B$3$NJQ?t$K@_Dj$5$l$?CM$r;H$C$FB>$N$9$Y$F$NJQ?t$K@_Dj$7$^$9!#(B

@defvar font-lock-defaults
@c This variable is set by major modes, as a buffer-local variable, to
@c specify how to fontify text in that mode.  The value should look like
@c this:
$B$3$NJQ?t$O%a%8%c!<%b!<%I$,%P%C%U%!%m!<%+%k$JJQ?t$H$7$F@_Dj$7!"(B
$BEv3:%b!<%I$K$*$$$F%F%-%9%H$r$I$N$h$&$KI=<($9$k$+$r;XDj$9$k!#(B
$BCM$O$D$.$N7A$G$"$k$3$H!#(B

@example
(@var{keywords} @var{keywords-only} @var{case-fold}
 @var{syntax-alist} @var{syntax-begin} @var{other-vars}@dots{})
@end example

@c The first element, @var{keywords}, indirectly specifies the value of
@c @code{font-lock-keywords}.  It can be a symbol, a variable whose value
@c is list to use for @code{font-lock-keywords}.  It can also be a list of
@c several such symbols, one for each possible level of fontification.  The
@c first symbol specifies how to do level 1 fontification, the second
@c symbol how to do level 2, and so on.
$B:G=i$NMWAG(B@var{keywords}$B$O!"(B
$B4V@\E*$K(B@code{font-lock-keywords}$B$NCM$r;XDj$9$k!#(B
$BMWAG(B@var{keywords}$B$,%7%s%\%k$G$"$k$H!"(B
$B$=$NJQ?t$H$7$F$NCM$,(B@code{font-lock-keywords}$B$K;H$o$l$k!#(B
$B$"$k$$$O!"MWAG(B@var{keywords}$B$,$=$N$h$&$J%7%s%\%k$N%j%9%H$G$"$k$H!"(B
$B3F%7%s%\%k$,(B1$B$D$N%l%Y%k$NI=<(J}K!$r;XDj$9$k!#(B
$B:G=i$N%7%s%\%k$O%l%Y%k(B1$B$NI=<(J}K!!"(B
2$BHVL\$N%7%s%\%k$O%l%Y%k(B2$B$NI=<(J}K!$H$$$C$?6q9g$G$"$k!#(B

@c The second element, @var{keywords-only}, specifies the value of the
@c variable @code{font-lock-keywords-only}.  If this is non-@code{nil},
@c syntactic fontification (of strings and comments) is not performed.
2$BHVL\$NMWAG(B@var{keywords-only}$B$O!"(B
$BJQ?t(B@code{font-lock-keywords-only}$B$NCM$r;XDj$9$k!#(B
$B$3$l$,(B@code{nil}$B0J30$G$"$k$H!JJ8;zNs$d%3%a%s%H$N!K9=J8$K$h$k=hM}$r9T$o$J$$!#(B

@c The third element, @var{case-fold}, specifies the value of
@c @code{font-lock-case-fold-search}.  If it is non-@code{nil}, Font Lock
@c mode ignores case when searching as directed by
@c @code{font-lock-keywords}.
3$BHVL\$NMWAG(B@var{case-fold}$B$O!"(B
@code{font-lock-case-fold-search}$B$NCM$r;XDj$9$k!#(B
$B$3$l$,(B@code{nil}$B0J30$G$"$k$H!"%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I$O(B
@code{font-lock-keywords}$B$G;XDj$5$l$?C5:w$G(B
$BBgJ8;z>.J8;z$r6hJL$7$J$$!#(B

@c If the fourth element, @var{syntax-alist}, is non-@code{nil}, it should be
@c a list of cons cells of the form @code{(@var{char-or-string}
@c . @var{string})}.  These are used to set up a syntax table for
@c fontification (@pxref{Syntax Table Functions}).  The resulting syntax
@c table is stored in @code{font-lock-syntax-table}.
4$BHVL\$NMWAG(B@var{syntax-alist}$B$,(B@code{nil}$B0J30$G$"$k>l9g!"(B
$B$=$l$O(B@code{(@var{char-or-string} . @var{string})}$B$N7A$N(B
$B%3%s%9%;%k$N%j%9%H$G$"$k$3$H!#(B
$B$3$l$i$OI=<(J}K!$rA*$V$?$a$N9=J8%F!<%V%k$N@_Dj$K;H$o$l$k(B
$B!J(B@pxref{Syntax Table Functions}$B!K!#(B
$BF@$i$l$?9=J8%F!<%V%k$O(B@code{font-lock-syntax-table}$B$KJ];}$5$l$k!#(B

@c The fifth element, @var{syntax-begin}, specifies the value of
@c @code{font-lock-beginning-of-syntax-function} (see below).
5$BHVL\$NMWAG(B@var{syntax-begin}$B$O!"(B
@code{font-lock-beginning-of-syntax-function}$B$NCM$r;XDj$9$k(B
$B!J2<5-;2>H!K!#(B

@c Any further elements @var{other-vars} are have form
@c @code{(@var{variable} . @var{value})}.  This kind of element means to
@c make @var{variable} buffer-local and then set it to @var{value}.  This
@c is used to set other variables that affect fontification.
@var{other-vars}$B0J9_$NMWAG$O!"(B
@code{(@var{variable} . @var{value})}$B$H$$$&7A$G$"$k!#(B
$B$3$N<o$NMWAG$O!"I=<(J}K!$NA*Br$K1F6A$9$k(B
$B$=$NB>$NJQ?t$K@_Dj$9$k$?$a$K;H$o$l$k!#(B
@end defvar

@node Search-based Fontification
@c @subsection Search-based Fontification
@subsection $BC5:w$K4p$E$/%U%)%s%HA*Br(B

@c   The most important variable for customizing Font Lock mode is
@c @code{font-lock-keywords}.  It specifies the search criteria for
@c search-based fontification.
$B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I$N%+%9%?%^%$%:$K$*$$$F(B
$B$b$C$H$b=EMW$JJQ?t$O(B@code{font-lock-keywords}$B$G$9!#(B
$BC5:w$K4p$E$/I=<(J}K!$NA*Br$K$*$1$kC5:w>r7o$r;XDj$7$^$9!#(B

@defvar font-lock-keywords
@c This variable's value is a list of the keywords to highlight.  Be
@c careful when composing regular expressions for this list; a poorly
@c written pattern can dramatically slow things down!
$B$3$NJQ?t$NCM$O!"6/D4I=<($9$k$Y$-%-!<%o!<%I$N%j%9%H$G$"$k!#(B
$B$3$N%j%9%H$K@55,I=8=$r=q$/>l9g$K$OCm0U$9$k$3$H!#(B
$BIO<e$J=q$-J}$r$7$?%Q%?!<%s$G$"$k$H!"F0:n$r7`E*$KCY$/$9$k!*(B
@end defvar

@c   Each element of @code{font-lock-keywords} specifies how to find
@c certain cases of text, and how to highlight those cases.  Font Lock mode
@c processes the elements of @code{font-lock-keywords} one by one, and for
@c each element, it finds and handles all matches.  Ordinarily, once
@c part of the text has been fontified already, this cannot be overridden
@c by a subsequent match in the same text; but you can specify different
@c behavior using the @var{override} element of a @var{highlighter}.
@code{font-lock-keywords}$B$N3FMWAG$O!"(B
$BFCDj$N%F%-%9%H$NC5$7J}$H(B
$BEv3:%F%-%9%H$r$I$N$h$&$K6/D4I=<($9$k$+;XDj$7$^$9!#(B
$B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I$O!"(B
@code{font-lock-keywords}$B$NMWAG$r(B1$B$D(B1$B$D=hM}$7!"(B
$B3FMWAG$K$*$$$F!"$=$l$K0lCW$9$k$b$N$9$Y$F$rC5$7$F=hM}$7$^$9!#(B
$BDL>o!"$9$G$KI=<(J}K!$rA*Br:Q$_$N%F%-%9%HItJ,$K$D$$$F$O!"(B
$B$=$l0J9_$NMWAG$K0lCW$7$F$bI=<(J}K!$rJQ$($^$;$s!#(B
$B$7$+$7!"(B@var{highlighter}$B$NMWAG(B@var{override}$B$r;H$C$F!"(B
$B0[$J$k$U$k$^$$$r;XDj$G$-$^$9!#(B

@c   Each element of @code{font-lock-keywords} should have one of these
@c forms:
@code{font-lock-keywords}$B$N3FMWAG$O$D$.$N$$$:$l$+$N7A$G$9!#(B

@table @code
@item @var{regexp}
@c Highlight all matches for @var{regexp} using
@c @code{font-lock-keyword-face}.  For example,
$B@55,I=8=(B@var{regexp}$B$K0lCW$7$?$b$N$O$9$Y$F(B
@code{font-lock-keyword-face}$B$r;H$C$F6/D4I=<($9$k!#(B

@example
@c ;; @r{Highlight discrete occurrences of @samp{foo}}
@c ;; @r{using @code{font-lock-keyword-face}.}
;; @r{$B8IN)$7$?(B@samp{foo}$B$N=P8=$O(B}
;; @r{@code{font-lock-keyword-face}$B$G6/D4I=<($9$k!#(B}
"\\<foo\\>"
@end example

@c The function @code{regexp-opt} (@pxref{Syntax of Regexps}) is useful for
@c calculating optimal regular expressions to match a number of different
@c keywords.
$B4X?t(B@code{regexp-opt}$B!J(B@pxref{Syntax of Regexps}$B!K$O!"(B
$B0[$J$kJ#?t8D$N%-!<%o!<%I$K0lCW$9$k:GE,$J@55,I=8=$r(B
$B7W;;$9$k$N$KM-MQ$G$"$k!#(B

@item @var{function}
@c Find text by calling @var{function}, and highlight the matches
@c it finds using @code{font-lock-keyword-face}.
$B4X?t(B@var{function}$B$r8F$S=P$7$F%F%-%9%H$rC5$7!"(B
$B$=$l$,C5$7=P$7$?$b$N$r(B@code{font-lock-keyword-face}$B$r;H$C$F6/D4I=<($9$k!#(B

@c When @var{function} is called, it receives one argument, the limit of
@c the search.  It should return non-@code{nil} if it succeeds, and set the
@c match data to describe the match that was found.
@var{function}$B$O!"C5:w8B3&$r0z?t$H$7$F8F$S=P$5$l$k!#(B
$B$_$D$+$l$P(B@code{nil}$B0J30$rJV$9$H$H$b$K(B
$B$_$D$1$?ItJ,$rI=$9%^%C%A%G!<%?$r@_Dj$9$k!#(B

@item (@var{matcher} . @var{match})
@c In this kind of element, @var{matcher} stands for either a regular
@c expression or a function, as described above.  The @sc{cdr},
@c @var{match}, specifies which subexpression of @var{matcher} should be
@c highlighted (instead of the entire text that @var{matcher} matched).
$B$3$N<o$NMWAG$G$O!"(B@var{matcher}$B$O!">e$K=R$Y$?@55,I=8=$+4X?t$rI=$9!#(B
@sc{cdr}$B$N(B@var{match}$B$O!"!J(B@var{matcher}$B$K0lCW$7$?ItJ,A4BN$N$+$o$j$K!K(B
$B6/D4I=<($9$Y$-(B@var{matcher}$B$NItJ,<0$r;XDj$9$k!#(B

@example
@c ;; @r{Highlight the @samp{bar} in each occurrences of @samp{fubar},}
@c ;; @r{using @code{font-lock-keyword-face}.}
;; @r{@samp{fubar}$B$N3F=P8=$N(B@samp{bar}$B$r(B}
;; @r{@code{font-lock-keyword-face}$B$G6/D4I=<((B}
("fu\\(bar\\)" . 1)
@end example

@c If you use @code{regexp-opt} to produce the regular expression
@c @var{matcher}, then you can use @code{regexp-opt-depth} (@pxref{Syntax
@c of Regexps}) to calculate the value for @var{match}.
$B@55,I=8=(B@var{matcher}$B$r:n$k$?$a$K(B@code{regexp-opt}$B$r;H$C$?>l9g!"(B
@var{match}$B$NCM$r7W;;$9$k$K$O(B
@code{regexp-opt-depth}$B!J(B@pxref{Syntax of Regexps}$B!K$r;H$($k!#(B

@item (@var{matcher} . @var{facename})
@c In this kind of element, @var{facename} is an expression whose value
@c specifies the face name to use for highlighting.
$B$3$N<o$NMWAG$G$O!"(B@var{facename}$B$O!"(B
$B6/D4I=<($K;H$&%U%'%$%9L>$r;XDj$9$kCM$rI=$9<0$G$"$k!#(B

@example
@c ;; @r{Highlight occurrences of @samp{fubar},}
@c ;; @r{using the face which is the value of @code{fubar-face}.}
;; @r{@samp{fubar}$B$N=P8=$O!"(B@code{fubar-face}$B$NCM$G(B}
;; @r{$BI=$5$l$?%U%'%$%9$r;H$C$F6/D4I=<((B}
("fubar" . fubar-face)
@end example

@item (@var{matcher} . @var{highlighter})
@c In this kind of element, @var{highlighter} is a list
@c which specifies how to highlight matches found by @var{matcher}.
@c It has the form
$B$3$N<o$NMWAG$G$O!"(B@var{highlighter}$B$O!"(B
@var{matcher}$B$K0lCW$7$?ItJ,$N6/D4I=<(J}K!$r;XDj$9$k%j%9%H$G$"$k!#(B
$B$D$.$N7A$G$"$k$3$H!#(B

@example
(@var{subexp} @var{facename} @var{override} @var{laxmatch})
@end example

@c The @sc{car}, @var{subexp}, is an integer specifying which subexpression
@c of the match to fontify (0 means the entire matching text).  The second
@c subelement, @var{facename}, specifies the face, as described above.
@sc{car}$B$N(B@var{subexp}$B$O!"(B
$B6/D4I=<($9$Y$-0lCWItJ,$NItJ,<0$r;XDj$9$k@0?t(B
$B!J(B0$B$O0lCWItJ,A4BN$r0UL#$9$k!K$G$"$k!#(B
2$BHVL\$NMWAG(B@var{facename}$B$O!">e$K=R$Y$?$h$&$K%U%'%$%9$r;XDj$9$k!#(B

@c The last two values in @var{highlighter}, @var{override} and
@c @var{laxmatch}, are flags.  If @var{override} is @code{t}, this element
@c can override existing fontification made by previous elements of
@c @code{font-lock-keywords}.  If it is @code{keep}, then each character is
@c fontified if it has not been fontified already by some other element.
@c If it is @code{prepend}, the face @var{facename} is added to the
@c beginning of the @code{face} property.  If it is @code{append}, the face
@c @var{facename} is added to the end of the @code{face} property.
@var{highlighter}$B$N:G8e$N(B2$B$D$NMWAG!"(B
@var{override}$B$H(B@var{laxmatch}$B$O%U%i%0$G$"$k!#(B
@var{override}$B$,(B@code{t}$B$G$"$k$H!"Ev3:MWAG$O!"(B
@code{font-lock-keywords}$B$N$^$($NMWAG$G7hDj:Q$_$N(B
$BI=<(J}K!$KM%@h$9$k$3$H$rI=$9!#(B
@code{keep}$B$G$"$k$H!"B>$NMWAG$G$OI=<(J}K!$,7hDj$7$F$$$J$$(B
$B3FJ8;z$NI=<(J}K!$rI=$9!#(B
@code{prepend}$B$G$"$k$H!"(B
$BB0@-(B@code{face}$B$N@hF,$K%U%'%$%9(B@var{facename}$B$rDI2C$9$k!#(B
@code{append}$B$G$"$k$H!"(B
$BB0@-(B@code{face}$B$NKvHx$K%U%'%$%9(B@var{facename}$B$rDI2C$9$k!#(B

@c If @var{laxmatch} is non-@code{nil}, it means there should be no error
@c if there is no subexpression numbered @var{subexp} in @var{matcher}.
@var{laxmatch}$B$,(B@code{nil}$B0J30$G$"$k$H!"(B
@var{matcher}$B$G0lCW$7$?$b$N$NCf$K(B@var{subexp}$BHVL\$NItJ,<0$,(B
$B$J$/$F$b%(%i!<$H$7$J$$$3$H$r0UL#$9$k!#(B

@c Here are some examples of elements of this kind, and what they do:
$B$3$N<o$NMWAG$H$=$NF0:n$NNc$r<($9!#(B

@smallexample
@c ;; @r{Highlight occurrences of either @samp{foo} or @samp{bar},}
@c ;; @r{using @code{foo-bar-face}, even if they have already been highlighted.}
@c ;; @r{@code{foo-bar-face} should be a variable whose value is a face.}
;; @r{@samp{foo}$B$d(B@samp{bar}$B$N=P8=$NI=<(J}K!$,$9$G$K7h$^$C$F$$$F$b(B}
;; @r{@code{foo-bar-face}$B$G6/D4I=<($9$k(B}
;; @r{@code{foo-bar-face}$B$NCM$O%U%'%$%9$G$"$k$3$H(B}
("foo\\|bar" 0 foo-bar-face t)

@c ;; @r{Highlight the first subexpression within each occurrences}
@c ;; @r{that the function @code{fubar-match} finds,}
@c ;; @r{using the face which is the value of @code{fubar-face}.}
;; @r{$B4X?t(B@code{fubar-match}$B$,$_$D$1$?3F=P8=Fb$N:G=i$NItJ,<0$r(B}
;; @r{@code{fubar-face}$B$NCM$,I=$9%U%'%$%9$G6/D4I=<($9$k(B}
(fubar-match 1 fubar-face)
@end smallexample

@item (@var{matcher} @var{highlighters}@dots{})
@c This sort of element specifies several @var{highlighter} lists for a
@c single @var{matcher}.  In order for this to be useful, each
@c @var{highlighter} should have a different value of @var{subexp}; that is,
@c each one should apply to a different subexpression of @var{matcher}.
$B$3$N<o$NMWAG$O!"(B1$B$D$N(B@var{matcher}$B$KBP$7$F(B
$BJ#?t$N%j%9%H(B@var{highlighter}$B$r;XDj$9$k!#(B
$B$3$l$,M-MQ$G$"$k$?$a$K$O!"(B
$B3F(B@var{highlighter}$B$G(B@var{subexp}$B$NCM$,0[$J$k$3$H!#(B
$B$D$^$j!"$=$l$>$l$r(B@var{matcher}$B$N0[$J$kItJ,<0$KE,MQ$G$-$k$3$H!#(B

@ignore
@item (@var{matcher} . @var{anchored})
In this kind of element, @var{anchored} acts much like a
@var{highlighter}, but it is more complex and can specify multiple
successive searches.

For highlighting single items, typically only @var{highlighter} is
required.  However, if an item or (typically) items are to be
highlighted following the instance of another item (the anchor) then
@var{anchored} may be required.

It has this format:

@example
(@var{submatcher} @var{pre-match-form} @var{post-match-form} @var{highlighters}@dots{})
@end example

@c I can't parse this text -- rms
where @var{submatcher} is much like @var{matcher}, with one
exception---see below.  @var{pre-match-form} and @var{post-match-form}
are evaluated before the first, and after the last, instance
@var{anchored}'s @var{submatcher} is used.  Therefore they can be used
to initialize before, and cleanup after, @var{submatcher} is used.
Typically, @var{pre-match-form} is used to move to some position
relative to the original @var{submatcher}, before starting with
@var{anchored}'s @var{submatcher}.  @var{post-match-form} might be used
to move, before resuming with @var{anchored}'s parent's @var{matcher}.

For example, an element of the form highlights (if not already highlighted):

@example
("\\<anchor\\>" (0 anchor-face) ("\\<item\\>" nil nil (0 item-face)))
@end example

Discrete occurrences of @samp{anchor} in the value of
@code{anchor-face}, and subsequent discrete occurrences of @samp{item}
(on the same line) in the value of @code{item-face}.  (Here
@var{pre-match-form} and @var{post-match-form} are @code{nil}.
Therefore @samp{item} is initially searched for starting from the end of
the match of @samp{anchor}, and searching for subsequent instance of
@samp{anchor} resumes from where searching for @samp{item} concluded.)

The above-mentioned exception is as follows.  The limit of the
@var{submatcher} search defaults to the end of the line after
@var{pre-match-form} is evaluated.  However, if @var{pre-match-form}
returns a position greater than the position after @var{pre-match-form}
is evaluated, that position is used as the limit of the search.  It is
generally a bad idea to return a position greater than the end of the
line; in other words, the @var{submatcher} search should not span lines.

@item (@var{matcher} @var{highlighters-or-anchoreds} ...)
@end ignore

@item (eval . @var{form})
@c Here @var{form} is an expression to be evaluated the first time
@c this value of @code{font-lock-keywords} is used in a buffer.
@c Its value should have one of the forms described in this table.
@var{form}$B$O!"%P%C%U%!$K$*$$$F(B@code{font-lock-keywords}$B$N$3$NCM$,(B
$B;O$a$F;H$o$l$?$H$-$KI>2A$9$Y$-<0$G$"$k!#(B
$B$=$NCM$O!"$3$NI=$K$"$2$?7A$N(B1$B$D$G$"$k$3$H!#(B
@end table

@c @strong{Warning:} Do not design an element of @code{font-lock-keywords}
@c to match text which spans lines; this does not work reliably.  While
@c @code{font-lock-fontify-buffer} handles multi-line patterns correctly,
@c updating when you edit the buffer does not, since it considers text one
@c line at a time.
@strong{$B7Y9p!'(B}@code{ }
@code{font-lock-keywords}$B$NMWAG$O!"(B
$B9T$r$^$?$,$C$F0lCW$9$k$h$&$K@_7W$7$J$$$3$H!#(B
$B$=$N$h$&$J=hM}$O?.Mj@-$,$J$$!#(B
@code{font-lock-fontify-buffer}$B$O!"9T$K$^$?$,$k%Q%?!<%s$r@5$7$/07$($k$,!"(B
$BFI<T$,%P%C%U%!$rJT=8$7$?$H$-$N99?7=hM}$G$O!"(B
$B0lEY$K(B1$B9T$:$D=hM}$9$k$?$a$K@5$7$/07$($J$$!#(B

@node Other Font Lock Variables
@c @subsection Other Font Lock Variables
@subsection $B$=$NB>$N%U%)%s%H%m%C%/JQ?t(B

@c   This section describes additional variables that a major mode
@c can set by means of @code{font-lock-defaults}.
$BK\@a$G$O!"(B@code{font-lock-defaults}$B$rMQ$$$F%a%8%c!<%b!<%I$G(B
$B@_Dj$G$-$kB>$NJQ?t$K$D$$$F=R$Y$^$9!#(B

@defvar font-lock-keywords-only
@c Non-@code{nil} means Font Lock should not fontify comments or strings
@c syntactically; it should only fontify based on
@c @code{font-lock-keywords}.
@code{nil}$B0J30$G$"$k$H!"%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I$O!"(B
$B9=J8$K4p$E$$$F%3%a%s%H$dJ8;zNs$r6/D4I=<($9$Y$-$G$J$$$3$H$r0UL#$9$k!#(B
@code{font-lock-keywords}$B$K4p$E$/6/D4I=<($N$_$r9T$&!#(B
@end defvar

@ignore
Other variables include those for buffer-specialized fontification functions,
`font-lock-fontify-buffer-function', `font-lock-unfontify-buffer-function',
`font-lock-fontify-region-function', `font-lock-unfontify-region-function',
`font-lock-inhibit-thing-lock' and `font-lock-maximum-size'.
@end ignore

@defvar font-lock-keywords-case-fold-search
@c Non-@code{nil} means that regular expression matching for the sake of
@c @code{font-lock-keywords} should be case-insensitive.
@code{nil}$B0J30$G$"$k$H!"(B@code{font-lock-keywords}$B$N(B
$B@55,I=8=C5:w$G$OBgJ8;z>.J8;z$r6hJL$7$J$$$3$H$r0UL#$9$k!#(B
@end defvar

@defvar font-lock-syntax-table
@c This variable specifies the syntax table to use for fontification of
@c comments and strings.
$B$3$NJQ?t$O!"%3%a%s%H$dJ8;zNs$NI=<(J}K!$KMQ$$$k(B
$B9=J8%F!<%V%k$r;XDj$9$k!#(B
@end defvar

@defvar font-lock-beginning-of-syntax-function
@c If this variable is non-@code{nil}, it should be a function to move
@c point back to a position that is syntactically at ``top level'' and
@c outside of strings or comments.  Font Lock uses this when necessary
@c to get the right results for syntactic fontification.
$B$3$NJQ?t$,(B@code{nil}$B0J30$G$"$k$H!"(B
$B%]%$%s%H$r9=J8>e$N!X%H%C%W%l%Y%k!Y$GJ8;zNs$d%3%a%s%H$N30B&$K(B
$B8eJ}0\F0$9$k4X?t$G$"$k$3$H!#(B
$B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I$O!"(B
$B9=J8$K4p$E$/=hM}$K$*$$$F@5$7$$7k2L$rF@$k$?$a$K(B
$BI,MW$K1~$8$F$3$N4X?t$r;H$&!#(B

@c This function is called with no arguments.  It should leave point at the
@c beginning of any enclosing syntactic block.  Typical values are
@c @code{beginning-of-line} (i.e., the start of the line is known to be
@c outside a syntactic block), or @code{beginning-of-defun} for programming
@c modes or @code{backward-paragraph} for textual modes (i.e., the
@c mode-dependent function is known to move outside a syntactic block).
$B4X?t$O0z?t$J$7$G8F$S=P$5$l$k!#(B
$B%]%$%s%H$r9=J8%V%m%C%/$N@hF,$KCV$/$3$H!#(B
$BE57?E*$JCM$O!"(B
@code{beginning-of-line}$B!J9TF,$O9=J8%V%m%C%/$N30B&$G$"$k!K!"(B
$B$"$k$$$O!"(B
$B%W%m%0%i%`8~$1$N%b!<%I$G$O(B@code{beginning-of-defun}$B!"(B
$B%F%-%9%H8~$1$N%b!<%I$G$O(B@code{backward-paragraph}
$B!J%b!<%I8GM-$N4X?t$O9=J8%V%m%C%/$N30B&$K%]%$%s%H$r0\F0$9$k!K$G$"$k!#(B

@c If the value is @code{nil}, the beginning of the buffer is used as a
@c position outside of a syntactic block.  This cannot be wrong, but it can
@c be slow.
$BCM$,(B@code{nil}$B$G$"$k$H!"%P%C%U%!$N@hF,$r9=J8%V%m%C%/$N30B&$N0LCV$H$7$F;H$&!#(B
$B$3$l$O8m$j$G$O$J$$$,!"F0:n$rCY$/$9$k!#(B
@end defvar

@defvar font-lock-mark-block-function
@c If this variable is non-@code{nil}, it should be a function that is
@c called with no arguments, to choose an enclosing range of text for
@c refontification for the command @kbd{M-g M-g}
@c (@code{font-lock-fontify-block}).
$B$3$NJQ?t$,(B@code{nil}$B0J30$G$"$k$H!"(B
$B%3%^%s%I(B@kbd{M-g M-g}$B!J(B@code{font-lock-fontify-block}$B!K$K$h$k(B
$B:FI=<($N$?$a$K%F%-%9%H$N3g$i$l$?HO0O$rA*$V$?$a$K(B
$B0z?t$J$7$G8F$P$l4X?t$G$"$k$3$H!#(B

@c The function should report its choice by placing the region around it.
@c A good choice is a range of text large enough to give proper results,
@c but not too large so that refontification becomes slow.  Typical values
@c are @code{mark-defun} for programming modes or @code{mark-paragraph} for
@c textual modes.
$B4X?t$O!"A*$s$@HO0O$K%j!<%8%g%s$r@_Dj$9$k$3$H!#(B
$B@5$7$$7k2L$rF@$i$l$k$h$&$KBg$-$a$N%F%-%9%HHO0O$rA*$V$N$,$h$$$,!"(B
$B:FI=<(=hM}$,CY$/$J$i$J$$$h$&$KBg$-$9$.$J$$$3$H!#(B
$BE57?E*$JCM$O!"%W%m%0%i%`8~$1%b!<%I$G$O(B@code{mark-defun}$B!"(B
$B%F%-%9%H8~$1%b!<%I$G$O(B@code{mark-paragraph}$B$G$"$k!#(B
@end defvar

@node Levels of Font Lock
@c @subsection Levels of Font Lock
@subsection $B%U%)%s%H%m%C%/$N%l%Y%k(B

@c   Many major modes offer three different levels of fontification.  You
@c can define multiple levels by using a list of symbols for @var{keywords}
@c in @code{font-lock-defaults}.  Each symbol specifies one level of
@c fontification; it is up to the user to choose one of these levels.  The
@c chosen level's symbol value is used to initialize
@c @code{font-lock-keywords}.
$BB?$/$N%a%8%c!<%b!<%I$G$O!"(B3$BCJ3,$NI=<(J}K!$rDs6!$7$^$9!#(B
@code{font-lock-defaults}$B$N(B@var{keywords}$B$K(B
$B%7%s%\%k$N%j%9%H$r;H$C$FJ#?t%l%Y%k$rDj5A$G$-$^$9!#(B
$B3F%7%s%\%k$O(B1$B$D$N%l%Y%k$NI=<(J}K!$r;XDj$7$^$9!#(B
$B$I$N%l%Y%k$rA*$V$+$O%f!<%6!<$N@UG$$G$9!#(B
$B;XDj$7$?%l%Y%k$N%7%s%\%k$NCM$O(B@code{font-lock-keywords}$B$N=i4|2=$K;H$o$l$^$9!#(B

@c   Here are the conventions for how to define the levels of
@c fontification:
$BI=<(J}K!$N%l%Y%k$rDj5A$9$k:]$N47=,$r$"$2$F$*$-$^$9!#(B

@itemize @bullet
@item
@c Level 1: highlight function declarations, file directives (such as include or
@c import directives), strings and comments.  The idea is speed, so only
@c the most important and top-level components are fontified.
$B%l%Y%k(B1$B!'(B@code{ }
$B4X?t@k8@!"!J(Binclude$B$d(Bimport$B$J$I$N!K%U%!%$%k;XDj!"J8;zNs!"(B
$B%3%a%s%H$r6/D4I=<($9$k!#(B
$BB.$5$,4N?4$G$"$j!"=EMW$J9=J8$d%H%C%W%l%Y%k$N9=@.MWAG$N$_$r6/D4I=<($9$k!#(B

@item
@c Level 2: in addition to level 1, highlight all language keywords,
@c including type names that act like keywords, as well as named constant
@c values.  The idea is that all keywords (either syntactic or semantic)
@c should be fontified appropriately.
$B%l%Y%k(B2$B!'(B@code{ }
$B%l%Y%k(B1$B$K2C$($F!"%-!<%o!<%I$N$h$&$K$U$k$^$&7?L>$r4^$`(B
$BEv3:8@8l$N$9$Y$F$N%-!<%o!<%I!"L>A0IU$-Dj?t!#(B
$B!J9=J8E*$J!"$"$k$$$O!"0UL#E*$J!K$9$Y$F$N%-!<%o!<%I$r(B
$BE,@Z$K6/D4I=<($9$k$N$,L\E*!#(B

@item
@c Level 3: in addition to level 2, highlight the symbols being defined in
@c function and variable declarations, and all builtin function names,
@c wherever they appear.
$B%l%Y%k(B3$B!'(B@code{ }
$B%l%Y%k(B2$B$K2C$($F!"(B
$B4X?t$dJQ?t@k8@$GDj5A$5$l$?%7%s%\%k!"E,@Z$J$9$Y$F$NAH$_9~$_4X?t$NL>A0!#(B
@end itemize

@node Faces for Font Lock
@c @subsection Faces for Font Lock
@subsection $B%U%)%s%H%m%C%/$N%U%'%$%9(B

@c   You can make Font Lock mode use any face, but several faces are
@c defined specifically for Font Lock mode.  Each of these symbols is both
@c a face name, and a variable whose default value is the symbol itself.
@c Thus, the default value of @code{font-lock-comment-face} is
@c @code{font-lock-comment-face}.  This means you can write
@c @code{font-lock-comment-face} in a context such as
@c @code{font-lock-keywords} where a face-name-valued expression is used.
$B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I$G$OG$0U$N%U%'%$%9$r;H$($^$9$,!"(B
$B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I8~$1$KFCJL$KDj5A$5$?%U%'%$%9$,$"$j$^$9!#(B
$B$3$l$i$N%7%s%\%k$N$*$N$*$N$O!"%U%'%$%9L>$G$b$"$j!"(B
$B%7%s%\%k<+?H$r%G%U%)%k%HCM$H$9$kJQ?t$G$b$"$j$^$9!#(B
$B$D$^$j!"(B@code{font-lock-comment-face}$B$N%G%U%)%k%HCM$O!"(B
@code{font-lock-comment-face}$B$G$9!#(B
$B$3$l$O!"(B
$B%U%'%$%9L>$rCM$K;}$D$h$&$J<0$r=q$/(B@code{font-lock-keywords}$B$J$I$N>lLL$G!"(B
@code{font-lock-comment-face}$B$H=q$1$k$3$H$r0UL#$7$^$9!#(B

@table @code
@item font-lock-comment-face
@vindex font-lock-comment-face
@c Used (typically) for comments.
$B!JE57?E*$K$O!K%3%a%s%H$K;H$o$l$k!#(B

@item font-lock-string-face
@vindex font-lock-string-face
@c Used (typically) for string constants.
$B!JE57?E*$K$O!KJ8;zNs$K;H$o$l$k!#(B

@item font-lock-keyword-face
@vindex font-lock-keyword-face
@c Used (typically) for keywords---names that have special syntactic
@c significance, like @code{for} and @code{if} in C.
$B!JE57?E*$K$O!K%-!<%o!<%I!"$D$^$j!"(B
C$B$N(B@code{for}$B$d(B@code{if}$B$N$h$&$K9=J8E*$K=EMW$JL>A0$K;H$o$l$k!#(B

@item font-lock-builtin-face
@vindex font-lock-builtin-face
@c Used (typically) for built-in function names.
$B!JE57?E*$K$O!KAH$_9~$_4X?t$NL>A0$K;H$o$l$k!#(B

@item font-lock-function-name-face
@vindex font-lock-function-name-face
@c Used (typically) for the name of a function being defined or declared,
@c in a function definition or declaration. 
$B!JE57?E*$K$O!K4X?tDj5A!?@k8@Fb$K$*$$$F!"(B
$BDj5A!?@k8@$5$l$F$$$k4X?t$NL>A0$K;H$o$l$k!#(B

@item font-lock-variable-name-face
@vindex font-lock-variable-name-face
@c Used (typically) for the name of a variable being defined or declared,
@c in a variable definition or declaration.
$B!JE57?E*$K$O!KJQ?tDj5A!?@k8@Fb$K$*$$$F!"(B
$BDj5A!?@k8@$5$l$F$$$kJQ?t$NL>A0$K;H$o$l$k!#(B

@item font-lock-type-face
@vindex font-lock-type-face
@c Used (typically) for names of user-defined data types,
@c where they are defined and where they are used.
$B!JE57?E*$K$O!K%f!<%6!<Dj5A$N%G!<%?7?$NL>A0$,Dj5A!?;2>H$5$l$k>l=j$K$*$$$F!"(B
$B$=$l$i$NL>A0$K;H$o$l$k!#(B

@item font-lock-constant-face
@vindex font-lock-constant-face
@c Used (typically) for constant names.
$B!JE57?E*$K$O!KDj?t$NL>A0$K;H$o$l$k!#(B

@item font-lock-warning-face
@vindex font-lock-warning-face
@c Used (typically) for constructs that are peculiar, or that greatly
@c change the meaning of other text.  For example, this is used for
@c @samp{;;;###autoload} cookies in Emacs Lisp, and for @code{#error}
@c directives in C.
$B!JE57?E*$K$O!KFHFC$J9=J8$dJL$N%F%-%9%H$N0UL#$rBg$-$/JQ$($k$h$&$J$b$N$K(B
$B;H$o$l$k!#(B
$B$?$H$($P!"(BEmacs Lisp$B$N(B@samp{;;;###autoload}$B$d(B
C$B$N(B@code{#error}$B;XDj$K;H$o$l$k!#(B
@end table

@node Syntactic Font Lock
@c @subsection Syntactic Font Lock
@subsection $B9=J8E*$J%U%)%s%H%m%C%/(B

@c   Font Lock mode can be used to update @code{syntax-table} properties
@c automatically.  This is useful in languages for which a single syntax
@c table by itself is not sufficient.
$B%U%)%s%H%m%C%/!J(Bfont-lock$B!K%b!<%I$O!"(B
$BB0@-(B@code{syntax-table}$B$r<+F099?7$9$k$?$a$K$b;H$($^$9!#(B
1$B$D$N9=J8%F!<%V%k$@$1$G$O==J,$G$J$$$h$&$J8@8l$K$*$$$FM-MQ$G$9!#(B

@defvar font-lock-syntactic-keywords
@c This variable enables and controls syntactic Font Lock.  Its value
@c should be a list of elements of this form:
$B$3$NJQ?t$O9=J8E*$J%U%)%s%H%m%C%/$r%*%s$K$7@)8f$9$k!#(B
$B$=$NCM$O$D$.$N7A$NMWAG$+$i$J$k%j%9%H$G$"$k$3$H!#(B

@example
(@var{matcher} @var{subexp} @var{syntax} @var{override} @var{laxmatch})
@end example

@c The parts of this element have the same meanings as in the corresponding
@c sort of element of @code{font-lock-keywords},
$B$3$NMWAG$N3FItJ,$K$O!"$D$.$N(B@code{font-lock-keywords}$B$NBP1~$9$k<oN`$NMWAG$H(B
$BF1$80UL#$,$"$k!#(B

@example
(@var{matcher} @var{subexp} @var{facename} @var{override} @var{laxmatch})
@end example

@c However, instead of specifying the value @var{facename} to use for the
@c @code{face} property, it specifies the value @var{syntax} to use for the
@c @code{syntax-table} property.  Here, @var{syntax} can be a variable
@c whose value is a syntax table, a syntax entry of the form
@c @code{(@var{syntax-code} . @var{matching-char})}, or an expression whose
@c value is one of those two types.
$B$7$+$7!"B0@-(B@code{face}$B$K;H$&CM(B@var{facename}$B$r;XDj$9$k$+$o$j$K!"(B
$BB0@-(B@code{syntax-table}$B$K;H$&CM(B@var{syntax}$B$r;XDj$9$k!#(B
$B$3$3$G!"(B@var{syntax}$B$O!"9=J8%F!<%V%k$rCM$H$9$kJQ?t!"(B
@code{(@var{syntax-code} . @var{matching-char})}$B$N7A$N9=J8%F!<%V%k$N9`L\!"(B
$B$"$k$$$O!"$3$N(B2$B<oN`$N$I$A$i$+$rCM$H$9$k<0$G$"$k!#(B
@end defvar

@node Hooks
@c @section Hooks
@section $B%U%C%/(B
@c @cindex hooks
@cindex $B%U%C%/(B

@c   A @dfn{hook} is a variable where you can store a function or functions
@c to be called on a particular occasion by an existing program.  Emacs
@c provides hooks for the sake of customization.  Most often, hooks are set
@c up in the @file{.emacs} file, but Lisp programs can set them also.
@c @xref{Standard Hooks}, for a list of standard hook variables.
@dfn{$B%U%C%/(B}$B!J(Bhook$B!K$H$O!"4{B8$N%W%m%0%i%`$+$iFCDj$N>lLL$G(B
$B8F$S=P$5$l$k!J(B1$B$D$+0lO"$N!K4X?t$r<}$a$?JQ?t$G$9!#(B
Emacs$B$O!"%+%9%?%^%$%:$N$?$a$K%U%C%/$rMQ0U$7$F$$$^$9!#(B
$B$[$H$s$I$N>l9g!"%U%C%/$O%U%!%$%k(B@file{.emacs}$B$G@_Dj$7$^$9$,!"(B
Lisp$B%W%m%0%i%`$,9T$C$F$b$+$^$$$^$;$s!#(B
$BI8=`$N%U%C%/4X?t0lMw$K$D$$$F$O!"(B@xref{Standard Hooks}$B!#(B

@c @cindex normal hook
@cindex $B%N!<%^%k%U%C%/(B
@c   Most of the hooks in Emacs are @dfn{normal hooks}.  These variables
@c contain lists of functions to be called with no arguments.  When the
@c hook name ends in @samp{-hook}, that tells you it is normal.  We try to
@c make all hooks normal, as much as possible, so that you can use them in
@c a uniform way.
Emacs$B$NB?$/$N%U%C%/$O(B@dfn{$B%N!<%^%k%U%C%/(B}$B!J(Bnormal hook$B!K$G$9!#(B
$B$3$l$i$NJQ?t$O!"0z?t$J$7$G8F$S=P$5$l$k4X?t$N%j%9%H$rJ];}$7$F$$$^$9!#(B
$B%U%C%/L>$,(B@samp{-hook}$B$G=*$C$F$$$k$H!"%N!<%^%k%U%C%/$r0UL#$7$^$9!#(B
$BFI<T$,$=$l$i$rC10l$NJ}K!$G;H$($k$h$&$K!"(B
$B2DG=$J8B$j%N!<%^%k%U%C%/$K$9$k$h$&$K?43]$1$F$$$^$9!#(B

@c   Every major mode function is supposed to run a normal hook called the
@c @dfn{mode hook} as the last step of initialization.  This makes it easy
@c for a user to customize the behavior of the mode, by overriding the
@c buffer-local variable assignments already made by the mode.  But hooks
@c are used in other contexts too.  For example, the hook
@c @code{suspend-hook} runs just before Emacs suspends itself
@c (@pxref{Suspending Emacs}).
$B3F%a%8%c!<%b!<%I4X?t$O!"(B
$B$=$N=i4|2=$N:G=*CJ3,$G(B@dfn{$B%b!<%I%U%C%/(B}$B!J(Bmode hook$B!K$H8F$P$l$k(B
$B%N!<%^%k%U%C%/$r<B9T$9$k$H4|BT$5$l$^$9!#(B
$B$3$l$K$h$j!"%b!<%I$,$9$G$K@_Dj$7$?%P%C%U%!%m!<%+%k$JJQ?t$r>e=q$-$9$k$3$H$G!"(B
$B%f!<%6!<$,%b!<%I$N$U$k$^$$$r%+%9%?%^%$%:$7$d$9$/$7$F$$$^$9!#(B
$B$7$+$7!"%U%C%/$OJL$N>lLL$G$b;H$o$l$F$$$^$9!#(B
$B$?$H$($P!"%U%C%/(B@code{suspend-hook}$B$O!"(B
Emacs$B$,<+?H$r0l;~5Y;_$9$kD>A0$K<B9T$5$l$^$9!#(B
$B!J(B@pxref{Suspending Emacs}$B!K!#(B

@c   The recommended way to add a hook function to a normal hook is by
@c calling @code{add-hook} (see below).  The hook functions may be any of
@c the valid kinds of functions that @code{funcall} accepts (@pxref{What Is
@c a Function}).  Most normal hook variables are initially void;
@c @code{add-hook} knows how to deal with this.
$B%N!<%^%k%U%C%/$K%U%C%/4X?t$rDI2C$9$k?d>)J}K!$O!"(B
@code{add-hook}$B!J2<5-;2>H!K$r8F$V$3$H$G$9!#(B
$B%U%C%/4X?t$O!"(B@code{funcall}$B!J(B@pxref{What Is a Function}$B!K$,(B
$B<u$1IU$1$k$J$i$P$I$s$J<oN`$N4X?t$G$b$+$^$$$^$;$s!#(B
$B$[$H$s$I$N%N!<%^%k%U%C%/JQ?t$O:G=i$O6u$G$9$,!"(B
@code{add-hook}$B$O$=$N07$$J}$rCN$C$F$$$^$9!#(B

@c @cindex abnormal hook
@cindex $B%"%V%N!<%^%k%U%C%/(B
@c   If the hook variable's name does not end with @samp{-hook}, that
@c indicates it is probably an @dfn{abnormal hook}; you should look at its
@c documentation to see how to use the hook properly.
$B%U%C%/JQ?t$NL>A0$,(B@samp{-hook}$B$G=*$i$J$$>l9g!"(B
$B$=$l$,(B@dfn{$B%"%V%N!<%^%k%U%C%/(B}$B!J(Babnormal hook$B!K$G$"$k$3$H$rI=$7$^$9!#(B
$BFI<T$O!"$=$N$h$&$J%U%C%/$N@5$7$$;H$$J}$r@bL@=q$GD4$Y$k$Y$-$G$9!#(B

@c   If the variable's name ends in @samp{-functions} or @samp{-hooks},
@c then the value is a list of functions, but it is abnormal in that either
@c these functions are called with arguments or their values are used in
@c some way.  You can use @code{add-hook} to add a function to the list,
@c but you must take care in writing the function.  (A few of these
@c variables are actually normal hooks which were named before we
@c established the convention of using @samp{-hook} for them.)
$BJQ?tL>$,(B@samp{-functions}$B$d(B@samp{-hooks}$B$G=*$C$F$$$k$H!"(B
$B$=$NCM$O4X?t$N%j%9%H$G$9$,!"(B
$B$=$l$i$N4X?t$r0z?t$"$j$G8F$S=P$7$?$j!"(B
$B4X?t$NLa$jCM$r$I$3$+$G;H$&$H$$$&0UL#$G%"%V%N!<%^%k!J0[>o!K$J$N$G$9!#(B
$B%j%9%H$K4X?t$rDI2C$9$k$K$O(B@code{add-hook}$B$r;H$($^$9$,!"(B
$B4X?t$r=q$/$H$-$K$OCm0U$9$kI,MW$,$"$j$^$9!#(B
$B!J$3$l$i$NJQ?t$N$&$A!"<B:]$K$O%N!<%^%k%U%C%/$G$"$k$b$N$b$"$k!#(B
$B%N!<%^%k%U%C%/$K$O(B@samp{-hook}$B$r;H$&$H$$$&47=,$r(B
$B3NN)$9$k$^$($KL?L>$7$?$b$N$G$"$k!#!K(B

@c   If the variable's name ends in @samp{-function}, then its value
@c is just a single function, not a list of functions.
$BJQ?tL>$,(B@samp{-function}$B$G=*$C$F$$$k$H!"(B
$B$=$NCM$O!"4X?t$N%j%9%H$G$O$J$/!"(B1$B$D$N4X?t$G$9!#(B

@c   Here's an example that uses a mode hook to turn on Auto Fill mode when
@c in Lisp Interaction mode:
lisp$BBPOC%b!<%I$G<+F05M$a9~$_!J(Bauto-fill$B!K%b!<%I$r%*%s$K$9$k$?$a$K(B
$B%b!<%I%U%C%/$r;H$C$?Nc$r<($7$^$9!#(B

@example
(add-hook 'lisp-interaction-mode-hook 'turn-on-auto-fill)
@end example

@c   At the appropriate time, Emacs uses the @code{run-hooks} function to
@c run particular hooks.  This function calls the hook functions that have
@c been added with @code{add-hook}.
$BE,Ev$J;~4|$K!"(BEmacs$B$O4X?t(B@code{run-hooks}$B$r;H$C$F(B
$BFCDj$N%U%C%/$r<B9T$7$^$9!#(B
$B$3$N4X?t$O!"(B@code{add-hook}$B$GDI2C$5$l$?%U%C%/4X?t$r8F$S=P$7$^$9!#(B

@defun run-hooks &rest hookvar
@c This function takes one or more hook variable names as arguments, and
@c runs each hook in turn.  Each @var{hookvar} argument should be a symbol
@c that is a hook variable.  These arguments are processed in the order
@c specified.
$B$3$N4X?t$OJ#?t8D$N%U%C%/JQ?tL>$r0z?t$K$H$j!"3F%U%C%/$r=g$K<B9T$9$k!#(B
$B3F0z?t(B@var{hookvar}$B$O!"%U%C%/JQ?t$N%7%s%\%k$G$"$k$3$H!#(B
$B$3$l$i$N0z?t$O!";XDj$5$l$?=g$K=hM}$5$l$k!#(B

@c If a hook variable has a non-@code{nil} value, that value may be a
@c function or a list of functions.  If the value is a function (either a
@c lambda expression or a symbol with a function definition), it is called.
@c If it is a list, the elements are called, in order.  The hook functions
@c are called with no arguments.  Nowadays, storing a single function in
@c the hook variable is semi-obsolete; you should always use a list of
@c functions.
$B%U%C%/JQ?t$,(B@code{nil}$B0J30$NCM$G$"$k$H!"(B
$B$=$NCM$O!"4X?t$+4X?t$N%j%9%H$G$"$k!#(B
$BCM$,4X?t!J%i%`%@<0$d4X?tDj5A$r;}$D%7%s%\%k!K$G$"$k$H!"$=$l$r8F$S=P$9!#(B
$BCM$,%j%9%H$G$"$k$H!"=gHV$K$=$NMWAG$r8F$S=P$9!#(B
$B%U%C%/4X?t$O!"0z?t$J$7$G8F$S=P$5$l$k!#(B
$B8=:_!"%U%C%/JQ?t$K(B1$B$D$N4X?t$rF~$l$k$3$H$OGQ$l$+$1$F$$$k!#(B
$B$D$M$K4X?t$N%j%9%H$r;H$&$Y$-$G$"$k!#(B

@c For example, here's how @code{emacs-lisp-mode} runs its mode hook:
$BNc$H$7$F!"(B@code{emacs-lisp-mode}$B$,$=$N%b!<%I%U%C%/$r$I$N$h$&$K(B
$B<B9T$9$k$+$r<($9!#(B

@example
(run-hooks 'emacs-lisp-mode-hook)
@end example
@end defun

@defun run-hook-with-args hook &rest args
@c This function is the way to run an abnormal hook which passes arguments
@c to the hook functions.  It calls each of the hook functions, passing
@c each of them the arguments @var{args}.
$B$3$N4X?t$O!"%U%C%/4X?t$K0z?t$rEO$9%"%V%N!<%^%k%U%C%/$r<B9T$9$kJ}K!$G$"$k!#(B
$B3F%U%C%/4X?t$K0z?t(B@var{args}$B$rEO$7$F8F$S=P$9!#(B
@end defun

@defun run-hook-with-args-until-failure hook &rest args
@c This function is the way to run an abnormal hook which passes arguments
@c to the hook functions, and stops as soon as any hook function fails.  It
@c calls each of the hook functions, passing each of them the arguments
@c @var{args}, until some hook function returns @code{nil}.  Then it stops,
@c and returns @code{nil} if some hook function did, and otherwise
@c returns a non-@code{nil} value.
$B$3$N4X?t$O!"%U%C%/4X?t$K0z?t$rEO$9%"%V%N!<%^%k%U%C%/$r<B9T$9$k$,!"(B
$B%U%C%/4X?t$,<:GT$9$k$H$?$@$A$K;_$a$kJ}K!$G$"$k!#(B
$B%U%C%/4X?t$,(B@code{nil}$B$rJV$9$^$G!"(B
$B3F%U%C%/4X?t$K0z?t(B@var{args}$B$rEO$7$F8F$S=P$9!#(B
@code{nil}$B$,JV$C$F$/$k$H(B@code{nil}$B$GLa$k!#(B
$B$5$b$J$1$l$P!"(B@code{nil}$B0J30$NCM$rJV$9!#(B
@end defun

@defun run-hook-with-args-until-success hook &rest args
@c This function is the way to run an abnormal hook which passes arguments
@c to the hook functions, and stops as soon as any hook function succeeds.
@c It calls each of the hook functions, passing each of them the arguments
@c @var{args}, until some hook function returns non-@code{nil}.  Then it
@c stops, and returns whatever was returned by the last hook function
@c that was called.
$B$3$N4X?t$O!"%U%C%/4X?t$K0z?t$rEO$9%"%V%N!<%^%k%U%C%/$r<B9T$9$k$,!"(B
$B%U%C%/4X?t$,@.8y$9$k$H$?$@$A$K;_$a$kJ}K!$G$"$k!#(B
$B%U%C%/4X?t$,(B@code{nil}$B0J30$rJV$9$^$G!"(B
$B3F%U%C%/4X?t$K0z?t(B@var{args}$B$rEO$7$F8F$S=P$9!#(B
@code{nil}$B0J30$,JV$C$F$/$k$H(B
$B:G8e$K8F$S=P$7$?%U%C%/4X?t$NLa$jCM$rJV$9!#(B
@end defun

@defun add-hook hook function &optional append local
@c This function is the handy way to add function @var{function} to hook
@c variable @var{hook}.  The argument @var{function} may be any valid Lisp
@c function with the proper number of arguments.  For example,
$B$3$N4X?t$O%U%C%/JQ?t(B@var{hook}$B$K4X?t(B@var{function}$B$rDI2C$9$k(B
$B<j7Z$JJ}K!$G$"$k!#(B
$B0z?t(B@var{function}$B$O!"@5$7$$8D?t$N0z?t$r$H$kG$0U$N@5$7$$(BLisp$B4X?t$G$"$k$3$H!#(B
$B$?$H$($P!"(B

@example
(add-hook 'text-mode-hook 'my-text-hook-function)
@end example

@noindent
@c adds @code{my-text-hook-function} to the hook called @code{text-mode-hook}.
$B$O!"(B@code{text-mode-hook}$B$H$$$&%U%C%/$K(B
@code{my-text-hook-function}$B$rDI2C$9$k!#(B

@c You can use @code{add-hook} for abnormal hooks as well as for normal
@c hooks.
@code{add-hook}$B$O!"%N!<%^%k%U%C%/$K2C$($F%"%V%N!<%^%k%U%C%/$K$b;H$($k!#(B

@c It is best to design your hook functions so that the order in which they
@c are executed does not matter.  Any dependence on the order is ``asking
@c for trouble.''  However, the order is predictable: normally,
@c @var{function} goes at the front of the hook list, so it will be
@c executed first (barring another @code{add-hook} call).  If the optional
@c argument @var{append} is non-@code{nil}, the new hook function goes at
@c the end of the hook list and will be executed last.
$B%U%C%/4X?t$O<B9T=g=x$K0MB8$7$J$$$h$&$K@_7W$9$k$N$,:GNI$G$"$k!#(B
$B<B9T=g=x$K0MB8$9$k$H!X%H%i%V%k$r8F$S9~$`!Y$h$&$J$b$N$G$"$k!#(B
$B$7$+$7!"=g=x$OM=B,$G$-$k!#(B
$BDL>o!"(B@var{function}$B$O%U%C%/%j%9%H$N@hF,$KCV$+$l$k$N$G!"(B
$B!J$[$+$K(B@code{add-hook}$B$N8F$S=P$7$,$J$1$l$P!K:G=i$K<B9T$5$l$k!#(B
$B>JN,2DG=$J0z?t(B@var{append}$B$,(B@code{nil}$B0J30$G$"$k$H!"(B
$B?7$?$J%U%C%/4X?t$O%U%C%/%j%9%H$NKvHx$KCV$+$l!"(B
$B:G8e$K<B9T$5$l$k!#(B

@c If @var{local} is non-@code{nil}, that says to make the new hook
@c function buffer-local in the current buffer.  Before you can do this, you must
@c make the hook itself buffer-local by calling @code{make-local-hook}
@c (@strong{not} @code{make-local-variable}).  If the hook itself is not
@c buffer-local, then the value of @var{local} makes no difference---the
@c hook function is always global.
@var{local}$B$,(B@code{nil}$B0J30$G$"$k$H!"(B
$B?7$?$J%U%C%/4X?t$r%+%l%s%H%P%C%U%!$K%P%C%U%!%m!<%+%k$K$9$k$3$H$r0UL#$9$k!#(B
$B$3$l$r9T$&$^$($K!"!J(B@code{make-local-variable}@strong{$B$G$O$J$/(B}$B!K(B
@code{make-local-hook}$B$r8F$s$G(B
$B%U%C%/<+?H$r%P%C%U%!%m!<%+%k$K$7$F$*$/I,MW$,$"$k!#(B
$B%U%C%/<+?H$,%P%C%U%!%m!<%+%k$G$J$$$H!"(B@var{local}$B$NCM$O0UL#$r;}$?$J$$!#(B
$B%U%C%/4X?t$O$D$M$K%0%m!<%P%k$G$"$k!#(B
@end defun

@defun remove-hook hook function &optional local
@c This function removes @var{function} from the hook variable @var{hook}.
$B$3$N4X?t$O!"%U%C%/JQ?t(B@var{hook}$B$+$i(B@var{function}$B$r<h$j=|$/!#(B

@c If @var{local} is non-@code{nil}, that says to remove @var{function}
@c from the buffer-local hook list instead of from the global hook list.
@c If the hook variable itself is not buffer-local, then the value of
@c @var{local} makes no difference.
@var{local}$B$,(B@code{nil}$B0J30$G$"$k$H!"(B
$B%0%m!<%P%k$J%U%C%/%j%9%H$G$O$J$/%P%C%U%!%m!<%+%k$J%U%C%/%j%9%H$+$i(B
@var{function}$B$r:o=|$9$k$3$H$r;XDj$9$k!#(B
$B%U%C%/JQ?t<+?H$,%P%C%U%!%m!<%+%k$G$J$$$H!"(B@var{local}$B$NCM$O0UL#$r;}$?$J$$!#(B
@end defun

@defun make-local-hook hook
@c This function makes the hook variable @code{hook} buffer-local in the
@c current buffer.  When a hook variable is buffer-local, it can have
@c buffer-local and global hook functions, and @code{run-hooks} runs all of
@c them.
$B$3$N4X?t$O!"%U%C%/JQ?t(B@code{hook}$B$r%+%l%s%H%P%C%U%!$K%P%C%U%!%m!<%+%k$K$9$k!#(B
$B%U%C%/JQ?t$,%P%C%U%!%m!<%+%k$G$"$k$H!"(B
$B%P%C%U%!%m!<%+%k$J%U%C%/4X?t$H%0%m!<%P%k$J%U%C%/4X?t$r;}$D$3$H$,$G$-!"(B
@code{run-hooks}$B$O$=$l$i$9$Y$F$r<B9T$9$k!#(B

@c This function works by making @code{t} an element of the buffer-local
@c value.  That serves as a flag to use the hook functions in the default
@c value of the hook variable as well as those in the buffer-local value.
@c Since @code{run-hooks} understands this flag, @code{make-local-hook}
@c works with all normal hooks.  It works for only some non-normal
@c hooks---those whose callers have been updated to understand this meaning
@c of @code{t}.
$B$3$N4X?t$O!"%P%C%U%!%m!<%+%k$JCM$NMWAG$r(B@code{t}$B$K$9$k$3$H$GF0:n$9$k!#(B
$B$3$l$O!"%P%C%U%!%m!<%+%k$JCM$K2C$($F%U%C%/JQ?t$N%G%U%)%k%HCM$K$"$k(B
$B%U%C%/4X?t$r;H$&$3$H$rI=$9%U%i%0$G$"$k!#(B
@code{run-hooks}$B$O$3$N%U%i%0$rM}2r$7!"(B
@code{make-local-hook}$B$O$9$Y$F$N%N!<%^%k%U%C%/$r=hM}$G$-$k!#(B
$B%"%V%N!<%^%k%U%C%/$K4X$7$F$O!"(B
@code{t}$B$N0UL#$rM}2r$9$k$h$&$K99?7$7$?$b$N$@$1$,=hM}$G$-$k!#(B

@c Do not use @code{make-local-variable} directly for hook variables; it is
@c not sufficient.
$B%U%C%/JQ?t$KBP$7$F(B@code{make-local-variable}$B$rD>@\;H$o$J$$$3$H!#(B
$B$=$l$@$1$G$OIT==J,$G$"$k!#(B
@end defun