1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506
|
\input texinfo @c -*- texinfo -*-
@c %**start of header
@setfilename racket-mode.info
@settitle Racket Mode
@documentencoding UTF-8
@documentlanguage en
@syncodeindex pg cp
@c %**end of header
@copying
Copyright (C) 2013-2025 by Greg Hendershott.
SPDX-License-Identifier: GPL-3.0-or-later
@end copying
@dircategory Emacs
@direntry
* Racket Mode: (racket-mode). Edit and REPL major modes for Racket lang.
@end direntry
@finalout
@titlepage
@title Racket Mode
@author Greg Hendershott (@email{racket-mode-author@@greghendershott.com})
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@ifnottex
@node Top
@top Racket Mode
@end ifnottex
@menu
* Introduction::
* Install, Update, and Uninstall: Install Update and Uninstall.
* Configure::
* Architecture::
* Reference::
* Commands::
* Variables::
* Configuration functions::
* Faces::
@detailmenu
--- The Detailed Node Listing ---
Install, Update, and Uninstall
* Use Emacs 28.1 or newer with NonGNU ELPA: Use Emacs 281 or newer with NonGNU ELPA.
* Configure Emacs to use MELPA::
* Install::
* Minimal Racket::
* Uninstall::
* Update::
Update
* Upgrading all packages::
* Updating just Racket Mode::
Configure
* Which major mode to use::
* Key bindings::
* Font-lock (syntax highlighting)::
* Completion at point::
* Completion in minibuffer::
* Xref (definitions and references)::
* Indent::
* paredit::
* smartparens::
* Appearance of parentheses::
* Edit buffers and REPL buffers::
* eldoc::
* Start faster::
* Inserting Unicode math symbols::
* Ligatures::
Commands
* Edit::
* Hash Langs::
* Explore::
* Run::
* Test::
* Eval::
* Collections::
* Macro expand::
* Packages::
* Other::
Edit
* racket-mode::
* racket-insert-lambda::
* racket-insert-symbol::
* racket-fold-all-tests::
* racket-unfold-all-tests::
* racket-tidy-requires::
* racket-trim-requires::
* racket-base-requires::
* racket-add-require-for-identifier::
* racket-indent-line::
* racket-smart-open-bracket-mode::
* racket-insert-closing::
* racket-cycle-paren-shapes::
* racket-backward-up-list::
* racket-input-mode::
* racket-align::
* racket-unalign::
* racket-complete-at-point::
Hash Langs
* racket-hash-lang-mode::
* racket-hash-lang-backward::
* racket-hash-lang-forward::
* racket-hash-lang-up::
* racket-hash-lang-down::
* racket-hash-lang-C-M-q-dwim::
Explore
* racket-xp-mode::
* racket-xp-describe::
* racket-xp-documentation::
* racket-xp-next-definition::
* racket-xp-previous-definition::
* racket-xp-next-use::
* racket-xp-previous-use::
* racket-xp-next-error::
* racket-xp-previous-error::
* racket-xp-tail-up::
* racket-xp-tail-down::
* racket-xp-tail-next-sibling::
* racket-xp-tail-previous-sibling::
* racket-documentation-search::
* racket-describe-mode::
* racket-describe-search::
Run
* racket-repl-mode::
* racket-run::
* racket-run-and-switch-to-repl::
* racket-run-module-at-point::
* racket-repl::
* racket-repl-describe::
* racket-repl-documentation::
* racket-racket::
* racket-profile::
* racket-profile-mode::
* racket-logger::
* racket-logger-mode::
* racket-debug-mode::
* racket-repl-clear::
* racket-repl-clear-leaving-last-prompt::
Test
* racket-test::
* racket-raco-test::
Eval
* racket-send-region::
* racket-send-definition::
* racket-send-last-sexp::
Collections
* racket-open-require-path::
Macro expand
* racket-stepper-mode::
* racket-expand-file::
* racket-expand-region::
* racket-expand-definition::
* racket-expand-last-sexp::
Packages
* racket-package-refresh::
* list-racket-packages::
* racket-package-mode::
* describe-racket-package::
Other
* racket-debug-toggle-breakpoint::
* racket-mode-start-faster::
* racket-mode-start-slower::
Variables
* General variables::
* Hash lang variables::
* REPL variables::
* Other variables::
* Experimental debugger variables::
* Showing information::
* Running racket and raco commands in a shell or terminal::
* Racket input method::
General variables
* racket-program::
* racket-command-timeout::
* racket-memory-limit::
* racket-error-context::
* racket-user-command-line-arguments::
* racket-browse-url-function::
* racket-xp-after-change-refresh-delay::
* racket-xp-highlight-unused-regexp::
* racket-xp-add-binding-faces::
* racket-xp-eldoc-level::
* racket-documentation-search-location::
* racket-expand-hiding::
Hash lang variables
* racket-hash-lang-token-face-alist::
* racket-hash-lang-module-language-hook::
REPL variables
* racket-repl-buffer-name-function::
* racket-submodules-to-run::
* racket-repl-history-directory::
* racket-history-filter-regexp::
* racket-images-inline::
* racket-imagemagick-props::
* racket-images-keep-last::
* racket-images-system-viewer::
* racket-images-do-not-use-svg::
* racket-pretty-print::
* racket-repl-command-file::
* racket-repl-echo-sent-expressions::
Other variables
* racket-doc-index-directory::
* racket-doc-index-predicate-function::
* racket-indent-curly-as-sequence::
* racket-indent-sequence-depth::
* racket-pretty-lambda::
* racket-smart-open-bracket-enable::
* racket-logger-config::
* racket-before-run-hook::
* racket-after-run-hook::
* racket-sexp-comment-fade::
Experimental debugger variables
* racket-debuggable-files::
Showing information
* racket-show-functions::
Running racket and raco commands in a shell or terminal
* racket-shell-or-terminal-function::
Racket input method
* racket-input-prefix::
* racket-input-translations::
Configuration functions
* Showing information: Showing information (1).
* Associating edit buffers with REPL buffers::
* Browsing file URLs with anchors::
* Configuring back ends::
* Running racket and raco commands in a shell or terminal: Running racket and raco commands in a shell or terminal (1).
Showing information
* racket-show-pseudo-tooltip::
* racket-show-echo-area::
* racket-show-header-line::
* racket-show-pos-tip::
Associating edit buffers with REPL buffers
* racket-repl-buffer-name-shared::
* racket-repl-buffer-name-unique::
* racket-repl-buffer-name-project::
* racket-project-root::
Browsing file URLs with anchors
* racket-browse-url-using-temporary-file::
Configuring back ends
* racket-add-back-end::
Running racket and raco commands in a shell or terminal
* racket-shell::
* racket-term::
* racket-ansi-term::
* racket-vterm::
Faces
* All::
All
* racket-keyword-argument-face::
* racket-reader-quoted-symbol-face::
* racket-reader-syntax-quoted-symbol-face::
* racket-here-string-face::
* racket-xp-def-face::
* racket-xp-use-face::
* racket-xp-unused-face::
* racket-xp-tail-target-face::
* racket-xp-tail-position-face::
* racket-xp-binding-lang-face::
* racket-xp-binding-lang-use-face::
* racket-xp-binding-import-face::
* racket-xp-binding-import-use-face::
* racket-xp-binding-local-face::
* racket-xp-binding-local-use-face::
* racket-logger-config-face::
* racket-logger-topic-face::
* racket-logger-fatal-face::
* racket-logger-error-face::
* racket-logger-warning-face::
* racket-logger-info-face::
* racket-logger-debug-face::
* racket-doc-link-face::
* racket-ext-link-face::
* racket-doc-output-face::
* racket-doc-litchar-face::
* racket-repl-message::
* racket-repl-prompt::
* racket-repl-value::
* racket-repl-error-message::
* racket-repl-error-location::
* racket-repl-stdout::
* racket-repl-stderr::
* racket-hash-lang-text::
@end detailmenu
@end menu
@node Introduction
@chapter Introduction
The @uref{https://www.racket-mode.com/, Racket Mode} package consists of a variety of Emacs major and minor modes, including:
@itemize
@item
@code{racket-mode}: A major mode to edit @code{.rkt} files. Generally assumes @code{#lang racket}.
@item
@ref{racket-hash-lang-mode}: An alternative to @code{racket-mode} using behavior specified by a @code{#lang} for colors, indent, expression navigation, etc. @emph{Experimental}.
@item
@ref{racket-xp-mode}: A minor mode to enhance either edit mode. Explain and explore code, similar to background check-syntax in Dr Racket.
@item
@code{racket-repl-mode}: A major mode to run programs and use a REPL@.
@item
Various other modes to support specific features:
@itemize
@item
@ref{racket-logger-mode}
@item
@ref{racket-profile-mode}
@item
@ref{racket-debug-mode}
@end itemize
@end itemize
For code, issues, and pull requests, see the @uref{https://github.com/greghendershott/racket-mode, Git repo}.
To sponsor this work, see @uref{https://github.com/users/greghendershott/sponsorship, GitHub Sponsors} or @uref{https://www.paypal.me/greghendershott, PayPal}.
@node Install Update and Uninstall
@chapter Install, Update, and Uninstall
The most common way to use Racket Mode is to install from a package archive like MELPA or NonGNU ELPA@.
Some people also use a system like @uref{https://github.com/radian-software/straight.el, straight.el}.
Note that Racket Mode is only available on MELPA (@emph{not} ``MELPA Stable''), and is available as a ``rolling release'' from NonGNU ELPA@.
@menu
* Use Emacs 28.1 or newer with NonGNU ELPA: Use Emacs 281 or newer with NonGNU ELPA.
* Configure Emacs to use MELPA::
* Install::
* Minimal Racket::
* Uninstall::
* Update::
@end menu
@node Use Emacs 281 or newer with NonGNU ELPA
@section Use Emacs 28.1 or newer with NonGNU ELPA
Emacs 28.1 or newer comes configured to use @uref{https://elpa.nongnu.org, NonGNU ELPA}, in which case you can skip ahead to @ref{Install}.
With older versions of Emacs, you can use MELPA@.
@node Configure Emacs to use MELPA
@section Configure Emacs to use MELPA
Following is a quick guide that may work for you. (For definitive instructions and the latest trouble-shooting tips, please see @uref{https://melpa.org/#/getting-started}.)
@itemize
@item
Add the following to your @samp{~/.emacs} or @samp{~/.emacs.d/init.el}:
@end itemize
@lisp
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/")
t)
(package-initialize)
@end lisp
@itemize
@item
Restart Emacs.
@end itemize
@quotation
NOTE: If you ever get an error message about ``contacting a host'' or ``downloading an archive'', the problem is not unique to Racket Mode. Please see @uref{https://melpa.org/#/getting-started}.
@end quotation
@node Install
@section Install
When Emacs is configured to use NonGNU ELPA or MELPA:
@enumerate
@item
Type @kbd{M-x} @code{package-initialize} @kbd{RET} .
@item
Type @kbd{M-x} @code{package-refresh-contents} @kbd{RET} .
@item
Type @kbd{M-x} @code{package-install} @kbd{RET} @code{racket-mode} @kbd{RET} .
@end enumerate
@quotation
NOTE: If you get an error message about ``contacting a host'' or ``downloading an archive'', the problem is not unique to Racket Mode. Please see @uref{https://melpa.org/#/getting-started}.
@end quotation
@node Minimal Racket
@section Minimal Racket
If you have installed the minimal Racket distribution (for example by using the @uref{https://github.com/Homebrew/homebrew-core/blob/master/Formula/m/minimal-racket.rb, homebrew formula}) Racket Mode needs some additional Racket packages. A simple way to get all these packages is to install the @code{drracket} Racket package. In a command shell:
@example
raco pkg install --auto drracket
@end example
A more-targeted approach is instead to install these specific packages and their dependencies:
@example
raco pkg install --auto data-lib errortrace-lib macro-debugger-text-lib rackunit-lib racket-index scribble-lib drracket-tool-text-lib
@end example
If you do @emph{not} want to use @code{racket-xp-mode}, then you can omit @code{drracket-tool-text-lib}.
On a headless server, you might want to omit @code{gui-lib}. Unfortunately, @code{racket-doc} depends on @code{gui-lib}. On the one hand, if you uninstall @code{racket-doc} and @code{gui-lib}, you will no longer be able to access documentation when using a Racket Mode back end running there. On the other hand, if you leave @code{gui-lib} installed, you should be careful to run the Racket Mode back end using @code{xvfb-run racket}.
@node Uninstall
@section Uninstall
To uninstall Racket Mode, simply type @kbd{M-x} @code{package-delete} @kbd{RET} @code{racket-mode} @kbd{RET} .
You should probably also exit and restart Emacs.
@node Update
@section Update
@menu
* Upgrading all packages::
* Updating just Racket Mode::
@end menu
@node Upgrading all packages
@subsection Upgrading all packages
The ``easy path'' provided by Emacs is to update @emph{all} packages to their latest versions. Although you might not want to do this --- see next section --- here is how to do so:
@enumerate
@item
Use @kbd{M-x} @code{package-initialize}.
@item
Use @kbd{M-x} @code{package-refresh-contents}.
@item
Use @kbd{M-x} @code{list-packages}. It should display a message like ``42 packages can be upgraded; type ‘U’ to mark them for upgrading.''.
@item
Press @kbd{U} as suggested to mark them all.
@item
Press @kbd{x} to execute.
@end enumerate
After such a mass update, it might be wise to exit and restart Emacs.
@quotation
NOTE: If you get an error message about ``contacting a host'' or ``downloading an archive'', the problem is not unique to Racket Mode. Please see @uref{https://melpa.org/#/getting-started}.
@end quotation
@node Updating just Racket Mode
@subsection Updating just Racket Mode
Updating all packages sometimes is more than you want. For example, maybe you will discover that some packages have changed in ways that require you to take time to learn about, change customizations, and so on.
To update just Racket Mode:
@enumerate
@item
@ref{Uninstall}.
@item
Optional but most reliable: Exit and restart Emacs.
@item
@ref{Install} again. This will install the latest version.
@end enumerate
@node Configure
@chapter Configure
Although Racket Mode can be customized with many @ref{Variables}, there is only one that you might @emph{need} to set: @ref{racket-program}. This is the name or pathname of the Racket executable. It defaults to @code{Racket.exe} on Windows else @code{racket}.
On Windows or Linux, this default will probably work for you.
On macOS, downloading Racket doesn't add its @code{bin} directory to your @code{PATH}. Even after you add it, GUI Emacs doesn't automatically use your path (unless you use the handy @uref{https://melpa.org/#/exec-path-from-shell, exec-path-from-shell} package). Therefore you might want to set @code{racket-program} to a complete pathname.
You can @code{setq} this directly in your Emacs init file (@samp{~/.emacs} or @samp{~/.emacs.d/init.el}), or, use @kbd{M-x} @code{customize}, as you prefer.
@menu
* Which major mode to use::
* Key bindings::
* Font-lock (syntax highlighting)::
* Completion at point::
* Completion in minibuffer::
* Xref (definitions and references)::
* Indent::
* paredit::
* smartparens::
* Appearance of parentheses::
* Edit buffers and REPL buffers::
* eldoc::
* Start faster::
* Inserting Unicode math symbols::
* Ligatures::
@end menu
@node Which major mode to use
@section Which major mode to use
Racket is a programming language.
Racket is also a ``language-oriented programming language''. Most Racket source files contain a `#lang` line. The lang may be an s-expression lang like @code{racket}, or an at-expression lang like @code{scribble/manual}, or something completely different like @code{datalog} or @code{rhombus}.
The Racket Mode package offers a choice of two major modes to use in buffers for viewing and editing source code. Each has pros and cons.
Whereas @code{racket-mode} is in the tradition of Emacs @code{lisp-mode} and @code{scheme-mode} and assumes s-expression langs, @code{racket-hash-lang-mode} takes the approach of DrRacket to work for all langs.
@itemize
@item
@code{racket-mode} is the original, ``classic'' mode for @code{#lang racket} and related s-expression languages. It is implemented entirely in Emacs and does @emph{not} need Racket Mode's back end racket process running. Font-lock (coloring) uses rules for a fixed set of identifiers from @code{racket} lang and popular modules like @code{racket/match}. Indentation uses rules for a fixed set of forms, and may be customized.
@item
@code{racket-hash-lang-mode} uses font-lock (colors) and indentation determined by the lang; to get this information it @emph{does} need the Racket Mode's back end racket process running. Although basic editing should feel fast, you might notice some delay when indenting. You might see colors appear after a small delay (but it will not block editing). Speaking of colors, they will be ``plainer'' than @code{racket-mode} -- just colors for tokens like numbers, comments, strings, and keywords. This looks similar to DrRacket. However you can enhance this in various ways; see the discussion of @ref{racket-hash-lang-module-language-hook}.
@end itemize
You can use different major modes for different kinds of files:
@itemize
@item
For editing @code{.rkt} files and s-expression langs, which mode to use is personal preference.
@item
For @code{.scrbl} files and at-expression langs like @code{scribble/manual}, @code{racket-hash-lang-mode} is probably better than @code{racket-mode}. (Note there is also an unrelated @code{scribble-mode} package.)
@item
For non-s-expression langs like @code{datalog} or @code{rhombus} (@code{.rhm}), @code{racket-hash-lang-mode} is definitely better than @code{racket-mode}. (Note there is also an unrelated @code{rhombus-mode} package.)
@end itemize
You can use @code{auto-mode-alist} to tell Emacs which major mode to use initially for certain file extensions. Also, in a buffer you can use @code{M-x racket-mode} and @code{M-x racket-hash-lang-mode} to switch between them.
@node Key bindings
@section Key bindings
To customize things like key bindings, you can use @code{racket-mode-hook} in your Emacs init file to modify @code{racket-mode-map}. For example, although @kbd{C-c C-c} is bound by default to the @code{racket-run} command, let's say you wanted @kbd{F5} to be an additional binding:
@lisp
(add-hook 'racket-mode-hook
(lambda ()
(define-key racket-mode-map (kbd "<f5>") 'racket-run)))
@end lisp
Likewise for @code{racket-repl-mode-hook} and @code{racket-repl-mode-map}.
@node Font-lock (syntax highlighting)
@section Font-lock (syntax highlighting)
@quotation
Note: The alternative major mode @ref{racket-hash-lang-mode} disables all of the following behavior and uses colors determined by the #lang.
@end quotation
Font-lock (as Emacs calls syntax highlighting) can be controlled using the variable @code{font-lock-maximum-decoration}, which defaults to @code{t} (maximum). You can set it to a number, where @code{0} is the lowest level. You can even supply an association list to specify different values for different major modes.
Historically you might choose a lower level for speed. These days you might do so because you prefer a simpler appearance.
Racket Mode supports four, increasing levels of font-lock:
@itemize
@item
@code{0}: Just strings, comments, and @code{#lang}.
@item
@code{1}: @code{#:keyword} and self-evaluating literals like numbers, quoted symbols (including symbols with spaces delimited by @code{|} characters), and @code{#rx} and @code{#px} regular expressions.
@item
@code{2}: Identifiers in @code{define}-like and @code{let}-like forms.
@item
@code{3}: Identifiers provided by @code{racket}, @code{typed/racket}, @code{racket/syntax}, and @code{syntax/parse}. (This level effectively treats Racket as a language, instead of a language for making languages.).
@end itemize
@node Completion at point
@section Completion at point
In Emacs, a major mode may supply a ``completion-at-point function''. This function is used by manual completion commands like @code{complete-symbol} (bound by default to @kbd{C-M-i} ), as well as by auto-completion packages like @code{company-mode}.
@itemize
@item
@code{racket-mode} supplies @code{racket-complete-at-point}, which simply supplies the same symbols that it knows how to font-lock. This does @emph{not} require the Racket Mode back end to be running. But of course the completion candidates do not correspond to your program's definitions or those it imports. This is a static, ``better than nothing'' fallback.
@item
@code{racket-xp-mode} --- an optional minor mode that enhances @code{racket-mode} --- supplies @code{racket-xp-complete-at-point}, which uses a static analysis to find local and imported binding names. Although this requires the Racket Mode back end to be running --- and will automatically start it --- it does @emph{not} require the edit buffer to be @code{racket-run}. This also supplies meta data usable by the @code{company-capf} backend.
@item
@code{racket-repl-mode} supplies @code{racket-repl-complete-at-point}, which uses the result of @code{namespace-mapped-symbols} on the program currently running in the REPL@.
@end itemize
These completion functions are set by default. (However, @code{racket-xp-mode} is not enabled by default. To do so: @ref{racket-xp-mode}.)
If you want @kbd{TAB} to do completion as well as indent, add the following to your Emacs init file:
@lisp
(setq tab-always-indent 'complete)
@end lisp
This changes the behavior of Emacs' standard @code{indent-for-tab-command}, to which @kbd{TAB} is bound by default in @code{racket-mode} and @code{racket-repl-mode}.
@node Completion in minibuffer
@section Completion in minibuffer
Sometimes Racket Mode asks for input in the minibuffer. To do so it uses the standard Emacs function @code{completing-read}, so as to be compatible with all Emacs packages that enhance @code{completing-read}, such as helm, ivy, ido-completing-read+, vertico, and so on.
(Earlier versions of Racket Mode sometimes used @code{ido-completing-read}. If you have upgraded Racket Mode and miss that, simply install the ido-completing-read+ package.)
@node Xref (definitions and references)
@section Xref (definitions and references)
Several modes support the Emacs commands
@itemize
@item
@kbd{M-.} @code{xref-find-definitions}
@item
@kbd{M-?} @code{xref-find-references}
@item
@kbd{M-,} @code{xref-pop-marker-stack}
@end itemize
To do so, each mode adds a local hook for @code{xref-backend-functions}:
@itemize
@item
@ref{racket-mode}: @code{#'racket-mode-xref-backend-function}
@item
@ref{racket-xp-mode}: @code{#'racket-xp-xref-backend-function}
@item
@ref{racket-repl-mode}: @code{#'racket-repl-xref-backend-function}
@end itemize
If you prefer, you can remove the local hook --- e.g. for @code{racket-mode}: @code{(remove-hook 'xref-backend-functions #'racket-mode-xref-function t)}.
You can @code{M-x customize-group} and enter @code{xref} to adjust some other settings. For example, the customization variable @code{xref-prompt-for-identifier} controls which commands prompt you and when. You might prefer to set it to @code{nil}.
If you use @code{paredit}, by default it binds @kbd{M-?} to @code{paredit-convolute-sexp}. You can change that binding in @code{paredit-mode-map} allowing the global binding for @kbd{M-?} to be used, or, pick some other key for @code{xref-find-references} in the global map.
Finally, what to expect:
@itemize
@item
Racket does not have a global or project-wide database of definitions and references.
@item
Various modules can export identifiers with the same symbolic value -- for example a different ``define'' is provided by @code{racket/base}, @code{typed/racket/base}, and other modules.
@item
A module can import something, then rename, contract, and re-export it.
@end itemize
As a result, to find a definition, it is necessary to know exactly @emph{which} identifier is meant --- either by expanding the module (as is done by @code{racket-xp-mode}) or by actually running it (@code{racket-repl-mode}). Once known, we can usually find the definition site, even through a chain of renaming and/or contract-wrapping exports. In addition, when point is on a module within @code{require} form, we can usually find the source file. (In plain @code{racket-mode} edit buffers not enhanced by @code{racket-xp-mode}, the only thing that @code{xref-find-definitions} does is visit relative requires, e.g. @code{foo.rkt} in @code{(require "foo.rkt")}.)
As for finding references, the default xref implementation is used, which greps for strings among a project's files. Although @code{racket-xp-mode} can sometimes do better, using @code{drracket/check-syntax} for definitions and references @emph{within} the current buffer, beyond those it also falls back to the default implementation.
In any case, using the Emacs xref API allows for consistent command names, shortcut keys, and even a special buffer to navigate among references and visit each source location.
@node Indent
@section Indent
@quotation
Note: The alternative major mode @ref{racket-hash-lang-mode} disables all of the following behavior and uses indentation determined by the #lang.
@end quotation
Indentation can be customized in a way similar to lisp-mode and scheme-mode: @ref{racket-indent-line}.
(Indentation preserves your line breaks. If you want to use an auto-reformatter --- an expressive pretty printer that chooses line breaks while computing an optimal layout --- the Racket package @uref{https://docs.racket-lang.org/fmt/, fmt} is supported by the Emacs package @uref{https://github.com/lassik/emacs-format-all-the-code, emacs-format-all-the-code}.)
@node paredit
@section paredit
@quotation
Note: If you use @ref{racket-hash-lang-mode}, see @ref{racket-hash-lang-module-language-hook} for how to enable/disable paredit based on the specific #lang.
@end quotation
If you use @uref{https://melpa.org/#/paredit, paredit}, you might want to add keybindings to @code{paredit-mode-map}:
@itemize
@item
Bind the curly brace keys to @code{paredit-open-curly} and @code{paredit-close-curly}.
@item
Bind whatever keys you prefer for @code{paredit-wrap-square} and @code{paredit-wrap-curly}.
@end itemize
For example, with @uref{https://melpa.org/#/use-package, @code{use-package}}:
@lisp
(use-package paredit
:ensure t
:config
(dolist (m '(emacs-lisp-mode-hook
racket-mode-hook
racket-repl-mode-hook))
(add-hook m #'paredit-mode))
(bind-keys :map paredit-mode-map
("@{" . paredit-open-curly)
("@}" . paredit-close-curly))
(unless terminal-frame
(bind-keys :map paredit-mode-map
("M-[" . paredit-wrap-square)
("M-@{" . paredit-wrap-curly))))
@end lisp
Starting c. November 2022, paredit binds the @kbd{RET} key to its own command. Unfortunately this is @emph{not} compatible with interactive modes --- including but not limited to @code{racket-repl-mode} --- which expect @kbd{RET} to be bound to a command to submit your input to the REPL@. In other words, if you type an expression and hit @kbd{RET} , nothing will happen and the REPL will seem frozen. You @code{M-x racket-repl-submit} to proceed.
If you want to use paredit with interactive modes, their advice is to remove the binding from @code{paredit-mode-map} (note that this will also disable it for all buffers, including editing buffers). One way you can do this for all related keys:
@lisp
(dolist (k '("RET" "C-m" "C-j"))
(define-key paredit-mode-map (kbd k) nil))
@end lisp
@node smartparens
@section smartparens
@quotation
Note: If you use @ref{racket-hash-lang-mode}, see @ref{racket-hash-lang-module-language-hook} for how to enable/disable smartparens based on the specific #lang.
@end quotation
If instead of paredit you prefer @uref{https://melpa.org/#/smartparens, smartparens}, you can use the default configuration it provides for Lisp modes generally and for Racket Mode specifically:
@lisp
(require 'smartparens-config)
@end lisp
@node Appearance of parentheses
@section Appearance of parentheses
If you prefer parentheses to appear ``dimmed'', see @uref{https://melpa.org/#/paren-face, paren-face}.
If you prefer the opposite, see @uref{https://melpa.org/#/rainbow-delimiters, rainbow-delimiters}.
@node Edit buffers and REPL buffers
@section Edit buffers and REPL buffers
By default, all @code{racket-mode} edit buffers share one @code{racket-repl-mode} buffer, named @code{*Racket REPL*}. For example, if you run foo.rkt, the REPL prompt changes to @code{foo.rkt>}, and the REPL is inside the file module namespace. If you then run bar.rkt, the REPL prompt changes to @code{bar.rkt>}, and you are in that namespace.
If you prefer, you can use more than one REPL buffer, by customizing the variable @ref{racket-repl-buffer-name-function}:
@itemize
@item
Share a REPL buffer among files belonging to the same project; each REPL buffer is named @code{*Racket REPL <project-name>*}.
@item
A unique REPL buffer for each edit buffer, similar to Dr Racket; each REPL buffer is named @code{*Racket REPL <file.rkt>*}.
@item
You can also define your own, custom function.
@end itemize
You can customize where the REPL buffer is displayed by adding an item to the Emacs variable @code{display-buffer-alist}. A good regular expression to use for this would be @code{\\`\\*Racket REPL}. For example, if you wanted to make the REPL buffer appear in a new frame:
@lisp
(add-to-list 'display-buffer-alist
'("\\`\\*Racket REPL"
(display-buffer-reuse-window
display-buffer-pop-up-frame)
(reusable-frames . 0)
(inhibit-same-window . t)))
@end lisp
@node eldoc
@section eldoc
Various modes add local hooks to @code{eldoc-documentation-functions}.
@itemize
@item
The minor mode @code{racket-xp-mode} adds hooks to document the identifiers at point or at an apparent s-expression application head position. The identifiers are documented from check-syntax annotations. You may customize the variable @ref{racket-xp-eldoc-level} to choose how much information is shown.
@item
The major mode @code{racket-repl-mode} adds hooks to describe the namespace identifers at point or at an apparent s-expression application head position. The description is a signature from surface syntax, or a Typed Racket type, or a ``bluebox'' for the namespace identifier.
@end itemize
Tip: With an @code{eldoc-documentation-strategy} of @code{eldoc-documentation-default}, these hooks show info about point when available, @emph{or else} for the s-expression application head. You may change that to @code{eldoc-documentation-compose} to show info for @emph{both} positions when available.
Tip: Some people use the third-party package @code{eldoc-box} to show information in a child frame (near point, or in a corner of the main frame) instead of the echo area.
Note: Racket Mode does not support the ``old'' eldoc API that uses @code{eldoc-documentation-function}, singular.
@node Start faster
@section Start faster
You can use @ref{racket-mode-start-faster} to make the Racket REPL start faster.
@node Inserting Unicode math symbols
@section Inserting Unicode math symbols
To insert various Unicode math symbols, you can:
@itemize
@item
Use a command: @xref{racket-insert-symbol}.
@item
Use an Emacs input method, which you can enable in a buffer using a minor mode: @xref{racket-input-mode}.
@end itemize
@node Ligatures
@section Ligatures
Prior to Emacs 28.0.50, things like @code{auto-composition-mode} or @code{ligature-mode} that use @code{composition-function-table} to display ligatures can cause Emacs to freeze. This can happen when an Emacs @emph{overlay} displays a string containing such a ligature. Although the problem is not limited to Racket Mode, it affects the overlays created by @code{racket-show-pseudo-tooltip}, as used by @code{racket-xp-mode}. The only known work-around is to change the value of @code{racket-show-functions} to something ``boring'' such as @code{(racket-show-echo-area)}.
@node Architecture
@chapter Architecture
Racket Mode consists of a single Emacs front end, and one or more processes running a back end written in Racket.@footnote{Racket Mode's Racket code is delivered as part of the Emacs package --- @emph{not} as a Racket package. Delivering both Emacs and Racket code in one Emacs package simplifies installation and updates. The main drawback is that the Racket code is not automatically compiled, as would normally be done by @code{raco pkg install}. To address this: @xref{racket-mode-start-faster}.}
A back end is responsible for commands that cannot be implemented in Emacs Lisp, as well as supplying zero or more REPLs.
Although you can start and stop a back end with @code{racket-start-back-end} and @code{racket-stop-back-end}, a back end is normally started automatically when the front end needs to issue some command. This includes commands that do @emph{not} involve @code{racket-run} or a REPL@. For example @code{racket-xp-mode} issues commands to check your code and annotate the buffer, even if you do not run it. In other words, a back end supplies zero or more REPLs --- a back end is not the same thing as a REPL@.
To learn more about how @emph{many} REPLs are used: @xref{racket-repl-buffer-name-function}.
In the common case there is only one back end, on the same local host as Emacs, and it is used for @code{.rkt} files in any directory.
@image{scenario-0,,, Emacs front end and one local back end. Command I/O via pipe (local) or ssh (remote). Each back end provides zero or more REPLs.,.svg}
However you can configure using any number of back ends on any number of local or remote host paths.
As one example, you can have multiple back ends on the local host. One back end is used for a project under a specific subdirectory, and the other back end for all others. (Perhaps one project needs Racket built from source, and everything else uses an installed, older version of Racket. By using different back ends, not only will @code{racket-run} use the desired version of Racket for a file, so will commands for documentation or visiting definitions.)
@image{scenario-1,,, Emacs front end and two local back ends --- one for a project path. Command I/O via pipe (local) or ssh (remote). Each back end provides zero or more REPLs.,.svg}
(Note: If you use various versions of Racket via @uref{https://direnv.net/, @code{direnv}} combined with the @uref{https://github.com/purcell/envrc, @code{envrc} Emacs package}, you still need a distinct back end for each project. To arrange this, add or modify a @code{.dir-locals.el} file next to each @code{.envrc} file; @xref{racket-add-back-end}.)
Furthermore, you could work with a project located on a remote host, whose files you edit using TRAMP@. You also want the back end to run there. For a remote host, Racket Mode copies its back end source files to the remote when necessary, and runs the back end using ssh.
@image{scenario-2,,, Emacs front end and a back end on a remote host. Command I/O via pipe (local) or ssh (remote). Each back end provides zero or more REPLs.,.svg}
Of course the remote can also use different back ends for different paths.
@image{scenario-3,,, Emacs front end and two back ends on a remote host. Command I/O via pipe (local) or ssh (remote). Each back end provides zero or more REPLs.,.svg}
And of course you can have multiple remotes.
@image{scenario-4,,, Emacs front end and two back ends each on two remote hosts. Command I/O via pipe (local) or ssh (remote). Each back end provides zero or more REPLs.,.svg}
If you need any of these ``fancy'' configurations: @xref{racket-add-back-end}.
However by default a configuration is automatically created for one back end on the local host. For that very common case, you don't need to configure anything.
@node Reference
@chapter Reference
The following sections are generated from the doc strings for each command, variable, or face. (As a result, some of the formatting might not be quite as nice or correct as in the previous sections.)
You can also view these by using the normal Emacs help mechanism:
@itemize
@item
@kbd{C-h f} and enter the name of a command.
@item
@kbd{C-h v} and enter the name of a variable.
@end itemize
@node Commands
@chapter Commands
@menu
* Edit::
* Hash Langs::
* Explore::
* Run::
* Test::
* Eval::
* Collections::
* Macro expand::
* Packages::
* Other::
@end menu
@node Edit
@section Edit
@menu
* racket-mode::
* racket-insert-lambda::
* racket-insert-symbol::
* racket-fold-all-tests::
* racket-unfold-all-tests::
* racket-tidy-requires::
* racket-trim-requires::
* racket-base-requires::
* racket-add-require-for-identifier::
* racket-indent-line::
* racket-smart-open-bracket-mode::
* racket-insert-closing::
* racket-cycle-paren-shapes::
* racket-backward-up-list::
* racket-input-mode::
* racket-align::
* racket-unalign::
* racket-complete-at-point::
@end menu
@node racket-mode
@subsection racket-mode
@kbd{M-x} @code{racket-mode}
The ``classic'' major mode to edit an s-expression Racket #lang.
This major mode is implemented entirely in Emacs and does @emph{not}
need Racket Mode's back end racket process to be running.
Font-lock (coloring) uses rules for a fixed set of identifiers
from @code{racket} lang and popular modules like @code{racket/match}.
Indentation uses rules for a fixed set of forms, and may be
customized.
See also @ref{racket-hash-lang-mode}.
@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
@item Key
@tab Binding
@item @kbd{TAB}
@tab @code{indent-for-tab-command}
@item @kbd{C-M-u}
@tab @ref{racket-backward-up-list}
@item @kbd{C-c C-p}
@tab @ref{racket-cycle-paren-shapes}
@item @kbd{C-c C-s} or @kbd{C-c C-.}
@tab @ref{racket-describe-search}
@item @kbd{C-c C-d}
@tab @ref{racket-documentation-search}
@item @kbd{C-c C-z}
@tab @code{racket-edit-switch-to-repl}
@item @kbd{C-c C-e x}
@tab @ref{racket-expand-definition}
@item @kbd{C-c C-e f}
@tab @ref{racket-expand-file}
@item @kbd{C-c C-e e}
@tab @ref{racket-expand-last-sexp}
@item @kbd{C-c C-e r}
@tab @ref{racket-expand-region}
@item @kbd{C-c C-f}
@tab @ref{racket-fold-all-tests}
@item @kbd{)} or @kbd{]} or @kbd{@}}
@tab @ref{racket-insert-closing}
@item @kbd{C-M-y}
@tab @ref{racket-insert-lambda}
@item @kbd{C-c C-l}
@tab @ref{racket-logger}
@item @kbd{C-c C-x C-f}
@tab @ref{racket-open-require-path}
@item @kbd{C-c C-o}
@tab @ref{racket-profile}
@item @kbd{C-c C-c} or @kbd{C-c C-k}
@tab @ref{racket-run-module-at-point}
@item @kbd{C-M-x}
@tab @ref{racket-send-definition}
@item @kbd{C-x C-e}
@tab @ref{racket-send-last-sexp}
@item @kbd{C-c C-r}
@tab @ref{racket-send-region}
@item @kbd{C-c C-t}
@tab @ref{racket-test}
@item @kbd{C-c C-u}
@tab @ref{racket-unfold-all-tests}
@end multitable
In addition to any hooks its parent mode @code{prog-mode} might have run,
this mode runs the hook @code{racket-mode-hook}, as the final or
penultimate step during initialization.
@node racket-insert-lambda
@subsection racket-insert-lambda
@kbd{C-M-y}
Insert λ.
To insert Unicode symbols generally, see @ref{racket-input-mode}.
@node racket-insert-symbol
@subsection racket-insert-symbol
@kbd{M-x} @code{racket-insert-symbol}
Insert a symbol from @ref{racket-input-translations}.
A command alternative to the ``Racket'' input method activated by
@ref{racket-input-mode}.
Presents a @code{completing-read} UI, in which the symbols that would
be inserted are shown as annotations -- a preview unlike what is
currently provided by the Emacs UI for input method.
@node racket-fold-all-tests
@subsection racket-fold-all-tests
@kbd{C-c C-f}
Fold (hide) all test submodules.
@node racket-unfold-all-tests
@subsection racket-unfold-all-tests
@kbd{C-c C-u}
Unfold (show) all test submodules.
@node racket-tidy-requires
@subsection racket-tidy-requires
@kbd{M-x} @code{racket-tidy-requires}
Make a single, sorted ``require'' form for each module.
Use a single require-spec for each phase-level, sorted in this
order: for-syntax, for-template, for-label, for-meta, and
plain (phase 0).
Within each phase-level, sort require-specs by module name.
Format at most one module per line.
Simplify gratuitous require-specs. For example reduce (only-in m)
to m and elide (combine-in).
See also: @ref{racket-trim-requires} and @ref{racket-base-requires}.
@node racket-trim-requires
@subsection racket-trim-requires
@kbd{M-x} @code{racket-trim-requires}
Like @ref{racket-tidy-requires} but also delete unnecessary requires.
Use macro-debugger/analysis/check-requires to analyze.
The analysis:
@itemize
@item
Needs the @code{macro-debugger-lib} package.
@item
Only works when the source file can be fully expanded with no
@end itemize
errors.
@itemize
@item
Only works for requires at the top level of a source file using
@end itemize
#lang -- not for requires inside submodule forms. Furthermore,
the analysis is not smart about module+ or module* forms -- it
might delete outer requires that are actually needed by such
submodules.
See also: @ref{racket-base-requires}.
@node racket-base-requires
@subsection racket-base-requires
@kbd{M-x} @code{racket-base-requires}
Change from ``#lang racket'' to ``#lang racket/base''.
Using ``racket/base'' is a recommended optimization for Racket
applications. Loading all of ``racket'' is slower and uses more
memory.
Add explicit requires for imports that are provided by ``racket''
but not by ``racket/base''.
Also do the equivalent of @ref{racket-trim-requires} and
@code{nil}. See those commands for additional notes
and caveats.
Note: Currently this only helps change ``#lang racket'' to
``#lang racket/base''. It does not help with other similar
conversions, such as changing ``#lang typed/racket'' to ``#lang
typed/racket/base''.
@node racket-add-require-for-identifier
@subsection racket-add-require-for-identifier
@kbd{M-x} @code{racket-add-require-for-identifier}
Add a require for an identifier.
Useful when you know the name of an export but don't remember
from what module it is exported.
After you choose an identifier, this command will:
@itemize
@item
Insert the identifier at point if not already there.
@item
Insert a ``require'' form and do @ref{racket-tidy-requires}.
@end itemize
Caveat: This works only for identifiers that are documented. The
mechanism is similar to that used for Racket's ``Search Manuals''
feature. Today there exists no system-wide database of
identifiers that are exported but not documented.
@node racket-indent-line
@subsection racket-indent-line
@kbd{M-x} @code{racket-indent-line}
Indent current line as Racket code.
Normally you don't invoke this command directly. Instead, because
it is used as the value for the variable @code{indent-line-function}
in @ref{racket-mode} and @ref{racket-repl-mode} buffers, it is used
automatically when you press keys like RET or TAB@. However you
might refer to it when configuring custom indentation, explained
below.
Following the tradition of @code{lisp-mode} and @code{scheme-mode}, the
primary way to determine the indentation of a form is to look for
a rule stored as a @code{racket-indent-function} property.
To extend, use your Emacs init file to
@lisp
(put SYMBOL 'racket-indent-function INDENT)
@end lisp
SYMBOL is the name of the Racket form like ``test-case'' and
INDENT is an integer or the symbol ``defun''. When INDENT is an
integer, the meaning is the same as for lisp-indent-function and
scheme-indent-function: Indent the first INDENT arguments
specially and indent any further arguments like a body. (The
number may be negative; see discussion below.)
For example:
@lisp
(put 'test-case 'racket-indent-function 1)
@end lisp
This will change the indent of @code{test-case} from this:
@example
(test-case foo
blah
blah)
@end example
to this:
@example
(test-case foo
blah
blah)
@end example
For backward compatibility, if @code{racket-indent-function} has no
property for a symbol, a scheme-indent-function property is also
considered, although the ``with-'' indents defined by scheme-mode
are ignored. This is only to help people who may have extensive
scheme-indent-function settings, particularly in the form of file
or dir local variables. Otherwise prefer putting properties on
@code{racket-indent-function}.
If no explicit rules match, regular expressions are used for a
couple special cases:
@itemize
@item
Forms that start with ``begin'' indent like ``begin''.
@item
Forms that start with ``def'' or ``with-'' indent like
``define''.
@end itemize
On the one hand this is convenient when you create your own
``DRY'' macros; they will indent as expected without you needing
to make custom indent rules. On the other hand there can be false
matches; for example a function or form named ``defer'' will
indent like ``define''. This is a known drawback and is unlikely
to be fixed unless/until Racket macros someday support a protocol
to communicate how they should be indented.
There is also automatic handling for:
@itemize
@item
Forms that begin with a #:keyword (as found in contracts)
@item
Literal forms like #hasheq()
@item
Quoted forms when the variable @ref{racket-indent-sequence-depth}
is > 0.
@item
@{@} forms when the variable @ref{racket-indent-curly-as-sequence} is
not nil.
@end itemize
Finally and otherwise, a form will be indented as if it were a
procedure application.
--- --- ---
Note: Racket Mode extends the traditional Emacs lisp indent spec
to allow a @emph{negative} integer, which means that all distinguished
forms should align with the first one. This style originated with
``for/fold'', which has two distinguished forms. Traditionally
those would indent like this:
@example
(for/fold ([x xs])
([y ys]) ; twice body indent
body)
@end example
However the popularly desired indent is:
@example
(for/fold ([x xs])
([y ys]) ; same as first distingushed form
body)
@end example
This idea extends to optional distinguished forms, such as Typed
Racket annotation ``prefixes'' in ``for/fold'', ``for/x'', and
even ``let'' forms:
@example
(for/fold : Type
([x xs])
([y ys]) ; same as first distingushed form
body)
@end example
@node racket-smart-open-bracket-mode
@subsection racket-smart-open-bracket-mode
@kbd{M-x} @code{racket-smart-open-bracket-mode}
Minor mode to let you always type @code{[}' to insert @code{(} or @code{[} automatically.
Behaves like the ``Automatically adjust opening square brackets''
feature in Dr. Racket.
By default, inserts a @code{(}. Inserts a @code{[} in the following cases:
@itemize
@item
@code{let}-like bindings -- forms with @code{let} in the name as well
as things like @code{parameterize}, @code{with-handlers}, and
@code{with-syntax}.
@item
@code{case}, @code{cond}, @code{match}, @code{syntax-case}, @code{syntax-parse}, and
@code{syntax-rules} clauses.
@item
@code{for}-like bindings and @code{for/fold} accumulators.
@item
@code{class} declaration syntax, such as @code{init} and @code{inherit}.
@end itemize
When the previous s-expression in a sequence is a compound
expression, uses the same kind of delimiter.
To force insert @code{[}, use @code{quoted-insert}.
Combined with @ref{racket-insert-closing} this means that you can
press the unshifted @code{[} and @code{]} keys to get whatever delimiters
follow the Racket conventions for these forms. When something
like @code{electric-pair-mode} or @code{paredit-mode} is active, you need
not even press @code{]}.
Tip: When also using @code{paredit-mode}, enable that first so that
the binding for the @code{[}' key in the map for
@ref{racket-smart-open-bracket-mode} has higher priority. See also
the variable @code{minor-mode-map-alist}.
Tip: When using this with @ref{racket-hash-lang-mode}, you may want
to use @ref{racket-hash-lang-module-language-hook} to enable it IFF
the module langugage is something like ``racket''.
This is a minor mode. If called interactively, toggle the
@code{Racket-Smart-Open-Bracket mode} mode. If the prefix argument is
positive, enable the mode, and if it is zero or negative, disable
the mode.
If called from Lisp, toggle the mode if ARG is @code{toggle}. Enable
the mode if ARG is nil, omitted, or is a positive number.
Disable the mode if ARG is a negative number.
To check whether the minor mode is enabled in the current buffer,
evaluate @ref{racket-smart-open-bracket-mode}.
The mode's hook is called both when the mode is enabled and when
it is disabled.
@node racket-insert-closing
@subsection racket-insert-closing
@kbd{]} or @kbd{)}
Insert a matching closing delimiter.
With @kbd{C-u} insert the typed character as-is.
This is handy if you're not yet using something like
@code{paredit-mode}, @code{smartparens-mode}, @code{parinfer-mode}, or simply
@code{electric-pair-mode} added in Emacs 24.5.
@node racket-cycle-paren-shapes
@subsection racket-cycle-paren-shapes
@kbd{C-c C-p}
Cycle the sexpr among () [] @{@}.
@node racket-backward-up-list
@subsection racket-backward-up-list
@kbd{C-M-u}
Like @code{backward-up-list} but works when point is in a string or comment.
Typically you should not use this command in Emacs Lisp --
especially not repeatedly. Instead, initially use
@code{racket--escape-string-or-comment} to move to the start of a
string or comment, if any, then use normal @code{backward-up-list}
repeatedly.
@node racket-input-mode
@subsection racket-input-mode
@kbd{M-x} @code{racket-input-mode}
A minor mode to enable the ``Racket'' input method.
The Racket input method lets you type @ref{racket-input-prefix},
followed by a key sequence from @ref{racket-input-translations},
directly in a buffer, to insert a symbol.
For example when @ref{racket-input-prefix} is the default ``\'', you
can type ``\All'' and it is immediately replaced with ``∀''.
To enable @ref{racket-input-mode} (and the Racket input method) for
all new buffers, put the following in your Emacs init file:
@lisp
(dolist (hook '(racket-mode-hook
racket-hash-lang-mode-hook
racket-repl-mode-hook))
(add-hook hook #'racket-input-mode))
@end lisp
Tip: You may use the standard Emacs key C-\ to toggle the
current input method.
Tip: If you don’t like the highlighting of partially matching
tokens you can disable that using @code{input-method-highlight-flag}.
See the Emacs manual for other information about input methods.
Tip: Another way to use @ref{racket-input-translations} is by using a
command: @ref{racket-insert-symbol}.
This is a minor mode. If called interactively, toggle the
@code{Racket-Input mode} mode. If the prefix argument is positive,
enable the mode, and if it is zero or negative, disable the mode.
If called from Lisp, toggle the mode if ARG is @code{toggle}. Enable
the mode if ARG is nil, omitted, or is a positive number.
Disable the mode if ARG is a negative number.
To check whether the minor mode is enabled in the current buffer,
evaluate @ref{racket-input-mode}.
The mode's hook is called both when the mode is enabled and when
it is disabled.
@node racket-align
@subsection racket-align
@kbd{M-x} @code{racket-align}
Align values in the same column.
Useful for binding forms like ``let'' and ``parameterize'',
conditionals like ``cond'' and ``match'', association lists, and
any series of couples like the arguments to ``hash''.
Before choosing this command, put point on the first of a series
of ``couples''. A couple is:
@itemize
@item
A list of two or more sexprs: ``[sexpr val sexpr @dots{}]''.
@item
Two sexprs: ``sexpr val''.
@end itemize
Each ``val'' moves to the same column and is
@code{prog-indent-sexp}-ed (in case it is a multi-line form).
For example with point on the ``['' before ``a'':
@example
Before After
(let ([a 12] (let ([a 12]
[bar 23]) [bar 23])
....) ....)
([a . 12] ([a . 12]
[bar . 23]) [bar . 23])
(cond [a? #t] (cond [a? #t]
[b? (f x [b? (f x
y)] y)]
[else #f]) [else #f])
@end example
Or with point on the quote before ``a'':
@example
(list a 12 (list a 12
bar 23) bar 23)
@end example
If more than one couple is on the same line, none are aligned,
because it is unclear where the value column should be. For
example the following form will not change; @ref{racket-align} will
display an error message:
@example
(let ([a 0][b 1]
[c 2]) error; unchanged
....)
@end example
When a couple's sexprs start on different lines, that couple is
ignored. Other, single-line couples in the series are aligned as
usual. For example:
@example
(let ([foo (let ([foo
0] 0]
[bar 1] [bar 1]
[x 2]) [x 2])
....) ....)
@end example
See also: @ref{racket-unalign}.
@node racket-unalign
@subsection racket-unalign
@kbd{M-x} @code{racket-unalign}
The opposite of @ref{racket-align}.
Effectively does M-x @code{just-one-space} and @code{prog-indent-sexp} for
each couple's value.
@node racket-complete-at-point
@subsection racket-complete-at-point
A value for the variable @code{completion-at-point-functions}.
Completion candidates are drawn from the same symbols used for
font-lock. This is a static list. If you want dynamic, smarter
completion candidates, enable the minor mode @ref{racket-xp-mode}.
@node Hash Langs
@section Hash Langs
@menu
* racket-hash-lang-mode::
* racket-hash-lang-backward::
* racket-hash-lang-forward::
* racket-hash-lang-up::
* racket-hash-lang-down::
* racket-hash-lang-C-M-q-dwim::
@end menu
@node racket-hash-lang-mode
@subsection racket-hash-lang-mode
@kbd{M-x} @code{racket-hash-lang-mode}
An ``experimental'' major mode to edit any Racket #lang.
This major mode uses color-lexer, indent, and navigation supplied
by each #lang -- which means Racket Mode's back end process needs
to be running.
In your Emacs configuration, you may want to update the
variable @code{auto-mode-alist} to use @ref{racket-hash-lang-mode} for
file extensions like ``.rkt'', ``.scrbl'', and/or ``.rhm''.
Languages supply colors for lexer tokens like strings and
comments; see the customization variable
@ref{racket-hash-lang-token-face-alist}. For more colors see the hook
variable @ref{racket-hash-lang-module-language-hook}, which can also
be used to vary configurations per language.
A discussion of the information provided by a Racket language:
@uref{https://docs.racket-lang.org/tools/lang-languages-customization.html}
@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
@item Key
@tab Binding
@item @kbd{TAB}
@tab @code{indent-for-tab-command}
@item @kbd{RET}
@tab @code{newline-and-indent}
@item @kbd{C-c C-z}
@tab @code{racket-edit-switch-to-repl}
@item @kbd{C-c C-e x}
@tab @ref{racket-expand-definition}
@item @kbd{C-c C-e f}
@tab @ref{racket-expand-file}
@item @kbd{C-c C-e e}
@tab @ref{racket-expand-last-sexp}
@item @kbd{C-c C-e r}
@tab @ref{racket-expand-region}
@item @kbd{C-c C-f}
@tab @ref{racket-fold-all-tests}
@item @kbd{C-M-q}
@tab @ref{racket-hash-lang-C-M-q-dwim}
@item @kbd{C-M-b}
@tab @ref{racket-hash-lang-backward}
@item @kbd{C-M-d}
@tab @ref{racket-hash-lang-down}
@item @kbd{C-M-f}
@tab @ref{racket-hash-lang-forward}
@item @kbd{C-M-u}
@tab @ref{racket-hash-lang-up}
@item @kbd{C-M-y}
@tab @ref{racket-insert-lambda}
@item @kbd{C-c C-l}
@tab @ref{racket-logger}
@item @kbd{C-c C-x C-f}
@tab @ref{racket-open-require-path}
@item @kbd{C-c C-o}
@tab @ref{racket-profile}
@item @kbd{C-c C-c} or @kbd{C-c C-k}
@tab @ref{racket-run-module-at-point}
@item @kbd{C-M-x}
@tab @ref{racket-send-definition}
@item @kbd{C-x C-e}
@tab @ref{racket-send-last-sexp}
@item @kbd{C-c C-r}
@tab @ref{racket-send-region}
@item @kbd{C-c C-t}
@tab @ref{racket-test}
@item @kbd{C-c C-u}
@tab @ref{racket-unfold-all-tests}
@end multitable
In addition to any hooks its parent mode @code{prog-mode} might have run,
this mode runs the hook @code{racket-hash-lang-mode-hook}, as the final or
penultimate step during initialization.
@node racket-hash-lang-backward
@subsection racket-hash-lang-backward
@kbd{C-M-b}
Like @code{backward-sexp} but uses #lang supplied navigation.
@node racket-hash-lang-forward
@subsection racket-hash-lang-forward
@kbd{C-M-f}
Like @code{forward-sexp} but uses #lang supplied navigation.
@node racket-hash-lang-up
@subsection racket-hash-lang-up
@kbd{C-M-u}
Like @code{backward-up-list} but uses #lang supplied navigation.
@node racket-hash-lang-down
@subsection racket-hash-lang-down
@kbd{C-M-d}
Like @code{down-list} but uses #lang supplied navigation.
@node racket-hash-lang-C-M-q-dwim
@subsection racket-hash-lang-C-M-q-dwim
@kbd{C-M-q}
Fill or indent depending on lang lexer's token at point.
When the lang lexer token is@dots{}
@itemize
@item
``text'', for example in Scribble document text, do
@code{fill-paragraph}.
@item
``comment'', do @code{fill-comment}.
@item
``whitespace'', give an error message.
@item
anything else, do @code{prog-indent-sexp}.
@end itemize
@node Explore
@section Explore
@menu
* racket-xp-mode::
* racket-xp-describe::
* racket-xp-documentation::
* racket-xp-next-definition::
* racket-xp-previous-definition::
* racket-xp-next-use::
* racket-xp-previous-use::
* racket-xp-next-error::
* racket-xp-previous-error::
* racket-xp-tail-up::
* racket-xp-tail-down::
* racket-xp-tail-next-sibling::
* racket-xp-tail-previous-sibling::
* racket-documentation-search::
* racket-describe-mode::
* racket-describe-search::
@end menu
@node racket-xp-mode
@subsection racket-xp-mode
@kbd{M-x} @code{racket-xp-mode}
A minor mode that analyzes expanded code to explain and explore.
This minor mode is an optional enhancement to @ref{racket-mode} edit
buffers. Like any minor mode, you can turn it on or off for a
specific buffer. If you always want to use it, put the following
code in your Emacs init file:
@lisp
(require 'racket-xp)
(add-hook 'racket-mode-hook #'racket-xp-mode)
@end lisp
Note: This mode won't do anything unless/until the Racket Mode
back end is running. It will try to start the back end
automatically. You do @emph{not} need to @ref{racket-run} the buffer you
are editing.
This mode uses the drracket/check-syntax package to analyze
fully-expanded programs, without needing to evaluate a.k.a.
``run'' them. The resulting analysis provides information for:
@itemize
@item
Visually annotating bindings -- local or imported definitions
and references to them.
@item
Visually annotating expressions in a tail position, as well as
the enclosing expression with respect to which they are in a
tail position.
@item
Completion candidates.
@item
Defintions' source and documentation.
@end itemize
When point is on a definition or use, related items are
highlighted using @ref{racket-xp-def-face} and @ref{racket-xp-use-face}
-- instead of drawing arrows as in Dr Racket. Information is
displayed using the function(s) in the hook variable
@ref{racket-show-functions}; it is also available when hovering the
mouse cursor.
Note: If you find these point-motion features too distracting
and/or slow, in your @code{racket-xp-mode-hook} you may disable them:
@lisp
(require 'racket-xp)
(add-hook 'racket-xp-mode-hook
(lambda ()
(remove-hook 'pre-redisplay-functions
#'racket-xp-pre-redisplay
t)))
@end lisp
The remaining features discussed below will still work.
You may also use commands to navigate among a definition and its
uses, or to rename a local definitions and all its uses:
@itemize
@item
@ref{racket-xp-next-definition}
@item
@ref{racket-xp-previous-definition}
@item
@ref{racket-xp-next-use}
@item
@ref{racket-xp-previous-use}
@end itemize
In the following little example, not only does
drracket/check-syntax distinguish the various ``x'' bindings, it
understands the two different imports of ``define'':
@example
#lang racket/base
(define x 1)
x
(let ([x x])
(+ x 1))
(module m typed/racket/base
(define x 2)
x)
@end example
When point is on the opening parenthesis of an expression in tail
position, it is highlighted using the face
@ref{racket-xp-tail-position-face}.
When point is on the opening parenthesis of an enclosing
expression with respect to which one or more expressions are in
tail position, it is highlighted using the face
@ref{racket-xp-tail-target-face}.
Furthermore, when point is on the opening parenthesis of either
kind of expression, all of the immediately related expressions
are also highlighted. Various commands move among them:
@itemize
@item
@ref{racket-xp-tail-up}
@item
@ref{racket-xp-tail-down}
@item
@ref{racket-xp-tail-next-sibling}
@item
@ref{racket-xp-tail-previous-sibling}
@end itemize
The function @code{racket-xp-complete-at-point} is added to the
variable @code{completion-at-point-functions}. Note that in this case,
it is not smart about submodules; identifiers are assumed to be
definitions from the file's module or its imports. In addition to
supplying completion candidates, it supports the
``:company-location'' property to inspect the definition of a
candidate and the ``:company-doc-buffer'' property to view its
documentation.
When you edit the buffer, existing annotations are retained;
their positions are updated to reflect the edit. Annotations for
new or deleted text are not requested until after
@ref{racket-xp-after-change-refresh-delay} seconds. The request is
made asynchronously so that Emacs will not block -- for
moderately complex source files, it can take some seconds simply
to fully expand them, as well as a little more time for the
drracket/check-syntax analysis. When the results are ready, all
annotations for the buffer are completely refreshed.
You may also set @ref{racket-xp-after-change-refresh-delay} to nil
and use the @code{racket-xp-annotate} command manually.
The mode line changes to reflect the current status of
annotations, and whether or not you had a syntax error.
If you have one or more syntax errors, @code{next-error} and
@code{previous-error} navigate among them. Although most languages
will stop after the first syntax error, some like Typed Racket
will try to collect and report multiple errors.
You may use @code{xref-find-definitions} @kbd{M-.} ,
@code{xref-pop-marker-stack} @kbd{M-x} @code{xref-pop-marker-stack}, and
@code{xref-find-references}: @ref{racket-xp-mode} adds a backend to the
variable @code{xref-backend-functions}. This backend uses information
from the drracket/check-syntax static analysis. Its ability to
find references is limited to the current file; when it finds
none it will try the default xref backend implementation which is
grep-based.
Tip: This mode follows the convention that a minor mode may only
use a prefix key consisting of ``C-c'' followed by a punctuation
key. As a result, @code{racket-xp-control-c-hash-keymap} is bound to
``C-c #'' by default. Although you might find this awkward to
type, remember that as an Emacs user, you are free to bind this
map to a more convenient prefix, and/or bind any individual
commands directly to whatever keys you prefer.
@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
@item Key
@tab Binding
@item @kbd{C-c # N}
@tab @code{next-error}
@item @kbd{C-c # P}
@tab @code{previous-error}
@item @kbd{C-c C-s}
@tab @ref{racket-describe-search}
@item @kbd{C-c # g}
@tab @code{racket-xp-annotate}
@item @kbd{C-c C-.}
@tab @ref{racket-xp-describe}
@item @kbd{C-c C-d}
@tab @ref{racket-xp-documentation}
@item @kbd{C-c # j}
@tab @ref{racket-xp-next-definition}
@item @kbd{C-c # n}
@tab @ref{racket-xp-next-use}
@item @kbd{C-c # k}
@tab @ref{racket-xp-previous-definition}
@item @kbd{C-c # p}
@tab @ref{racket-xp-previous-use}
@item @kbd{C-c # r}
@tab @code{racket-xp-rename}
@item @kbd{C-c # v}
@tab @ref{racket-xp-tail-down}
@item @kbd{C-c # >}
@tab @ref{racket-xp-tail-next-sibling}
@item @kbd{C-c # <}
@tab @ref{racket-xp-tail-previous-sibling}
@item @kbd{C-c # ^}
@tab @ref{racket-xp-tail-up}
@item @kbd{M-.} or @kbd{C-c # .}
@tab @code{xref-find-definitions}
@item @kbd{C-c # ?}
@tab @code{xref-find-references}
@end multitable
This is a minor mode. If called interactively, toggle the
@code{Racket-Xp mode} mode. If the prefix argument is positive,
enable the mode, and if it is zero or negative, disable the mode.
If called from Lisp, toggle the mode if ARG is @code{toggle}. Enable
the mode if ARG is nil, omitted, or is a positive number.
Disable the mode if ARG is a negative number.
To check whether the minor mode is enabled in the current buffer,
evaluate @ref{racket-xp-mode}.
The mode's hook is called both when the mode is enabled and when
it is disabled.
@node racket-xp-describe
@subsection racket-xp-describe
@kbd{C-c C-.}
Describe the identifier at point.
The command varies based on how many @kbd{C-u} command prefixes you supply.
@itemize
@item
@kbd{C-c C-.}
Uses the symbol at point. If no such symbol exists, you are
prompted enter the identifier, but in this case it only
considers definitions or imports at the file's module level --
not local bindings nor definitions in submodules.
@itemize
@item
If the identifier has installed Racket documentation, then a
simplified version of the HTML is presented in the buffer,
including the ``blue box'', documentation prose, and
examples.
@item
Otherwise, if the identifier is a function, then its
signature is displayed, for example ``(name arg-1-name
arg-2-name)''.
@end itemize
@item
@kbd{C-u} @kbd{C-c C-.}
Always prompts you to enter a symbol, defaulting to the symbol
at point if any.
@item
@kbd{C-u} @kbd{C-u} @kbd{C-c C-.}
This is an alias for @ref{racket-describe-search}, which uses
installed documentation in a @ref{racket-describe-mode} buffer
instead of an external web browser.
@end itemize
The intent is to give a quick reminder or introduction to
something, regardless of whether it has installed documentation
-- and to do so within Emacs, without switching to a web browser.
This buffer is also displayed when you use @code{company-mode} and
press F1 or C-h in its pop up completion list.
@node racket-xp-documentation
@subsection racket-xp-documentation
@kbd{C-c C-d}
View documentation in an external web browser.
The command varies based on how many @kbd{C-u}
command prefixes you supply.
@itemize
@item
@kbd{C-c C-d}
Uses the symbol at point. Tries to find documentation for an
identifer defined in the expansion of the current buffer.
If no such identifer exists, opens the Search Manuals page. In
this case, the variable @ref{racket-documentation-search-location}
determines whether the search is done locally as with @code{raco
doc}, or visits a URL@.
@item
@kbd{C-u} @kbd{C-c C-d}
Always prompts you to enter a symbol, defaulting to the symbol
at point if any.
@item
@kbd{C-u} @kbd{C-u} @kbd{C-c C-d}
Always prompts you to enter anything, defaulting to the symbol
at point if any.
Proceeds directly to the Search Manuals page. Use this if you
would like to see documentation for all identifiers named
``define'', for example.
@end itemize
@node racket-xp-next-definition
@subsection racket-xp-next-definition
@kbd{C-c # j}
Move point to the next definition.
@node racket-xp-previous-definition
@subsection racket-xp-previous-definition
@kbd{C-c # k}
Move point to the previous definition.
@node racket-xp-next-use
@subsection racket-xp-next-use
@kbd{C-c # n}
When point is on a use, go to the next, sibling use.
@node racket-xp-previous-use
@subsection racket-xp-previous-use
@kbd{C-c # p}
When point is on a use, go to the previous, sibling use.
@node racket-xp-next-error
@subsection racket-xp-next-error
@kbd{M-x} @code{racket-xp-next-error}
An obsolete alias for @code{next-error}.
@node racket-xp-previous-error
@subsection racket-xp-previous-error
@kbd{M-x} @code{racket-xp-previous-error}
An obsolete alias for @code{previous-error}.
@node racket-xp-tail-up
@subsection racket-xp-tail-up
@kbd{C-c # ^}
Go ``up'' to the expression enclosing an expression in tail position.
When point is on the opening parenthesis of an expression in tail
position, go its ``target'' -- that is, go to the enclosing
expression with the same continuation as the tail expression.
@node racket-xp-tail-down
@subsection racket-xp-tail-down
@kbd{C-c # v}
Go ``down'' to the first tail position enclosed by the current expression.
@node racket-xp-tail-next-sibling
@subsection racket-xp-tail-next-sibling
@kbd{C-c # >}
Go to the next tail position sharing the same enclosing expression.
@node racket-xp-tail-previous-sibling
@subsection racket-xp-tail-previous-sibling
@kbd{C-c # <}
Go to the previous tail position sharing the same enclosing expression.
@node racket-documentation-search
@subsection racket-documentation-search
@kbd{C-c C-d}
Search documentation.
This command is useful in several situations:
@itemize
@item
You are not using @ref{racket-xp-mode} for a @ref{racket-mode} edit
buffer, so @ref{racket-xp-documentation} is not available.
@item
There is no @ref{racket-repl-mode} buffer with a live namespace, so
@ref{racket-repl-documentation} is not available or helpful.
@item
You want to search for definitions provided by all modules --
for example, the ``define'' syntax provided by racket/base, by
typed/racket/base, and by other modules, as well definitions or
topics that merely include ``define''.
@end itemize
This command does not try to go directly to the help topic for a
definition provided by any specific module. Instead it goes to
the Racket ``Search Manuals'' page.
@node racket-describe-mode
@subsection racket-describe-mode
@kbd{M-x} @code{racket-describe-mode}
Major mode for viewing Racket documentation.
Many of the default key bindings are similar to @code{Info-mode}, as
listed below.
To see ``On this page'' links, use @kbd{M-g i} for @code{imenu}, or,
when @code{context-menu-mode} is enabled, right click the mouse.
Supports bookmarks: @code{bookmark-set}.
Supports org links: @code{org-store-link}, @code{org-insert-link}, and
@code{org-open-at-point}.
Internal, intra-doc links -- which go to other doc pages in the
same @ref{racket-describe-mode} buffer in Emacs -- are given
@ref{racket-doc-link-face} unless the documentation specifies some
non-default face.
External links -- which are opened using the variable
@ref{racket-browse-url-function}, by default in an external web
browser program -- are given @ref{racket-ext-link-face}.
@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
@item Key
@tab Binding
@item @kbd{<}
@tab @code{beginning-of-buffer}
@item @kbd{>}
@tab @code{end-of-buffer}
@item @kbd{q}
@tab @code{quit-window}
@item @kbd{l} or @kbd{b} or @kbd{C-c C-b}
@tab @code{racket-describe-back}
@item @kbd{x}
@tab @code{racket-describe-browse-external}
@item @kbd{r} or @kbd{f} or @kbd{C-c C-f}
@tab @code{racket-describe-forward}
@item @kbd{n}
@tab @code{racket-describe-nav-next}
@item @kbd{p}
@tab @code{racket-describe-nav-prev}
@item @kbd{C-^}
@tab @code{racket-describe-nav-top}
@item @kbd{^}
@tab @code{racket-describe-nav-up}
@item @kbd{i} or @kbd{C-c C-s}
@tab @ref{racket-describe-search}
@item @kbd{g}
@tab @code{revert-buffer}
@item @kbd{DEL} or @kbd{S-SPC}
@tab @code{scroll-down-command}
@item @kbd{SPC}
@tab @code{scroll-up-command}
@end multitable
In addition to any hooks its parent mode @code{special-mode} might have
run, this mode runs the hook @code{racket-describe-mode-hook}, as the final
or penultimate step during initialization.
@node racket-describe-search
@subsection racket-describe-search
@kbd{C-c C-.} or @kbd{C-c C-s}
Search installed documentation; view using @ref{racket-describe-mode}.
@node Run
@section Run
@menu
* racket-repl-mode::
* racket-run::
* racket-run-and-switch-to-repl::
* racket-run-module-at-point::
* racket-repl::
* racket-repl-describe::
* racket-repl-documentation::
* racket-racket::
* racket-profile::
* racket-profile-mode::
* racket-logger::
* racket-logger-mode::
* racket-debug-mode::
* racket-repl-clear::
* racket-repl-clear-leaving-last-prompt::
@end menu
@node racket-repl-mode
@subsection racket-repl-mode
@kbd{M-x} @code{racket-repl-mode}
Major mode for Racket REPL@.
You may use @code{xref-find-definitions} @kbd{M-.} and
@code{xref-pop-marker-stack} @kbd{M-x} @code{xref-pop-marker-stack}:
@ref{racket-repl-mode} adds a backend to the variable
@code{xref-backend-functions}. This backend uses information about
identifier bindings and modules from the REPL's namespace.
@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
@item Key
@tab Binding
@item @kbd{TAB}
@tab @code{indent-for-tab-command}
@item @kbd{C-j}
@tab @code{newline-and-indent}
@item @kbd{C-M-q}
@tab @code{prog-indent-sexp}
@item @kbd{C-M-u}
@tab @ref{racket-backward-up-list}
@item @kbd{C-c C-s}
@tab @ref{racket-describe-search}
@item @kbd{C-c C-e x}
@tab @ref{racket-expand-definition}
@item @kbd{C-c C-e f}
@tab @ref{racket-expand-file}
@item @kbd{C-c C-e e}
@tab @ref{racket-expand-last-sexp}
@item @kbd{C-c C-e r}
@tab @ref{racket-expand-region}
@item @kbd{)} or @kbd{]} or @kbd{@}}
@tab @ref{racket-insert-closing}
@item @kbd{C-M-y}
@tab @ref{racket-insert-lambda}
@item @kbd{C-c C-l}
@tab @ref{racket-logger}
@item @kbd{C-c C-c}
@tab @code{racket-repl-break}
@item @kbd{C-c C-u}
@tab @code{racket-repl-clear-input}
@item @kbd{C-c C-o}
@tab @code{racket-repl-delete-output}
@item @kbd{C-c C-.}
@tab @ref{racket-repl-describe}
@item @kbd{C-c C-d}
@tab @ref{racket-repl-documentation}
@item @kbd{C-c C-\}
@tab @code{racket-repl-exit}
@item @kbd{M-n}
@tab @code{racket-repl-next-input}
@item @kbd{C-c C-n}
@tab @code{racket-repl-next-prompt-or-run}
@item @kbd{M-p}
@tab @code{racket-repl-previous-input}
@item @kbd{C-c C-p}
@tab @code{racket-repl-previous-prompt-or-run}
@item @kbd{RET}
@tab @code{racket-repl-submit}
@item @kbd{C-c C-z}
@tab @code{racket-repl-switch-to-edit}
@end multitable
This mode runs the hook @code{racket-repl-mode-hook}, as the final or
penultimate step during initialization.
@node racket-run
@subsection racket-run
@kbd{M-x} @code{racket-run}
Save the buffer in REPL and run your program.
As well as evaluating the outermost, file module, automatically
runs the submodules specified by the customization variable
@ref{racket-submodules-to-run}.
See also @ref{racket-run-module-at-point}, which runs just the
specific module at point.
The command varies based on how many @kbd{C-u}
prefix arguments you supply.
@itemize
@item
@kbd{<f5>}
Follows the @ref{racket-error-context} setting.
@item
@kbd{C-u} @kbd{<f5>}
Uses errortrace for improved stack traces, as if
@ref{racket-error-context} were set to ``high''.
This lets you keep @ref{racket-error-context} set to a faster
value like ``low'' or ``medium'', then conveniently re-run
when you need a better strack trace.
@item
@kbd{C-u} @kbd{C-u} @kbd{<f5>}
Instruments code for step debugging. See @ref{racket-debug-mode}
and the variable @ref{racket-debuggable-files}.
@end itemize
Each run occurs within a Racket custodian. Any prior run's
custodian is shut down, releasing resources like threads and
ports. Each run's evaluation environment is reset to the contents
of the source file. In other words, like Dr Racket, this provides
the benefit that your source file is the ``single source of
truth''. At the same time, the run gives you a REPL inside the
namespace of the module, giving you the ability to explore it
interactively. Any explorations are temporary, unless you also
make them to your source file, they will be lost on the next run.
See also @ref{racket-run-and-switch-to-repl}, which is even more like
Dr Racket's Run command because it selects the REPL window after
running.
To visit error locations, move point there and press RET or mouse
click. Or, use the standard @code{next-error} and @code{previous-error}
commands from either the edit or REPL buffer.
@node racket-run-and-switch-to-repl
@subsection racket-run-and-switch-to-repl
@kbd{<f5>}
This is @ref{racket-run} followed by selecting the REPL buffer window.
This is similar to how Dr Racket behaves.
To make it even more similar, you may add @ref{racket-repl-clear} to
the variable @ref{racket-before-run-hook}.
@node racket-run-module-at-point
@subsection racket-run-module-at-point
@kbd{C-c C-k} or @kbd{C-c C-c}
Save the buffer and run the module at point.
Like @ref{racket-run} but runs the innermost module around point,
which is determined textually by looking for ``module'',
``module*'', or ``module+'' forms nested to any depth, else
simply the outermost, file module.
@node racket-repl
@subsection racket-repl
@kbd{M-x} @code{racket-repl}
Show a Racket REPL buffer in some window.
The intended use of Racket Mode's REPL is that you @code{find-file}
some specific file, then run it using a command like @ref{racket-run}
or @ref{racket-run-module-at-point}. The resulting REPL will
correspond to those definitions and match your expectations.
Therefore this @ref{racket-repl} command -- which is intended as a
convenience for people who want to ``just get a quick scratch
REPL'' -- is actually implemented as running the file named in
the customization variable @ref{racket-repl-command-file}. When that
file doesn't exist, it is created to contain just ``#lang
racket/base''. You may edit the file to use a different lang,
require other modules, or whatever.
@node racket-repl-describe
@subsection racket-repl-describe
@kbd{C-c C-.}
Describe the identifier at point.
The command varies based on how many @kbd{C-u} prefix arguments you supply.
@itemize
@item
@kbd{C-c C-.}
Uses the symbol at point. If no such symbol exists, you are
prompted enter the identifier, but in this case it only
considers definitions or imports at the file's module level --
not local bindings nor definitions in submodules.
@itemize
@item
If the identifier has installed Racket documentation, then a
simplified version of the HTML is presented in the buffer,
including the ``blue box'', documentation prose, and
examples.
@item
Otherwise, if the identifier is a function, then its
signature is displayed, for example ``(name arg-1-name
arg-2-name)''.
@end itemize
@item
@kbd{C-u} @kbd{C-c C-.}
Always prompts you to enter a symbol, defaulting to the symbol
at point if any.
@item
@kbd{C-u} @kbd{C-u} @kbd{C-c C-.}
This is an alias for @ref{racket-describe-search}, which uses
installed documentation in a @ref{racket-describe-mode} buffer
instead of an external web browser.
@end itemize
The intent is to give a quick reminder or introduction to
something, regardless of whether it has installed documentation
-- and to do so within Emacs, without switching to a web browser.
@node racket-repl-documentation
@subsection racket-repl-documentation
@kbd{C-c C-d}
View documentation in an external web browser.
The command varies based on how many @kbd{C-u} command prefixes you supply.
@itemize
@item
@kbd{C-c C-d}
Uses the symbol at point. Tries to find documentation for an
identifer defined in the current namespace.
If no such identifer exists, opens the Search Manuals page. In
this case, the variable @ref{racket-documentation-search-location}
determines whether the search is done locally as with @code{raco
doc}, or visits a URL@.
@item
@kbd{C-u} @kbd{C-c C-d}
Prompts you to enter a symbol, defaulting to the symbol at
point if any.
@item
@kbd{C-u} @kbd{C-u} @kbd{C-c C-d}
Prompts you to enter anything, defaulting to the symbol at
point if any.
Proceeds directly to the Search Manuals page. Use this if you
would like to see documentation for all identifiers named
``define'', for example.
@end itemize
@node racket-racket
@subsection racket-racket
@kbd{C-M-<f5>}
Use command-line racket to run the file.
Uses a shell or terminal buffer as specified by the configuration
variable @ref{racket-shell-or-terminal-function}.
@node racket-profile
@subsection racket-profile
@kbd{C-c C-o}
Like @ref{racket-run-module-at-point} but with profiling.
Results are presented in a @ref{racket-profile-mode} buffer, which
also lets you quickly view the source code.
You may evaluate expressions in the REPL@. They are also profiled.
Use @code{racket-profile-refresh} to see the updated results. In
other words a possible workflow is: @ref{racket-profile} a .rkt file,
call one its functions in the REPL, and refresh the profile
results.
Caveat: Only source files are instrumented. You may need to
delete compiled/*.zo files.
@node racket-profile-mode
@subsection racket-profile-mode
@kbd{M-x} @code{racket-profile-mode}
Major mode for results of @ref{racket-profile}.
@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
@item Key
@tab Binding
@item @kbd{q}
@tab @code{quit-window}
@item @kbd{g}
@tab @code{racket-profile-refresh}
@item @kbd{f}
@tab @code{racket-profile-show-non-project}
@item @kbd{z}
@tab @code{racket-profile-show-zero}
@item @kbd{.} or @kbd{RET}
@tab @code{racket-profile-visit}
@end multitable
In addition to any hooks its parent mode @code{tabulated-list-mode} might
have run, this mode runs the hook @code{racket-profile-mode-hook}, as the
final or penultimate step during initialization.
@node racket-logger
@subsection racket-logger
@kbd{C-c C-l}
Create the @ref{racket-logger-mode} buffer.
@node racket-logger-mode
@subsection racket-logger-mode
@kbd{M-x} @code{racket-logger-mode}
Major mode for Racket logger output.
The customization variable @ref{racket-logger-config} determines the
levels for topics. During a session you may change topic levels
using @code{racket-logger-topic-level}.
For more information see:
@uref{https://docs.racket-lang.org/reference/logging.html}
@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
@item Key
@tab Binding
@item @kbd{g}
@tab @code{racket-logger-clear}
@item @kbd{n}
@tab @code{racket-logger-next-item}
@item @kbd{p}
@tab @code{racket-logger-previous-item}
@item @kbd{l}
@tab @code{racket-logger-topic-level}
@item @kbd{w}
@tab @code{toggle-truncate-lines}
@end multitable
In addition to any hooks its parent mode @code{special-mode} might have
run, this mode runs the hook @code{racket-logger-mode-hook}, as the final
or penultimate step during initialization.
@node racket-debug-mode
@subsection racket-debug-mode
@kbd{M-x} @code{racket-debug-mode}
Minor mode for debug breaks.
This feature is @strong{@strong{EXPERIMENTAL}}!!! It is likely to have
significant limitations and bugs. You are welcome to open an
issue to provide feedback. Please understand that this feature
might never be improved -- it might even be removed someday if it
turns out to have too little value and/or too much cost.
How to debug:
@enumerate
@item
``Instrument'' code for step debugging.
Use two @kbd{C-u} command prefixes for either
@ref{racket-run} or @ref{racket-run-module-at-point}.
The file will be instrumented for step debugging before it is
run. Any imported files are also instrumented if they are in
the variable @ref{racket-debuggable-files}.
The run will break at the first breakable position.
Tip: After you run to completion and return to a normal
REPL prompt, the code remains instrumented. You may enter
expressions that evaluate instrumented code and it will
break so you can step debug again.
@item
When a break occurs, the @ref{racket-repl-mode} prompt changes. In
this debug REPL, local variables are available for you to use
and even to @code{set!}.
Also, in the @ref{racket-mode} buffer where the break is located,
@ref{racket-debug-mode} is enabled. This minor mode makes the
buffer read-only, provides visual feedback -- about the break
position, local variable values, and result values -- and
provides shortcut keys:
@end enumerate
@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
@item Key
@tab Binding
@item @kbd{c}
@tab @code{racket-debug-continue}
@item @kbd{g}
@tab @code{racket-debug-go}
@item @kbd{?}
@tab @code{racket-debug-help}
@item @kbd{n}
@tab @code{racket-debug-next-breakable}
@item @kbd{N}
@tab @code{racket-debug-next-breakpoint}
@item @kbd{p}
@tab @code{racket-debug-prev-breakable}
@item @kbd{P}
@tab @code{racket-debug-prev-breakpoint}
@item @kbd{h}
@tab @code{racket-debug-run-to-here}
@item @kbd{SPC}
@tab @code{racket-debug-step}
@item @kbd{u}
@tab @code{racket-debug-step-out}
@item @kbd{o}
@tab @code{racket-debug-step-over}
@item @kbd{!}
@tab @ref{racket-debug-toggle-breakpoint}
@end multitable
This is a minor mode. If called interactively, toggle the
@code{Racket-Debug mode} mode. If the prefix argument is positive,
enable the mode, and if it is zero or negative, disable the mode.
If called from Lisp, toggle the mode if ARG is @code{toggle}. Enable
the mode if ARG is nil, omitted, or is a positive number.
Disable the mode if ARG is a negative number.
To check whether the minor mode is enabled in the current buffer,
evaluate @ref{racket-debug-mode}.
The mode's hook is called both when the mode is enabled and when
it is disabled.
@node racket-repl-clear
@subsection racket-repl-clear
Delete all text in the REPL@.
A suitable value for the hook @ref{racket-before-run-hook} if you
want the REPL buffer to be cleared before each run, much like
with Dr Racket. To do so you can use @code{customize}, or, add to your
Emacs init file something like:
(add-hook 'racket-before-run-hook #'racket-repl-clear)
See also the command @ref{racket-repl-clear-leaving-last-prompt}.
@node racket-repl-clear-leaving-last-prompt
@subsection racket-repl-clear-leaving-last-prompt
@kbd{M-x} @code{racket-repl-clear-leaving-last-prompt}
Delete all text in the REPL, except for the last prompt.
@node Test
@section Test
@menu
* racket-test::
* racket-raco-test::
@end menu
@node racket-test
@subsection racket-test
@kbd{C-<f5>} or @kbd{C-c C-t}
Run the ``test'' submodule.
Put your tests in a ``test'' submodule. For example:
@example
(module+ test
(require rackunit)
(check-true #t))
@end example
Any rackunit test failure messages show the location. You may use
@code{next-error} to jump to the location of each failing test.
With @kbd{C-u} uses errortrace for improved stack traces.
Otherwise follows the @ref{racket-error-context} setting.
With @kbd{C-u} @kbd{C-u} also runs the
tests with coverage instrumentation and highlights uncovered code
using @code{font-lock-warning-face}.
See also:
@itemize
@item
@ref{racket-fold-all-tests}
@item
@ref{racket-unfold-all-tests}
@end itemize
@node racket-raco-test
@subsection racket-raco-test
@kbd{M-x} @code{racket-raco-test}
Use command-line raco test to run the ``test'' submodule.
Uses a shell or terminal buffer as specified by the configuration
variable @ref{racket-shell-or-terminal-function}.
@node Eval
@section Eval
@menu
* racket-send-region::
* racket-send-definition::
* racket-send-last-sexp::
@end menu
@node racket-send-region
@subsection racket-send-region
@kbd{C-c C-r}
Send the current region (if any) to the Racket REPL@.
See the customization variable @ref{racket-repl-echo-sent-expressions}.
@node racket-send-definition
@subsection racket-send-definition
@kbd{C-M-x}
Send the current definition to the Racket REPL@.
See the customization variable @ref{racket-repl-echo-sent-expressions}.
@node racket-send-last-sexp
@subsection racket-send-last-sexp
@kbd{C-x C-e}
Send the expression before point to the Racket REPL@.
The expression may be either an at-expression or an s-expression.
When the expression is a sexp comment, the sexp itself is sent,
without the #; prefix.
See the customization variable @ref{racket-repl-echo-sent-expressions}.
@node Collections
@section Collections
@menu
* racket-open-require-path::
@end menu
@node racket-open-require-path
@subsection racket-open-require-path
@kbd{C-c C-x C-f}
Like Dr Racket's Open Require Path.
Type (or delete) characters that are part of a module path name.
``Fuzzy'' matches appear. For example try typing ``t/t/r''.
Choices are displayed in a vertical list. The current choice is
at the top, marked with ``->''.
@itemize
@item
C-n and C-p move among the choices.
@item
RET on a directory adds its contents to the choices.
@item
RET on a file exits doing @code{find-file}.
@item
C-g aborts.
@end itemize
@node Macro expand
@section Macro expand
@menu
* racket-stepper-mode::
* racket-expand-file::
* racket-expand-region::
* racket-expand-definition::
* racket-expand-last-sexp::
@end menu
@node racket-stepper-mode
@subsection racket-stepper-mode
@kbd{M-x} @code{racket-stepper-mode}
Major mode for Racket stepper output.
Used by the commands @ref{racket-expand-file},
@ref{racket-expand-definition}, @ref{racket-expand-region}, and
@ref{racket-expand-last-sexp}.
@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
@item Key
@tab Binding
@item @kbd{n} or @kbd{j}
@tab @code{racket-stepper-next-item}
@item @kbd{p} or @kbd{k}
@tab @code{racket-stepper-previous-item}
@item @kbd{g}
@tab @code{racket-stepper-refresh}
@item @kbd{RET}
@tab @code{racket-stepper-step}
@end multitable
In addition to any hooks its parent mode @code{special-mode} might have
run, this mode runs the hook @code{racket-stepper-mode-hook}, as the final
or penultimate step during initialization.
@node racket-expand-file
@subsection racket-expand-file
@kbd{C-c C-e f}
Expand the @ref{racket-mode} buffer's file in @ref{racket-stepper-mode}.
Uses the @code{macro-debugger} package to do the expansion.
You do not need to @ref{racket-run} the file first; the namespace
active in the REPL is not used.
If the file is non-trivial and/or is not compiled to a .zo
bytecode file, then it might take many seconds before the
original form is displayed and you can start stepping.
With @kbd{C-u} behaves as if @ref{racket-expand-hiding}
were 'disabled.
@node racket-expand-region
@subsection racket-expand-region
@kbd{C-c C-e r}
Expand the active region using @ref{racket-stepper-mode}.
Uses the @code{macro-debugger} package to do the expansion.
With @kbd{C-u} behaves as if @ref{racket-expand-hiding}
were 'disabled.
@node racket-expand-definition
@subsection racket-expand-definition
@kbd{C-c C-e x}
Expand the definition around point using @ref{racket-stepper-mode}.
Uses the @code{macro-debugger} package to do the expansion.
With @kbd{C-u} behaves as if @ref{racket-expand-hiding}
were 'disabled.
@node racket-expand-last-sexp
@subsection racket-expand-last-sexp
@kbd{C-c C-e e}
Expand the sexp before point using @ref{racket-stepper-mode}.
Uses the @code{macro-debugger} package to do the expansion.
With @kbd{C-u} behaves as if @ref{racket-expand-hiding}
were 'disabled.
@node Packages
@section Packages
@menu
* racket-package-refresh::
* list-racket-packages::
* racket-package-mode::
* describe-racket-package::
@end menu
@node racket-package-refresh
@subsection racket-package-refresh
@kbd{M-x} @code{racket-package-refresh}
Refresh the local copy of package catalogs.
Will make HTTP requests to remote catalog servers. May take a few
seconds to complete.
@node list-racket-packages
@subsection list-racket-packages
@kbd{M-x} @code{list-racket-packages}
Open a @ref{racket-package-mode} buffer for the active back end.
@node racket-package-mode
@subsection racket-package-mode
@kbd{M-x} @code{racket-package-mode}
Major mode for Racket package management.
The list of packages is equivalent to ``raco pkg show -all'' on
the active back end -- that is, all packages installed manually
or as dependencies -- plus packages available from your
configured catalogs, assuming you have run the command
@ref{racket-package-refresh}.
On each row you can press RET to @code{describe-racket-package}, which
opens a buffer where you can view details, and use buttons to
install/update/remove the package.
@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaa}
@item Key
@tab Binding
@item @kbd{RET}
@tab @code{racket-package-describe}
@end multitable
In addition to any hooks its parent mode @code{tabulated-list-mode} might
have run, this mode runs the hook @code{racket-package-mode-hook}, as the
final or penultimate step during initialization.
@node describe-racket-package
@subsection describe-racket-package
@kbd{M-x} @code{describe-racket-package}
Describe details of a Racket package.
Depending on the package status, buttons let you install, update,
and/or remove the package and its dependencies. These convenience
buttons are equivalent to using the command line on the active
back end to do ``raco pkg @{install update remove@} --auto''. For
other operations, you still need to use ``raco pkg'' yourself;
see @uref{https://docs.racket-lang.org/pkg/cmdline.html}.
Detail values are links when possible:
@itemize
@item
The @emph{Catalog} (when ``@uref{https://pkgs.racket-lang.org}'') links to
the package's web page, which may have additional details not
available locally.
@item
The @emph{Source} links to the repo's web page or local filesystem.
@item
The @emph{Directory} for an installed package opens a dired buffer.
@item
Each @emph{Dependencies} name links to details about that package.
@item
For installed packages, each @emph{Modules} item links to the local
file. There is also a button to each module's locally installed
documentation, if any.
@end itemize
If the package is available from a catalog, additional details
will be shown, assuming you have run the command
@ref{racket-package-refresh}.
@node Other
@section Other
@menu
* racket-debug-toggle-breakpoint::
* racket-mode-start-faster::
* racket-mode-start-slower::
@end menu
@node racket-debug-toggle-breakpoint
@subsection racket-debug-toggle-breakpoint
@kbd{M-x} @code{racket-debug-toggle-breakpoint}
Add or remove a breakpoint.
Each breakpoint has a condition and a list of actions.
The condition is a Racket expression that is evaluated in a
context where local variables exist. Examples:
@itemize
@item
``#t'' means break always.
@item
If the code around the breakpoint is something like
``(for ([n 100]) _)'', then a condition like
``(zero? (modulo n 10))'' is every 10 times through the
loop.
@end itemize
Actions is a list of symbols; you may specify one or more. The
action symbols are:
@itemize
@item
``break'' causes a break, enabling @ref{racket-debug-mode}.
@item
``log'' and ``print'' display information about local
variables to the logger or REPL output, respectively.
Although @ref{racket-debug-mode} already shows these values ``in
situ'' when you reach a break, this may be useful if you want
a history. Specifying ``log'' or ``print'', but not
``break'', is equivalent to what many debuggers call a
watchpoint instead of a breakpoint: Output some information
and automatically resume.
@end itemize
Note: Although @ref{racket-debug-mode} provides a convenient
keybinding, you may invoke this command anytime using M-x.
Note: If you're warned that point isn't known to be a breakable
position, that might be because it truly isn't, or, just because
you are not in @ref{racket-debug-mode} and the breakable positions
aren't yet known. Worst case, if you set a breakpoint someplace
that is not breakable, it is ignored. With a few exceptions --
such as close paren positions that are tail calls -- most open
parens and close parens are breakble positions.
@node racket-mode-start-faster
@subsection racket-mode-start-faster
@kbd{M-x} @code{racket-mode-start-faster}
Compile Racket Mode's .rkt files for faster startup.
Racket Mode is implemented as an Emacs Lisp ``front end'' that
talks to a Racket process ``back end''. Because Racket Mode is
delivered as an Emacs package instead of a Racket package,
installing it does not do the @code{raco setup} that is normally done
for Racket packages.
This command will do a @code{raco make} of Racket Mode's .rkt files,
creating bytecode files in @code{compiled/} subdirectories. As a
result, when a command must start the Racket process, it will
start somewhat faster.
On many computers, the resulting speed up is negligible, and
might not be worth the complication.
If you run this command, ever, you will need to run it again
after:
@itemize
@item
Installing an updated version of Racket Mode. Otherwise, you
might lose some of the speed-up.
@item
Installing a new version of Racket and/or changing the value of
the variable @ref{racket-program}. Otherwise, you might get an
error message due to the bytecode being different versions.
@end itemize
To revert to compiling on startup, use
@ref{racket-mode-start-slower}.
@node racket-mode-start-slower
@subsection racket-mode-start-slower
@kbd{M-x} @code{racket-mode-start-slower}
Delete the ``compiled'' directories made by @ref{racket-mode-start-faster}.
@node Variables
@chapter Variables
@menu
* General variables::
* Hash lang variables::
* REPL variables::
* Other variables::
* Experimental debugger variables::
* Showing information::
* Running racket and raco commands in a shell or terminal::
* Racket input method::
@end menu
@node General variables
@section General variables
@menu
* racket-program::
* racket-command-timeout::
* racket-memory-limit::
* racket-error-context::
* racket-user-command-line-arguments::
* racket-browse-url-function::
* racket-xp-after-change-refresh-delay::
* racket-xp-highlight-unused-regexp::
* racket-xp-add-binding-faces::
* racket-xp-eldoc-level::
* racket-documentation-search-location::
* racket-expand-hiding::
@end menu
@node racket-program
@subsection racket-program
Pathname of the Racket executable or command line to launch it.
@itemize
@item
If the value of this variable is a string, it will be interpreted as a
simple command without arguments.
@item
If it is a list of strings, the first element will be taken to be the
executable, and the rest of the list command line arguments to pass to
it before any other arguments.
@end itemize
Note that a back end configuration can override this with a
non-nil @code{racket-program} property list value. See
@ref{racket-add-back-end}.
@node racket-command-timeout
@subsection racket-command-timeout
How many seconds to wait for command server responses.
Note: This is mostly obsolete, fortunately, because it applies
only to commands that must block the Emacs UI until they get a
response. Instead most Racket Mode commands these days receive
their response asychronously.
@node racket-memory-limit
@subsection racket-memory-limit
Terminate the Racket process if memory use exceeds this value in MB@.
Changes to this value take effect upon the next @ref{racket-run}. A value
of 0 means no limit.
Caveat: This uses Racket's @code{custodian-limit-memory}, which does
not enforce the limit exactly. Instead, the program will be
terminated upon the first garbage collection where memory exceeds
the limit (maybe by a significant amount).
@node racket-error-context
@subsection racket-error-context
The amount of context for error messages.
Each increasing level supplies better context (``stack trace'')
for error messages, but causing your program to run more slowly.
@itemize
@item
low corresponds to compile-enforce-module-constants #t and
compile-context-preservation-enabled #f.
@item
medium corresponds to compile-enforce-module-constants #f and
compile-context-preservation-enabled #t, which disables some
optimizations like inlining.
@item
high corresponds to medium plus the use of errortrace, which
extensively instruments your code and therefore might cause
it to run significantly slower.
@end itemize
Tip: Regardless of this setting, you can enable high errortrace
for a specific @ref{racket-run} or @ref{racket-run-module-at-point} by
using @kbd{C-u} . This lets you normally run with a
lower, faster setting, and re-run when desired to get a
more-helpful error message.
@node racket-user-command-line-arguments
@subsection racket-user-command-line-arguments
List of command-line arguments to supply to your Racket program.
Accessible in your Racket program in the usual way --- the
parameter @code{current-command-line-arguments} and friends.
This is an Emacs buffer-local variable --- convenient to set as a
file local variable. For example at the end of your .rkt file:
@lisp
;; Local Variables:
;; racket-user-command-line-arguments: ("-f" "bar")
;; End:
@end lisp
Set this way, the value must be an @strong{unquoted} list of strings.
For example:
@lisp
("-f" "bar")
@end lisp
The following values will @emph{not} work:
@lisp
'("-f" "bar")
(list "-f" "bar")
@end lisp
@node racket-browse-url-function
@subsection racket-browse-url-function
Function to call to browse a URL@.
Defaults to @ref{racket-browse-url-using-temporary-file} on macOS and
@code{browse-url-browser-function} on other platforms.
@node racket-xp-after-change-refresh-delay
@subsection racket-xp-after-change-refresh-delay
Seconds to wait before refreshing @ref{racket-xp-mode} annotations.
Set to nil to disable automatic refresh and manually use @code{racket-xp-annotate}.
@node racket-xp-highlight-unused-regexp
@subsection racket-xp-highlight-unused-regexp
Only give @ref{racket-xp-unused-face} to unused bindings that match this regexp.
The default is to highlight identifiers that do not start with
an underline, which is a common convention.
@node racket-xp-add-binding-faces
@subsection racket-xp-add-binding-faces
Have @ref{racket-xp-mode} fontify binding identifier sites.
A 'font-lock-face property is added for bindings from:
@itemize
@item
the module language, using @ref{racket-xp-binding-lang-face} and
@ref{racket-xp-binding-lang-use-face}.
@item
other imports, using @ref{racket-xp-binding-import-face} and
@ref{racket-xp-binding-import-use-face}.
@item
local definitions, using @ref{racket-xp-binding-local-face} and
@ref{racket-xp-binding-local-use-face}.
@end itemize
This has a visible effect only when there is @emph{not} also a
'face property applied by the major mode's fontification.
@node racket-xp-eldoc-level
@subsection racket-xp-eldoc-level
How much documentation to show via @code{eldoc}.
Used by @code{racket-xp-eldoc-point} and @code{racket-xp-eldoc-sexp-app}.
@itemize
@item
Minimal: Only the help-echo string.
@item
Summary: Also the signature a.k.a. ``blubox'' from the
documentation.
@item
Complete: Also the complete prose documentation.
@end itemize
A third-party package like @code{eldoc-box} can be useful for all but
the minimal level. Even some bluebox signatures can take many
lines to show on screen.
@node racket-documentation-search-location
@subsection racket-documentation-search-location
The location of the Racket ``Search Manuals'' web page.
Where @ref{racket-documentation-search}, @ref{racket-xp-documentation}
and @ref{racket-repl-documentation} should look for the search page.
@itemize
@item
If the value of this variable is the symbol ``local'', open the
search page from the local documentation, as with ``raco doc''.
@item
Otherwise, the value is a string recognizable by @code{format}, with
``%s'' at the point at which to insert the user's search text
after applying @code{url-hexify-string}. Apart from ``%s'', the
string should be a properly encoded URL@.
@end itemize
@node racket-expand-hiding
@subsection racket-expand-hiding
The macro hiding policy for commands like @ref{racket-expand-file}.
@node Hash lang variables
@section Hash lang variables
@menu
* racket-hash-lang-token-face-alist::
* racket-hash-lang-module-language-hook::
@end menu
@node racket-hash-lang-token-face-alist
@subsection racket-hash-lang-token-face-alist
An association list from color-lexer token symbols to face symbols.
Note: In many Racket languages, the lexer classifies tokens for
identifiers as 'symbol. In many programs, a majority of the
source consists of identifiers at binding definition and use
sites. Therefore the appearance of ``symbol'' tokens is
significant, and a matter of personal preference.
@itemize
@item
If you prefer a ``plainer'' appearance, similar to Dr Racket:
Add 'symbol with the value 'default. This gives an
explicit 'face property that prevails over any
'font-lock-face property that a minor mode might apply to
enhance the basic fontification.
@item
If you prefer a more ``colorful'' appearance, similar to
``classic'' @ref{racket-mode}: Do @emph{not} map 'symbol tokens in
this list. See @ref{racket-hash-lang-module-language-hook} for
ideas.
@end itemize
Note: Some tokens are hardwired and not customizable by this
list: Comment tokens use the face @code{font-lock-comment-face},
sometimes blended with other faces. Parenthesis tokens use the
face @code{parenthesis} if defined, as by the paren-face package.
String tokens use @code{font-lock-string-face}. Text tokens, e.g.
Scribble text, use the face @ref{racket-hash-lang-text}.
@node racket-hash-lang-module-language-hook
@subsection racket-hash-lang-module-language-hook
Hook run when the module language changes.
Typically in Emacs each language gets its own major mode. As a
result, the major mode hook is your opportunity to express
preferences. However @ref{racket-hash-lang-mode} handles radically
different kinds of hash langs in one major mode. And a given
buffer can change langs when you edit the ``#lang'' line. As a
result, @code{racket-hash-lang-mode-hook} is not useful for per-lang
configuration. Instead you need a kind of ``sub major mode
hook''. This is that hook.
The hook is run when a file is first visited, and thereafter
whenever the ``#lang'' line is edited -- provided that results in
different language info; for example changing from ``#lang
racket'' to ``#lang racket/base'' will @emph{not} run the hook.
The function is called with a string returned by the lang's
``module-language'' info key. This info key is supplied
automatically when a language is defined using
syntax/module-reader:
@uref{https://docs.racket-lang.org/syntax/reader-helpers.html#%28mod-path._syntax%2Fmodule-reader%29}.
Otherwise a lang might not supply this and the value will be nil.
The hook is useful when you want to vary Emacs behavior in ways
that go beyond what a lang can describe. This may include
enabling ``fancy'' or ``classic'' Emacs behaviors only for
s-expression langs.
For example, maybe you want to use @code{paredit-mode} when it is
suitable for the module language, else @code{electric-pair-local-mode}:
@lisp
(defun my-hook (module-language)
(let ((rackety
(member module-language
(list "racket" "racket/base"
"typed/racket" "typed/racket/base"))))
(electric-pair-local-mode (if rackety -1 1))
(paredit-mode (if rackety 1 -1))))
(add-hook 'racket-hash-lang-module-language-hook #'my-hook)
@end lisp
A similar tactic can be used for @code{smartparens}. In general,
neither of these modes is likely to work well unless the
hash-lang uses racket for drracket:grouping-position, in which
case @ref{racket-hash-lang-mode} uses the classic @ref{racket-mode}
syntax-table for the buffer. Otherwise you should not enable one
of these modes, and instead just use the simple delimiter
matching of @code{electric-pair-local-mode}, as configured by
@ref{racket-hash-lang-mode}.
As another example, if you prefer more colors than just tokens,
choices include:
@itemize
@item
Enable @ref{racket-xp-mode} in @code{racket-hash-lang-mode-hook} and in
the module language hook locally set
@ref{racket-xp-add-binding-faces}:
@end itemize
@lisp
(setq-local racket-xp-add-binding-faces t)
@end lisp
OR
@itemize
@item
Use some of the regexp search-based fontification from classic
@ref{racket-mode} for rackety module languages:
@end itemize
@lisp
(require 'racket-font-lock)
(if rackety
(font-lock-add-keywords nil
(append racket-font-lock-keywords-2
racket-font-lock-keywords-3))
(font-lock-remove-keywords nil
(append racket-font-lock-keywords-2
racket-font-lock-keywords-3)))
@end lisp
@node REPL variables
@section REPL variables
@menu
* racket-repl-buffer-name-function::
* racket-submodules-to-run::
* racket-repl-history-directory::
* racket-history-filter-regexp::
* racket-images-inline::
* racket-imagemagick-props::
* racket-images-keep-last::
* racket-images-system-viewer::
* racket-images-do-not-use-svg::
* racket-pretty-print::
* racket-repl-command-file::
* racket-repl-echo-sent-expressions::
@end menu
@node racket-repl-buffer-name-function
@subsection racket-repl-buffer-name-function
How to associate @ref{racket-mode} edit buffers with @ref{racket-repl-mode} buffers.
The default is nil, which is equivalent to supplying
@ref{racket-repl-buffer-name-shared}: One REPL buffer is shared.
Other predefined choices include @ref{racket-repl-buffer-name-unique}
and @ref{racket-repl-buffer-name-project}.
This is used when a @ref{racket-mode} buffer is created. Changing
this to a new value only affects @ref{racket-mode} buffers created
later.
Any such function takes no arguments, should look at the variable
@code{buffer-file-name} if necessary, and either @code{setq-default} or
@code{setq-local} the variable @code{racket-repl-buffer-name} to a desired
@ref{racket-repl-mode} buffer name. As a result, @ref{racket-run}
commands will use a buffer of that name, creating it if
necessary.
@node racket-submodules-to-run
@subsection racket-submodules-to-run
Extra submodules to run.
This is a list of submodules. Each submodule is described as a
list, to support submodules nested to any depth.
This is used by commands that emulate the DrRacket Run command:
@itemize
@item
@ref{racket-run}
@item
@ref{racket-run-and-switch-to-repl} @kbd{<f5>}
@end itemize
It is NOT used by commands that run one specific module, such as:
@itemize
@item
@ref{racket-run-module-at-point} @kbd{C-c C-k} or @kbd{C-c C-c}
@item
@ref{racket-test} @kbd{C-<f5>} or @kbd{C-c C-t}
@item
@ref{racket-profile}
@end itemize
@node racket-repl-history-directory
@subsection racket-repl-history-directory
Directory for @ref{racket-repl-mode} history files.
@node racket-history-filter-regexp
@subsection racket-history-filter-regexp
Input matching this regexp are NOT saved on the history list.
Default value is a regexp to ignore input that is all whitespace.
@node racket-images-inline
@subsection racket-images-inline
Whether to display inline images in the REPL@.
@node racket-imagemagick-props
@subsection racket-imagemagick-props
Use ImageMagick with these properties for REPL images.
When this property list is not empty -- and the variable
@ref{racket-images-inline} is true, and Emacs is built with with
ImageMagick support -- then @code{create-image} is called with
``imagemagick'' as the type and with this property list.
For example, to scale images whose width is larger than 500
pixels, supply (:max-width 500).
@node racket-images-keep-last
@subsection racket-images-keep-last
How many images to keep in the image cache.
@node racket-images-system-viewer
@subsection racket-images-system-viewer
The image viewer program to use for @code{racket-view-image}.
@node racket-images-do-not-use-svg
@subsection racket-images-do-not-use-svg
Do not use SVG to render images?
Note: This value is used only when starting a back end -- @emph{not}
for each run. If you change this, for it to take effect you must
restart by using @code{racket-start-back-end}.
@node racket-pretty-print
@subsection racket-pretty-print
Use pretty-print instead of plain print?
When true, before each run set global-port-print-handler to use
pretty-print from racket/pretty, which is suitable for
s-expressions.
Note: A configure-runtime submodule might replace this initial
value with its own global port print handler -- for example to
implement printing a non-s-expression syntax.
@node racket-repl-command-file
@subsection racket-repl-command-file
Name of the file used by @ref{racket-repl}.
@node racket-repl-echo-sent-expressions
@subsection racket-repl-echo-sent-expressions
Should commands that send an expresion to the REPL echo it there?
The echoed expression and `` => '' are displayed using the face
@ref{racket-repl-message} to distinguish them from result values.
Affects @ref{racket-send-last-sexp}, @ref{racket-send-region}, and
@ref{racket-send-definition}.
@node Other variables
@section Other variables
@menu
* racket-doc-index-directory::
* racket-doc-index-predicate-function::
* racket-indent-curly-as-sequence::
* racket-indent-sequence-depth::
* racket-pretty-lambda::
* racket-smart-open-bracket-enable::
* racket-logger-config::
* racket-before-run-hook::
* racket-after-run-hook::
* racket-sexp-comment-fade::
@end menu
@node racket-doc-index-directory
@subsection racket-doc-index-directory
Directory for @ref{racket-describe-search} doc index files.
@node racket-doc-index-predicate-function
@subsection racket-doc-index-predicate-function
A function used by @ref{racket-describe-search} to filter results.
The default value, the @code{always} function, filters nothing.
The function is given four string arguments -- TERM, WHAT,
FROM-LIBS, and FAMILIES -- and should return whether to include
the item in the list of completion candidates. An example that
limits candidates to the ``Rhombus'' family:
(lambda (@math{_term} _what _from-libs families)
(string-equal families ``Rhombus'')
@node racket-indent-curly-as-sequence
@subsection racket-indent-curly-as-sequence
Indent @code{@{@}} with items aligned with the head item?
This is indirectly disabled if @ref{racket-indent-sequence-depth} is 0.
This is safe to set as a file-local variable.
@node racket-indent-sequence-depth
@subsection racket-indent-sequence-depth
To what depth should @ref{racket-indent-line} search.
This affects the indentation of forms like '() `() #() --
and @{@} if @ref{racket-indent-curly-as-sequence} is t --- but not
#'() #`() ,() ,@@(). A zero value disables, giving the
normal indent behavior of DrRacket or Emacs @code{lisp-mode} derived
modes like @code{scheme-mode}. Setting this to a high value can make
indentation noticeably slower. This is safe to set as a
file-local variable.
@node racket-pretty-lambda
@subsection racket-pretty-lambda
Display lambda keywords using λ. This is DEPRECATED@.
Instead use @code{prettify-symbols-mode} in newer verisons of Emacs,
or, use @ref{racket-insert-lambda} to insert actual λ characters.
@node racket-smart-open-bracket-enable
@subsection racket-smart-open-bracket-enable
This variable is obsolete and has no effect.
Instead of using this variable, you may bind the @code{[} key to the
@code{racket-smart-open-bracket} command in the @code{racket-mode-map}
and/or @code{racket-repl-mode-map} keymaps.
@node racket-logger-config
@subsection racket-logger-config
Configuration of @ref{racket-logger-mode} topics and levels.
The topic ``*'' respresents the default level used for topics not
assigned a level. Otherwise, the topic symbols are the same as
used by Racket's @code{define-logger}.
The levels are those used by Racket's logging system: ``debug'',
``info'', ``warning'', ``error'', ``fatal''.
For more information see:
@uref{https://docs.racket-lang.org/reference/logging.html}
The default value sets some known ``noisy'' topics to be one
level quieter. That way you can set the ``*'' topic to a level
like ``debug'' and not get overhwelmed by these noisy topics.
@node racket-before-run-hook
@subsection racket-before-run-hook
Normal hook done before various Racket Mode run commands.
Here ``before'' means that the @ref{racket-repl-mode} buffer might not
exist yet.
When hook functions are called, @code{current-buffer} is that of the
edit buffer when the run command was issued. If a hook function
instead needs the @ref{racket-repl-mode} buffer, it should get that
from the variable @code{racket-repl-buffer-name}.
@node racket-after-run-hook
@subsection racket-after-run-hook
Normal hook done after various Racket Mode run commands.
Here ``after'' means that the run has completed and the REPL is
waiting at another prompt.
When hook functions are called, @code{current-buffer} is that of the
buffer when the run command was issued. If a hook function
instead needs the @ref{racket-repl-mode} buffer, it should get that
from the variable @code{racket-repl-buffer-name}.
@node racket-sexp-comment-fade
@subsection racket-sexp-comment-fade
How much to fade faces used in s-expression comment bodies.
A number from 0.0 to 1.0, where 0.0 is 0% fade and 1.0 is 100%
fade (invisible).
This feature works by creating faces that are alternatives for
faces used in s-expression comments. The alernative faces use a
faded foreground color. The colors are recalculated automatically
after you change the value of this customization variable and
after any @code{load-theme}. However in other circumstances you might
need to use @code{racket-refresh-sexp-comment-faces}.
@node Experimental debugger variables
@section Experimental debugger variables
@menu
* racket-debuggable-files::
@end menu
@node racket-debuggable-files
@subsection racket-debuggable-files
Used to tell @ref{racket-run} what files may be instrumented for debugging.
This isn't yet a defcustom becuase the debugger status is still
``experimental''.
Must be either a list of file name strings, or, a function that
takes the name of the file being run and returns a list of file
names.
Each file name in the list is made absolute using
@code{expand-file-name} with respect to the file being run and given
to @code{racket-file-name-front-to-back}.
@node Showing information
@section Showing information
@menu
* racket-show-functions::
@end menu
@node racket-show-functions
@subsection racket-show-functions
An ``abnormal hook'' variable to customize @code{racket-show}.
This is a list of one or more functions.
Each such function must accept two arguments: STR and POS@.
STR is one of:
@itemize
@item
Non-blank string: Display the string somehow.
@item
Blank string: Hide any previously displayed string.
@item
nil: Hide any persistent UI that might have been created. For
instance @ref{racket-show-header-line} hides the header line.
@end itemize
POS may be nil when STR is nil or a blank string.
Otherwise POS is the buffer position -- typically the end of a
span -- that the non-blank STR describes.
A function that shows STR near POS should position it not to hide
the span, i.e. below and/or right of POS@. Examples:
@ref{racket-show-pseudo-tooltip} and @ref{racket-show-pos-tip}.
A function that shows STR in a fixed location may of course
ignore POS@. Examples: @ref{racket-show-echo-area} and
@ref{racket-show-header-line}
@node Running racket and raco commands in a shell or terminal
@section Running racket and raco commands in a shell or terminal
@menu
* racket-shell-or-terminal-function::
@end menu
@node racket-shell-or-terminal-function
@subsection racket-shell-or-terminal-function
How @ref{racket-racket} and @ref{racket-raco-test} run commands.
The function should accept a command string, not including a
newline, get or create a suitable buffer, send the command, and
send a newline or enter.
Predefined choices include @ref{racket-shell}, @ref{racket-term},
@ref{racket-ansi-term}, and @ref{racket-vterm}.
@node Racket input method
@section Racket input method
@menu
* racket-input-prefix::
* racket-input-translations::
@end menu
@node racket-input-prefix
@subsection racket-input-prefix
A prefix used by the ``Racket'' input method.
This string is prepended to the key sequence strings in
@ref{racket-input-translations}, when setting up the input method.
Using some non-nil, non-blank prefix avoids conflicts between key
sequences and portions of normal words. For example ``oint''
would insert ``∮'' while you're typing ``point'' -- but not
``\oint''.
If you change this setting manually with @code{setq} (instead of using
the customization buffer or @code{setopt}) you need to call
@code{racket-input-setup} in order for the change to take effect.
@node racket-input-translations
@subsection racket-input-translations
A list of translations.
Each element is (KEY-SEQUENCE-STRING TRANSLATION-STRING).
Used by the ``Racket'' input method activated by
@ref{racket-input-mode}, as well as by the @ref{racket-insert-symbol}
command.
If you change this setting manually with @code{setq} (instead of using
the customization buffer or @code{setopt}) you need to call
@code{racket-input-setup} in order for the change to take effect.
@node Configuration functions
@chapter Configuration functions
@menu
* Showing information: Showing information (1).
* Associating edit buffers with REPL buffers::
* Browsing file URLs with anchors::
* Configuring back ends::
* Running racket and raco commands in a shell or terminal: Running racket and raco commands in a shell or terminal (1).
@end menu
@node Showing information (1)
@section Showing information
@menu
* racket-show-pseudo-tooltip::
* racket-show-echo-area::
* racket-show-header-line::
* racket-show-pos-tip::
@end menu
@node racket-show-pseudo-tooltip
@subsection racket-show-pseudo-tooltip
@code{(racket-show-pseudo-tooltip str &optional pos)}
Show using an overlay that resembles a tooltip.
This is nicer than @ref{racket-show-pos-tip} because it:
@itemize
@item
Doesn't flicker while navigating.
@item
Doesn't disappear after a timeout.
@item
Performs well when @code{x-gtk-use-system-tooltips} is nil.
@end itemize
On the other hand, this does not look as nice when displaying
text that spans multiple lines or is too wide to fit the window.
In that case, we simply left-justify everything and do not draw
any border.
@node racket-show-echo-area
@subsection racket-show-echo-area
@code{(racket-show-echo-area str &optional _pos)}
Show things in the echo area.
A value for the variable @ref{racket-show-functions}.
This does @emph{not} add STR to the ``@strong{Messages}'' log buffer.
@node racket-show-header-line
@subsection racket-show-header-line
@code{(racket-show-header-line str &optional _pos)}
Show things using a buffer header line.
A value for the variable @ref{racket-show-functions}.
When there is nothing to show, keep a blank header-line. That
way, the buffer below doesn't ``jump up and down'' by a line as
messages appear and disappear. Only when V is nil do we remove
the header line.
@node racket-show-pos-tip
@subsection racket-show-pos-tip
@code{(racket-show-pos-tip str &optional pos)}
Show things using @code{pos-tip-show} if available.
A value for the variable @ref{racket-show-functions}.
@node Associating edit buffers with REPL buffers
@section Associating edit buffers with REPL buffers
@menu
* racket-repl-buffer-name-shared::
* racket-repl-buffer-name-unique::
* racket-repl-buffer-name-project::
* racket-project-root::
@end menu
@node racket-repl-buffer-name-shared
@subsection racket-repl-buffer-name-shared
@code{(racket-repl-buffer-name-shared)}
Share one @ref{racket-repl-mode} buffer per back end.
A value for the variable @ref{racket-repl-buffer-name-function}.
@node racket-repl-buffer-name-unique
@subsection racket-repl-buffer-name-unique
@code{(racket-repl-buffer-name-unique)}
Each @ref{racket-mode} edit buffer gets its own @ref{racket-repl-mode} buffer.
A value for the variable @ref{racket-repl-buffer-name-function}.
@node racket-repl-buffer-name-project
@subsection racket-repl-buffer-name-project
@code{(racket-repl-buffer-name-project)}
Share one @ref{racket-repl-mode} buffer per back end and per project.
A value for the variable @ref{racket-repl-buffer-name-function}.
The ``project'' is determined by @ref{racket-project-root}.
@node racket-project-root
@subsection racket-project-root
@code{(racket-project-root file)}
Given an absolute pathname for FILE, return its project root directory.
The ``project'' is determined by trying, in order:
@itemize
@item
@code{projectile-project-root}, if that exists
@item
@code{project-current} and @code{project-root}
@item
@code{file-name-directory}
@end itemize
@node Browsing file URLs with anchors
@section Browsing file URLs with anchors
@menu
* racket-browse-url-using-temporary-file::
@end menu
@node racket-browse-url-using-temporary-file
@subsection racket-browse-url-using-temporary-file
@code{(racket-browse-url-using-temporary-file url &rest _args)}
Browse a URL via a temporary HTML file using a meta redirect.
A suitable value for the variable @ref{racket-browse-url-function}.
Racket documentation URLs depend on anchors -- the portion of the
URL after the # character -- to jump to a location within a page.
Unfortunately on some operating systems and/or versions of Emacs,
the default handling for browsing file URLs ignores anchors. This
function attempts to avoid the problem by using a temporary HTML
file with a meta redirect as a ``trampoline''.
Although the intent is to provide a default that ``just works'',
you do not need to use this. You can customize the variable
@ref{racket-browse-url-function} instead to be @code{browse-url}, or
@code{browse-url-browser-function} in case have have customized that,
or indeed whatever you want.
@node Configuring back ends
@section Configuring back ends
@menu
* racket-add-back-end::
@end menu
@node racket-add-back-end
@subsection racket-add-back-end
@code{(racket-add-back-end directory &rest plist)}
Add a description of a Racket Mode back end.
Racket Mode supports one or more back ends, which are Racket
processes supporting REPLs as well as various other Racket Mode
features.
DIRECTORY is a string describing a @code{file-name-absolute-p}
directory on some local or remote server.
When a back end's DIRECTORY is the longest matching prefix of a
buffer's @code{default-directory}, that back end is used for the
buffer.
DIRECTORY can be a local directory like ``/'' or
``/path/to/project'', or a @code{file-remote-p} directory like
``/user@@host:'' or ``/user@@host:/path/to/project''.
Note that you need not include a method -- such as the ``ssh'' in
``/ssh:user@@host:'' -- and if you do it is stripped: A back end
process is always started using SSH@. Even if multiple buffers for
the same user+host+port use different methods, they will share
the same back end.
Practically speaking, DIRECTORY is a path you could give to
@code{find-file} to successfully find some local or remote file, but
omitting any method. (Some remote file shorthand forms get
expanded to at least ``/method:host:''. When in doubt check
@code{buffer-file-name} and follow its example.)
In addition to being used as a pattern to pick a back end for a
buffer, DIRECTORY determines:
@itemize
@item
Whether the back end is local or remote.
@item
When remote, any explicit user and port used to make SSH
connections (as opposed to relying on values from
~/.ssh/config).
@item
Other properties get reasonable defaults based on whether the
back end is local or remote, as described below.
@end itemize
After DIRECTORY, the remainining arguments are optional; they are
alternating :keywords and values describing some other properties
of a back end:
@itemize
@item
:racket-program
When not nil this is used instead of the value of the
customization variable @ref{racket-program}.
@item
:remote-source-dir
Where on a remote host to copy the back end's *.rkt files when
they do not exist or do not match the digest of the local
files. This must be @code{file-name-absolute-p} on the remote. Only
supply the localname there (not a full @code{file-remote-p}). The
default value is ``/tmp/racket-mode-back-end''.
@item
:windows
Whether the back end uses Windows style path names. Used to
translate betwen slashes and backslashes between the Emacs
front end (which uses slashes even on Windows) and the Racket
back end (which expects native backslashes on Windows).
@item
:restart-watch-directories
A list of @code{directory-name-p} strings. Each directory, and
recursively its subdirectories, will be watched for file system
changes. After any changes are detected, the next
@ref{racket-run} (or @ref{racket-run-module-at-point} etc.) command
will ask you if it should restart the back end for you. This
may be helpful when you are changing source files used by the
back end.
@end itemize
The default property values are appropriate for whether
DIRECTORY is local or remote:
@itemize
@item
When DIRECTORY is remote, :windows defaults to nil.
@item
Otherwise, :windows defaults to a value based on @code{system-type}.
@end itemize
Although the default values usually ``just work'' for local and
remote back ends, you might want a special configuration. Here
are a few examples.
@lisp
;; 1. A back end configuration for "/" is
;; created automatically and works fine as a default
;; for buffers visiting local files, so we don't need
;; to add one here.
;; 2. However assume we want buffers under /var/tmp/8.0
;; instead to use Racket 8.0.
(racket-add-back-end "/var/tmp/8.0"
:racket-program "~/racket/8.0/bin/racket")
;; 3. A back end configuration will be created
;; automatically for buffers visiting file names like
;; "/ssh:user@@linode", so we don't need to add one here.
;;
;; If ~/.ssh/config defines a Host alias named "linode",
;; with HostName and User settings, a file name as simple as
;; "/linode:" would work fine with tramp -- and the
;; automatically created back end configuration would work
;; fine, too.
;; 4. For example's sake, assume for buffers visiting
;; /ssh:headless:~/gui-project/ we want :racket-program instead
;; to be '("xvfb-run" "racket").
(racket-add-back-end "/ssh:headless:~/gui-project/"
:racket-program '("xvfb-run" "racket"))
@end lisp
If you use various versions of Racket by setting PATH values via
direnv, .envrc files and @code{envrc-global-mode}, then you need a
distinct back end for each such project subdirectory. One
approach is to use @ref{racket-add-back-end} for each project in your
Emacs init file. Another way to is to have a .dir-locals.el file
alongside each .envrc file:
@lisp
((nil . ((eval . (racket-add-back-end default-directory)))))
@end lisp
@node Running racket and raco commands in a shell or terminal (1)
@section Running racket and raco commands in a shell or terminal
@menu
* racket-shell::
* racket-term::
* racket-ansi-term::
* racket-vterm::
@end menu
@node racket-shell
@subsection racket-shell
@code{(racket-shell cmd)}
Run CMD using @code{shell}.
A value for the variable @ref{racket-shell-or-terminal-function}.
@node racket-term
@subsection racket-term
@code{(racket-term cmd)}
Run CMD using @code{term}.
A value for the variable @ref{racket-shell-or-terminal-function}.
@node racket-ansi-term
@subsection racket-ansi-term
@code{(racket-ansi-term cmd)}
Run CMD using @code{ansi-term}.
A value for the variable @ref{racket-shell-or-terminal-function}.
@node racket-vterm
@subsection racket-vterm
@code{(racket-vterm cmd)}
Run CMD using @code{vterm}, if that package is installed.
A value for the variable @ref{racket-shell-or-terminal-function}.
@node Faces
@chapter Faces
@menu
* All::
@end menu
@node All
@section All
@menu
* racket-keyword-argument-face::
* racket-reader-quoted-symbol-face::
* racket-reader-syntax-quoted-symbol-face::
* racket-here-string-face::
* racket-xp-def-face::
* racket-xp-use-face::
* racket-xp-unused-face::
* racket-xp-tail-target-face::
* racket-xp-tail-position-face::
* racket-xp-binding-lang-face::
* racket-xp-binding-lang-use-face::
* racket-xp-binding-import-face::
* racket-xp-binding-import-use-face::
* racket-xp-binding-local-face::
* racket-xp-binding-local-use-face::
* racket-logger-config-face::
* racket-logger-topic-face::
* racket-logger-fatal-face::
* racket-logger-error-face::
* racket-logger-warning-face::
* racket-logger-info-face::
* racket-logger-debug-face::
* racket-doc-link-face::
* racket-ext-link-face::
* racket-doc-output-face::
* racket-doc-litchar-face::
* racket-repl-message::
* racket-repl-prompt::
* racket-repl-value::
* racket-repl-error-message::
* racket-repl-error-location::
* racket-repl-stdout::
* racket-repl-stderr::
* racket-hash-lang-text::
@end menu
@node racket-keyword-argument-face
@subsection racket-keyword-argument-face
Face for @code{#:keyword} arguments.
@node racket-reader-quoted-symbol-face
@subsection racket-reader-quoted-symbol-face
Face for symbols quoted using ' or `.
This face is given only to symbols directly quoted using the
reader shorthands ' or `. All other directly quoted values,
including symbols quoted using ``quote'' or ``quasiquote'', get
the face @code{font-lock-constant-face}.
@node racket-reader-syntax-quoted-symbol-face
@subsection racket-reader-syntax-quoted-symbol-face
Face for symbols quoted using #' or #`.
This face is given only to symbols directly quoted using the
reader shorthands #' or #`. All other directly quoted
values, including symbols quoted using ``syntax'' or
``quasisyntax'', get the face @code{font-lock-constant-face}.
@node racket-here-string-face
@subsection racket-here-string-face
Face for here strings.
@node racket-xp-def-face
@subsection racket-xp-def-face
Face @ref{racket-xp-mode} uses when point is on a definition.
@node racket-xp-use-face
@subsection racket-xp-use-face
Face @ref{racket-xp-mode} uses when point is on a use.
@node racket-xp-unused-face
@subsection racket-xp-unused-face
Face @ref{racket-xp-mode} uses to highlight unused requires or definitions.
@node racket-xp-tail-target-face
@subsection racket-xp-tail-target-face
Face @ref{racket-xp-mode} uses to highlight targets of a tail position.
@node racket-xp-tail-position-face
@subsection racket-xp-tail-position-face
Face @ref{racket-xp-mode} uses to highlight expressions in a tail position.
@node racket-xp-binding-lang-face
@subsection racket-xp-binding-lang-face
Face @ref{racket-xp-mode} gives to the module language name.
See the variable @code{nil}.
@node racket-xp-binding-lang-use-face
@subsection racket-xp-binding-lang-use-face
Face @ref{racket-xp-mode} gives uses of bindings imported from the module language.
See the variable @code{nil}.
@node racket-xp-binding-import-face
@subsection racket-xp-binding-import-face
Face @ref{racket-xp-mode} gives to imported module names.
See the variable @code{nil}.
@node racket-xp-binding-import-use-face
@subsection racket-xp-binding-import-use-face
Face @ref{racket-xp-mode} gives uses of imported bindings.
See the variable @code{nil}.
@node racket-xp-binding-local-face
@subsection racket-xp-binding-local-face
Face @ref{racket-xp-mode} gives to local definitions.
See the variable @code{nil}.
@node racket-xp-binding-local-use-face
@subsection racket-xp-binding-local-use-face
Face @ref{racket-xp-mode} gives to uses of local definitions.
See the variable @code{nil}.
@node racket-logger-config-face
@subsection racket-logger-config-face
Face for @ref{racket-logger-mode} configuration.
@node racket-logger-topic-face
@subsection racket-logger-topic-face
Face for @ref{racket-logger-mode} topics.
@node racket-logger-fatal-face
@subsection racket-logger-fatal-face
Face for @ref{racket-logger-mode} fatal level.
@node racket-logger-error-face
@subsection racket-logger-error-face
Face for @ref{racket-logger-mode} error level.
@node racket-logger-warning-face
@subsection racket-logger-warning-face
Face for @ref{racket-logger-mode} warning level.
@node racket-logger-info-face
@subsection racket-logger-info-face
Face for @ref{racket-logger-mode} info level.
@node racket-logger-debug-face
@subsection racket-logger-debug-face
Face for @ref{racket-logger-mode} debug level.
@node racket-doc-link-face
@subsection racket-doc-link-face
Face @ref{racket-describe-mode} uses for links within documentation.
Note: When some special face is already specified by the
documentation, then to avoid visual clutter this face is NOT also
added.
@node racket-ext-link-face
@subsection racket-ext-link-face
Face @ref{racket-describe-mode} uses for external links.
See the variable @ref{racket-browse-url-function}.
@node racket-doc-output-face
@subsection racket-doc-output-face
Face @ref{racket-describe-mode} uses for Scribble @@example or @@interactions output.
@node racket-doc-litchar-face
@subsection racket-doc-litchar-face
Face @ref{racket-describe-mode} uses for Scribble @@litchar.
@node racket-repl-message
@subsection racket-repl-message
Face @ref{racket-repl-mode} uses for messages from the back end.
@node racket-repl-prompt
@subsection racket-repl-prompt
Face @ref{racket-repl-mode} uses for prompts.
@node racket-repl-value
@subsection racket-repl-value
Face @ref{racket-repl-mode} uses for @code{print}-ed values.
@node racket-repl-error-message
@subsection racket-repl-error-message
Face @ref{racket-repl-mode} uses for error messages.
@node racket-repl-error-location
@subsection racket-repl-error-location
Face @ref{racket-repl-mode} uses for error locations.
@node racket-repl-stdout
@subsection racket-repl-stdout
Face @ref{racket-repl-mode} uses for output to current-output-port.
@node racket-repl-stderr
@subsection racket-repl-stderr
Face @ref{racket-repl-mode} uses for output to current-error-port.
@node racket-hash-lang-text
@subsection racket-hash-lang-text
Face @ref{racket-hash-lang-mode} uses for text tokens.
@bye
|