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
|
@c $Id: text-editing.texinfo,v 1.45 2002/01/09 17:01:06 m Exp m $
@node Text Editing, Grammar, Viewing Text, Text
@comment node-name, next, previous, up
@chapter Text Editing
@cindex text editing
@cindex editing text
@cindex Emacs
@cindex Vi
@noindent
Text editing is one of the most fundamental activities of computing on
Linux-based systems, or most any computer for that matter. We edit text
when writing a document, sending email, making a Web page, posting an
article for Usenet, programming---and the list goes on. Most people
spend a good deal of their computing time editing text with a text
editor application.
There are a lot of text editors to choose from on Linux systems, as the
first recipe in this chapter shows, but the majority of editors fit in
one of two families of editor: Emacs and Vi. Most users prefer one or
the other; rarely is one adept at both. I give more coverage to Emacs,
and not only because it's my preferred editor---its keystroke commands
are used by default in many other tools and applications, including the
@code{bash} shell (@pxref{Shell, , The Shell}).
@menu
* Text Editors:: Overview of text editors.
* Emacs:: Introducing the Emacs editor.
* Vi:: Learning to use the Vi editor.
* Selecting Text:: Selecting text.
* Stream Editing:: Editing a stream of text in batch.
* Concatenating Text:: Concatenating text.
* Including Text:: Including text files into new files.
@end menu
@node Text Editors, Emacs, Text Editing, Text Editing
@comment node-name, next, previous, up
@section Choosing the Perfect Text Editor
@cindex choosing the perfect text editor
@cindex text editor, choosing a
@cindex editors, text
@cindex Cooledit
@cindex Davis, John E.
@cindex DEdit
@cindex Emacs
@cindex Hessling Editor
@cindex Midnight Commander
@cindex Pico
@cindex Pine
@cindex Rexx
@cindex University of Washington
@cindex Vi
@pindex ae
@pindex cooledit
@pindex dedit
@pindex ee
@pindex elvis
@pindex emacs
@pindex fe
@pindex jed
@pindex joe
@pindex nano
@pindex ted
@pindex the
@pindex vi
@pindex vim
@pindex wily
@pindex xedit
@noindent
The following table describes some of the more interesting text editors
available, and includes information about their special traits and
characteristics.
@multitable @columnfractions .20 .80
@item @sc{Text Editor}
@tab @sc{Description}
@item @code{ae}
@tab Anthony's Editor, @code{ae}, is a simple, easy-to-use text
editor. It has modes to emulate the behavior of other text editors.
@noindent
{@sf{Debian}}: @file{ae}
@noindent
{@sf{WWW}}: @url{http://dmoz.org/Computers/Software/Editors/Vi/}
@item @code{cooledit}
@tab Cooledit is a popular, fast text editor for use in X; its features include
anti-aliased fonts, Unicode support, and extensibility via the Python
programming language.
@noindent
{@sf{Debian}}: @file{cooledit}
@noindent
{@sf{WWW}}: @url{http://cooledit.sourceforge.net/}
@item @code{dedit}
@tab DEdit is a simple editor for use in X with GNOME installed. It can read
compressed files and display Japanese characters.
@noindent
{@sf{Debian}}: @file{dedit}
@item @code{ee}
@tab Intended to be an editor that novices can begin using immediately,
the Easy Editor features pop-up menus.
@noindent
{@sf{Debian}}: @file{ee}
@noindent
{@sf{WWW}}: @url{http://mahon.cwx.net/}
@item @code{elvis}
@tab Elvis is a modern implementation of Vi that comes with many new
features and extensions.
@noindent
{@sf{Debian}}: @file{elvis}
@noindent
{@sf{WWW}}: @url{http://elvis.vi-editor.org}
@item @code{emacs}
@tab Emacs is one of the two most-popular text editors. I've devoted an
entire section to it in this book: @ref{Emacs, , Emacs}.
@noindent
@sf{Debian}: @file{emacsen-common}
@noindent
@sf{Debian}: @file{emacs20}
@noindent
@sf{WWW}: @file{http://www.emacs.org/}
@item @code{jed}
@tab John E. Davis's @code{jed} offers many of the conveniences of Emacs
and is geared specifically toward programmers. Features unique to it
include drop-down menus that work in the console; @code{jed} loads
quickly, and makes editing files at a shell prompt easy and fast.
@noindent
{@sf{Debian}}: @file{jed}
@noindent
{@sf{WWW}}: @url{http://space.mit.edu/~davis/jed.html}
@item @code{joe}
@tab Joe's Own Editor, @code{joe}, is a full-screen editor with a look
and feel reminiscent of old DOS text editors like EDIT.
@noindent
{@sf{Debian}}: @file{joe}
@noindent
{@sf{WWW}}: @url{ftp://ftp.std.com/src/editors/}
@item @code{nano}
@tab Nano is a free software editor inspired by Pico, the editor that is
included with the University of Washington's proprietary Pine email
program. It's also faster than Pico, and comes with more features.
@noindent
{@sf{Debian}}: @file{nano}
@noindent
{@sf{WWW}}: @url{http://www.nano-editor.org/}
@item @code{ted}
@tab Ted is a WYSIWYG text editor for use in X which reads and writes
@file{.rtf} files in Microsoft's ``Rich Text Format.''
@noindent
{@sf{Debian}}: @file{ted}
@noindent
{@sf{WWW}}: @url{http://www.nllgg.nl/Ted/}
@item @code{the}
@tab The Hessling Editor is a configurable editor that uses the Rexx
macro language. It was inspired by the XEDIT editor for VM/CMS and the
Kedit editor for DOS.
@noindent
{@sf{Debian}}: @file{the}
@noindent
{@sf{Debian}}: @file{the-doc}
@noindent
{@sf{WWW}}: @url{http://www.lightlink.com/hessling/THE/}
@item @code{vi}
@tab Vi (pronounced ``vye,'' or sometimes ``vee-eye'') is a
@emph{visual}, or full-screen, editor. Touch typists often find its
keystroke commands enable very fast editing.
@noindent
Together with Emacs, Vi shares the spotlight for most popular editor on
Linux and Unix-based systems in general. Both were initially written in
the same period, and both have their staunch adherents. To run a
hands-on tutorial, see @ref{Vi, , Running a Vi Tutorial}.
@noindent
{@sf{Debian}}: @file{nvi}
@noindent
{@sf{WWW}}: @url{ftp://mongoose.bostic.com/pub/nvi.tar.gz}
@item @code{vim}
@tab Like the Elvis editor, Vim (``Vi improved'') is a modern
implementation of Vi whose new features include syntax coloring,
scrollbars and menus, mouse support, and built-in help.
@noindent
{@sf{Debian}}: @file{vim}
@noindent
{@sf{WWW}}: @url{http://www.vim.org/}
@item @code{wily}
@tab Wily, an interesting mouse-centric editor, is inspired by the Acme
editor from AT&T's Plan 9 experimental operating system. Wily commands
consist of various combinations of the three mouse buttons, called
@dfn{chords}, which can be tricky to master.
@noindent
{@sf{Debian}}: @file{wily}
@noindent
{@sf{WWW}}: @url{http://www.cs.su.oz.au/~gary/wily/}
@item @code{xedit}
@tab Xedit is a simple text editor that comes with, and works in, X. It
lets you insert, delete, copy and paste text as well as open and save
files---the very basics.
@noindent
{@sf{Debian}}: @file{xcontrib}
@item @code{xemacs}
@tab XEmacs is a version of Emacs with advanced capabilities for use in
X, including the ability to display images.
@noindent
{@sf{Debian}}: @file{emacsen-common}
@noindent
{@sf{Debian}}: @file{xemacs}
@noindent
{@sf{WWW}}: @url{http://www.xemacs.org/}
@end multitable
@node Emacs, Vi, Text Editors, Text Editing
@comment node-name, next, previous, up
@section Emacs
@cindex Emacs
@cindex GNU Emacs
@cindex Stallman, Richard
@cindex Free-Net
@cindex Case Western Reserve University
@cindex Lucid Emacs
@cindex Chet's Emacs
@pindex XEmacs
@pindex emacs
@pindex ce
@pindex xemacs
@flushleft
@sf{Debian}: @file{emacsen-common}
@sf{WWW}: @file{http://www.emacs.org/}
@end flushleft
@*
@noindent
To call Emacs a text editor does not do it justice---it's a large
application capable of performing many functions, including reading
email and Usenet news, browsing the World Wide Web, and even perfunctory
psychoanalysis.
There is more than one version of Emacs. GNU Emacs is the Emacs released
under the auspices of Richard Stallman, who wrote the original Emacs
predecessor in the 1970s. XEmacs (formerly Lucid Emacs) offers
essentially the same features GNU Emacs does, but also contains its own
features for use with the X Window System (it also behaves differently
from GNU Emacs in some minor ways).
GNU Emacs and XEmacs are by far the most popular emacsen (as they are
referred to in number); other flavors include @code{jed} (described in
the previous section) and Chet's Emacs, @code{ce}, developed by a
programmer at Case Western Reserve University.
Following is a brief introduction to using Emacs, interspersed with the
necessary Emacs jargon; following that are recipes that describe how to
use some of Emacs's advanced editing features.
@menu
* Emacs Intro:: How to learn Emacs.
* Emacs Editing:: The basic Emacs editing keys.
* Emacs Abbreviations:: Making abbreviations to save time.
* Emacs Macros:: Making macros to save time.
* Emacs Inserts:: Inserting special characters in Emacs.
@end menu
@node Emacs Intro, Emacs Editing, Emacs, Emacs
@comment node-name, next, previous, up
@subsection Getting Acquainted with Emacs
@cindex getting acquainted with Emacs
@cindex Emacs, getting acquainted with
@cindex mode line
@cindex Overwrite mode
@cindex echo area
@cindex minibuffer
@cindex point
@cindex *scratch*
@cindex buffer
@cindex menu bar, in Emacs
@cindex Info
@pindex emacs
@pindex xemacs
@noindent
Start Emacs in the usual way, either by choosing it from the menu
supplied by your window manager in X, or by typing its name (in
lowercase letters) at a shell prompt.
@itemize @bullet
@item
To start GNU Emacs at a shell prompt, type:
@example
$ @kbd{emacs @key{RET}}
@end example
@item
To start XEmacs at a shell prompt, type:
@example
$ @kbd{xemacs @key{RET}}
@end example
@end itemize
Upon startup in X, a typical GNU Emacs window looks like this (the
window frame will differ depending on your window manager):
@image{text-editing-emacs-01, 3in}
The welcome message appears when Emacs first starts, and it tells you,
among other things, how to run a tutorial (which we'll look at in just a
minute).
The top bar is called the @dfn{menu bar}, and you can pull down its
menus with the mouse by left-clicking a menu and then dragging it
down. When you run Emacs in a console, you can't use the mouse to pull
down the menus, but you can access and choose the same menu items in a
text menu by typing @kbd{@key{F10}}.@footnote{This key works in X as
well, and works as it does in the console.}
A file or other text open in Emacs is held in its own area called a
@dfn{buffer}. By default, the current buffer appears in the large area
underneath the menu bar. To write text in the buffer, just type it. The
place in the buffer where the cursor is at is called @dfn{point}, and is
referenced by many Emacs commands.
The horizontal bar near the bottom of the Emacs window and directly
underneath the current buffer is called the @dfn{mode line}; it gives
information about the current buffer, including its name, what
percentage of the buffer fits on the screen, what line point is on, and
whether or not the buffer is saved to a file.
The mode line also lists the modes active in the buffer. Emacs
@dfn{modes} are general states that control the way Emacs behaves---for
example, when @code{Overwrite} mode is set, text you type
@emph{overwrites} the text at point; in @code{Insert} mode (the
default), text you type is @emph{inserted} at point. Usually, either
@code{Fundamental} mode (the default) or @code{Text} mode will be
listed.
You can make the menu bar appear or disappear by toggling @code{Menu
bar} mode. Typing @kbd{@key{F10}} to activate the menu pull-downs works
whether @code{Menu bar} mode is on or off; if it's off, the menu choices
will appear in a new buffer window.
@itemize @bullet
@item
To turn off the top menu bar, type:
@example
@kbd{M-x menu-bar-mode @key{RET}}
@end example
@end itemize
(If the menu bar is already turned off, this command will turn it on.)
The @dfn{echo area} is where Emacs writes brief status messages, such as
error messages; it is the last line in the Emacs window. When you type a
command that requires input, that input is requested in this area (and
when that happens, the place you type your input, in the echo area, is
then called the @dfn{minibuffer}).
Emacs commands usually begin with a Control or Meta (Escape) key
sequence; many commands begin with the @kbd{C-x} sequence, which you
type by pressing and holding the @key{CTRL} key and then pressing the
@key{X} key (@pxref{Conventions, , Typographical Conventions}).
Because Emacs is different in culture from the editors and approach of
the Microsoft Windows and Apple MacOS world, it has gotten a rather
unfounded reputation in those corners that it is odd and difficult to
use. This is not so. The keyboard commands to run its various functions
are designed for ease of use and easy recall.
For example, the @code{find-file} function prompts for the name of a
file and opens a copy of the file in a new buffer; its keyboard
accelerator is @kbd{C-x C-f} (you can keep @key{CTRL} depressed while
you press and release the @key{X} and @key{F} keys).
You can run any Emacs function by typing @kbd{M-x} followed by the
function name and pressing @key{RET}.
@itemize @bullet
@item
To run the @code{find-file} function, type:
@example
@kbd{M-x find-file @key{RET}}
@end example
@end itemize
This command runs the @code{find-file} function, which prompts for the
name of a file and opens a copy of the file in a new buffer.
Type @kbd{C-g} in Emacs to quit a function or command; if you make a
mistake when typing a command, this is useful to cancel and abort the
keyboard input.
Now that we have run through the essential Emacs terminology, I'll show
you how to exit the program---just type @kbd{C-x C-c}.
Emacs can have more than one buffer open at once. To switch between
buffers, type @kbd{C-x C-b}. Then, give the name of the buffer to switch
to, followed by @key{RET}; alternatively, type @key{RET} without a
buffer name to switch to the last buffer you had visited. (Viewing a
buffer in Emacs is called @dfn{visiting} the buffer.)
@itemize @bullet
@item
To switch to a buffer called @file{rolo}, type:
@example
@kbd{C-x C-b rolo @key{RET}}
@end example
@end itemize
A special buffer called @file{*scratch*} is for notes and things you
don't want to save; it always exists in Emacs.
@itemize @bullet
@item
To switch to the @file{*scratch*} buffer, type:
@example
@kbd{C-x C-b *scratch* @key{RET}}
@end example
@end itemize
Any file names you give as an argument to @code{emacs} will open in
separate buffers:
@example
$ @kbd{emacs todo rolo /usr/local/src/nirvarna/README @key{RET}}
@end example
(You can also make new buffers and open files in buffers later, of
course.)
Emacs comes with an interactive, self-paced tutorial that teaches you
how to use the basics. In my experience, setting aside 25 minutes to go
through the tutorial is one of the best things you can do in your
computing career---even if you decide that you don't like Emacs very
much, a great many other applications use Emacs-like keyboard commands
and heuristics, so familiarizing yourself with them will always pay off.
To start the tutorial at any time when you are in Emacs, type @kbd{C-h
t}.
Incidentally, @kbd{C-h} is the Emacs help key; all help-related commands
begin with this key. For example, to read the @cite{Emacs FAQ}, type
@kbd{C-h F}, and to run the Info documentation browser (which contains
@cite{The GNU Emacs Manual}), type @kbd{C-h i}.
@node Emacs Editing, Emacs Abbreviations, Emacs Intro, Emacs
@comment node-name, next, previous, up
@subsection Basic Emacs Editing Keys
@cindex basic Emacs editing keys
@cindex Emacs, basic editing keys
@pindex emacs
@noindent
The following table lists basic editing keys and describes their
function. Where two common keystrokes are available for a function, both
are given.
@need 1000
@multitable @columnfractions .30 .70
@item @sc{Keys}
@tab @sc{Description}
@item @key{@math{@uparrow}} @var{or} @code{C-p}
@tab Move point up to the previous line.
@ifinfo
[GNU INFO BUG: any <> in the preceding line should be the one of the cursor arrow keys.]
@end ifinfo
@item @key{@math{@downarrow}} @var{or} @code{C-n}
@tab Move point down to the next line.
@ifinfo
[GNU INFO BUG: any <> in the preceding line should be the one of the cursor arrow keys.]
@end ifinfo
@item @key{@math{@leftarrow}} @var{or} @code{C-b}
@tab Move point @emph{back} through the buffer one character to the left.
@ifinfo
[GNU INFO BUG: any <> in the preceding line should be the one of the cursor arrow keys.]
@end ifinfo
@item @key{@math{@rightarrow}} @var{or} @code{C-f}
@tab Move point @emph{forward} through the buffer one character to the right.
@ifinfo
[GNU INFO BUG: any <> in the preceding line should be the one of the cursor arrow keys.]
@end ifinfo
@item @key{PgUp} @var{or} @code{C-v}
@tab Move point forward through the buffer one screenful.
@item @key{PgDn} @var{or} @code{M-v}
@tab Move point backward through the buffer one screenful.
@item @key{BKSP} @var{or} @code{C-h}
@tab Delete character to the left of point.
@item @key{DEL} @var{or} @code{C-d}
@tab Delete character to the right of point.
@item @key{INS}
@tab Toggles between @code{Insert} mode and @code{Overwrite} mode.
@item @key{Shift}-@key{INS} @var{or} @code{C-y}
@tab Yank text in the kill ring at point (@pxref{Pasting Text, , Pasting
Text}).
@item C-@key{SPC}
@tab Set mark (@pxref{Cutting Text, , Cutting Text}).
@item @code{C-_}
@tab Undo the last action (control-underscore).
@item @code{C-a}
@tab Move point to the beginning of the current line.
@item @code{C-e}
@tab Move point to the end of the current line.
@item @code{C-g}
@tab Cancel the current command.
@item @code{C-h F}
@tab Open a copy of the @cite{Emacs FAQ} in a new buffer.
@item @code{C-h a @var{function} @key{RET}}
@tab List all Emacs commands related to @var{function}.
@item @code{C-h i}
@tab Start Info.
@item @code{C-h k @var{key}}
@tab Describe key.
@item @code{C-h t}
@tab Start the Emacs tutorial.
@item @code{C-k}
@tab Kill text from point to end of line.
@item @code{C-l}
@tab Re-center the text in the Emacs window, placing the line where
point is in the middle of the screen.
@item @code{C-t}
@tab Transpose the character at point with the character to the left of
point.
@item @code{C-u @var{number}}
@tab Repeat the next command or keystroke you type @var{number} times.
@item @code{C-w}
@tab Kill text from mark to point.
@item @code{C-x C-c}
@tab Save all buffers open in Emacs, and then exit the program.
@item @code{C-x C-f @var{file} @key{RET}}
@tab Open @var{file} in a new buffer for editing. To create a new file
that does not yet exist, just specify the file name you want to give
it. To browse through your files, type @key{TAB} instead of a file
name.
@item @code{C-@var{left-click}}
@tab Display a menu of all open buffers, sorted by major mode (works in
X only).
@item @code{@key{SHIFT}-@var{left-click}}
@tab Display a font selection menu (works in X only).
@end multitable
@node Emacs Abbreviations, Emacs Macros, Emacs Editing, Emacs
@comment node-name, next, previous, up
@subsection Making Abbreviations in Emacs
@cindex making abbreviations in Emacs
@cindex abbreviations, making in Emacs
@cindex Emacs, making abbreviations in
@pindex Abbrev mode
@noindent
An @dfn{abbrev} is a word that is an @emph{abbreviation} of a (usually)
longer word or phrase. Abbrevs exist as a convenience to you---you can
define abbrevs to expand to a long phrase that is inconvenient to type,
or you can define a misspelling that you tend to make to expand to its
correct spelling. Abbrevs only expand when you have @code{Abbrev} mode
enabled.
@itemize @bullet
@item
To turn on @code{Abbrev} mode, type:
@example
@kbd{M-x abbrev-mode @key{RET}}
@end example
@end itemize
To define an abbrev, type the abbrev you want to use and then type
@kbd{C-x aig}. Emacs will prompt in the minibuffer for the text you want
the abbrev to expand to; type that text and then type @key{RET}.
@itemize @bullet
@item
To define @samp{rbf} as an abbrev for @samp{R. Buckminster Fuller}, do
the following:
@itemize @bullet
@item
First, type the abbrev itself:
@example
@kbd{rbf}
@end example
@item
Next, specify that this text is to be an abbrev; type:
@example
@kbd{C-x aig}
@end example
@item
Now type the text to expand it to:
@example
Global expansion for "rbf": @kbd{R. Buckminster Fuller @key{RET}}
@end example
@end itemize
@end itemize
Now, whenever you type @samp{rbf} followed by a whitespace or
punctuation character in the current buffer, that text will expand to
the text @samp{R. Buckminster Fuller}.
To save the abbrevs you have defined so that you can use them later, use
the @code{write-abbrev-file} function. This saves all of the abbrevs
currently defined to a file that you can read in a future Emacs session.
(You can also open the file in a buffer and edit the abbrevs if you
like.)
@itemize @bullet
@item
To save the abbrevs you have currently defined to a file
@file{~/.misspelling-abbrevs}, type:
@example
@kbd{M-x write-abbrev-file @key{RET} ~/.misspelling-abbrevs @key{RET}}
@end example
@end itemize
Then, in a future Emacs session, you can use the @code{read-abbrev-file}
function to define those abbrevs for that session.
@itemize @bullet
@item
To read the abbrevs from the file @file{~/.misspelling-abbrevs}, and
define them for the current session, type:
@example
@kbd{M-x read-abbrev-file @key{RET} ~/.misspelling-abbrevs @key{RET}}
@end example
@end itemize
@sp .25
@noindent
@strong{NOTE:} Emacs mode commands are toggles. So to turn off
@code{Abbrev} mode in a buffer, just type @kbd{M-x abbrev-mode
@key{RET}} again. If you turn @code{Abbrev} mode on in that buffer later
on during the Emacs session, the abbrevs will be remembered and will
expand again.
@node Emacs Macros, Emacs Inserts, Emacs Abbreviations, Emacs
@comment node-name, next, previous, up
@subsection Recording and Running Macros in Emacs
@cindex recording and running macros in Emacs
@cindex macros, recording and running in Emacs
@cindex Emacs, recording and running macros in
@noindent
A @dfn{macro} is like a recording of a sequence of keystrokes---when you
run a macro, Emacs executes that key sequence as if you had typed them.
To begin recording a macro, type @kbd{C-x (}. Then, everything you type
is recorded as the macro until you stop recording by typing @kbd{C-x
)}. After you have recorded a macro, you can play it back at any time
during the Emacs session by typing @kbd{C-x e}. You can precede it with
the @code{universal-argument} command, @kbd{C-u}, to specify a number of
times to play it back.
@itemize @bullet
@item
To record a macro that capitalizes the first word of the current line
(@kbd{M-c} capitalizes the word to the right of point) and then advances
to the next line, type:
@example
@kbd{C-x ( C-a M-c C-n C-x )}
@end example
@item
To play the macro back 20 times, type:
@example
@kbd{C-u 20 C-x e}
@end example
@end itemize
Macros are primary to how Emacs works---in fact, the name Emacs is
derived from @samp{Editing MACroS}, because the first version of Emacs
in 1976 was actually a collection of such macros written for another
text editor.
@node Emacs Inserts, , Emacs Macros, Emacs
@comment node-name, next, previous, up
@subsection Inserting Special Characters in Emacs
@cindex inserting special characters in Emacs
@cindex Emacs, inserting special characters in
@cindex special characters, inserting in Emacs
@cindex control characters, inserting in Emacs
@cindex accent characters, inserting in Emacs
@cindex formfeeds, inserting in a text file
@cindex page breaks, inserting in a text file
@cindex underlining text
@noindent
There are some characters that you cannot normally type into an Emacs
buffer. For example, in a text file, you can specify a page break by
inserting the formfeed character, ASCII @kbd{C-l} or octal code 014;
when you print a file with formfeeds, the current page is ejected at
this character and printing is resumed on a new page.
However, @kbd{C-l} has meaning as an Emacs command. To insert a
character like this, use the @code{quoted-insert} function, @kbd{C-q}.
It takes either a literal keystroke to insert, or the octal code of the
character to insert. It inserts that character at point.
@itemize @bullet
@item
To insert a formfeed character at point by specifying its actual
keystroke (@kbd{C-l}), type:
@example
@kbd{C-q C-l}
@end example
@item
To insert a formfeed character at point by specifying its octal
character code, type:
@example
@kbd{C-q 014 @key{RET}}
@end example
@end itemize
The preceding examples both do the same thing: they insert a formfeed
character at point.
An interesting use of @kbd{C-q} is to underline text. To do this, insert
a literal @kbd{C-h} character followed by an underscore (@samp{_}) after
each character you want to underline.
@itemize @bullet
@item
To underline the character before point, type:
@example
@kbd{C-q C-h _}
@end example
@end itemize
You can then use @code{ul} to output the text to the screen
(@pxref{Underlining Text, , Underlining Text}).
Another kind of special character insert you might want to make is for
accented characters and other characters used in various languages.
To insert an accented character, use @code{ISO Accents} mode. When this
mode is active, you can type a special accent character followed by the
character to be accented, and the proper accented character will be
inserted at point.
The following table shows the special accent characters and the key
combinations to use.
@ifinfo
[GNU INFO BUG: Info does not currently display accent characters correctly.]
@end ifinfo
@multitable @columnfractions .33 .33 .33
@item @sc{Prefix@dots{}} @tab @sc{Plus This Letter} @tab @sc{Yields This Result}
@item @code{"} @tab @code{a} @tab @"a
@item @code{"} @tab @code{e} @tab @"e
@item @code{"} @tab @code{i} @tab @"i
@item @code{"} @tab @code{o} @tab @"o
@item @code{"} @tab @code{u} @tab @"u
@item @code{"} @tab @code{s} @tab @ss{}
@item @code{'} @tab @code{a} @tab @'a
@item @code{'} @tab @code{e} @tab @'e
@item @code{'} @tab @code{i} @tab @'i
@item @code{'} @tab @code{o} @tab @'o
@item @code{'} @tab @code{u} @tab @'u
@item @code{`} @tab @code{a} @tab @`a
@item @code{`} @tab @code{e} @tab @`e
@item @code{`} @tab @code{i} @tab @`i
@item @code{`} @tab @code{o} @tab @`o
@item @code{`} @tab @code{u} @tab @`u
@item @code{~} @tab @code{a} @tab @~a
@item @code{~} @tab @code{c} @tab @,{c}
@item @code{~} @tab @code{d} @tab @~d
@item @code{~} @tab @code{n} @tab @~n
@item @code{~} @tab @code{t} @tab @~t
@item @code{~} @tab @code{u} @tab @~u
@item @code{~} @tab @code{<} @tab @sc{<<}
@item @code{~} @tab @code{>} @tab @sc{>>}
@c « » are supposedly html for guillemets
@item @code{~} @tab @code{!} @tab @exclamdown{}
@item @code{~} @tab @code{?} @tab @questiondown{}
@item @code{^} @tab @code{a} @tab @^a
@item @code{^} @tab @code{e} @tab @^e
@item @code{^} @tab @code{i} @tab @^i
@item @code{^} @tab @code{o} @tab @^o
@item @code{^} @tab @code{u} @tab @^u
@item @code{/} @tab @code{a} @tab @aa{}
@item @code{/} @tab @code{e} @tab @ae{}
@item @code{/} @tab @code{o} @tab @o{}
@end multitable
When a buffer contains accented characters, it can no longer be saved as
plain ASCII text, but must instead be saved as text in the ISO-8859-1
character set (@pxref{ASCII Chart, , Viewing a Character Chart}). When
you save a buffer, Emacs will notify you that it must do this.
@itemize @bullet
@item
To type the line @samp{Emacs ist spa@ss@code{}!} in the current buffer,
type:
@example
@kbd{M-x iso-accents-mode @key{RET}
Emacs ist spa"ss!}
@end example
@end itemize
In the event that you want to type the literal key combinations that
make up an accented character in a buffer where you have @code{ISO
Accents} mode on, type the prefix character twice.
@itemize @bullet
@item
To type the text @samp{'o} (and not the accent character @'o) in a
buffer while @code{ISO Accents} mode is on, type:
@example
@kbd{''o}
@end example
@end itemize
@sp .25
@noindent
@strong{NOTE:} GNU Emacs has recently added a number of
internationalization functions. A complete discussion of their use is
out of the scope of this book; for more information on this topic, see
@ref{International, , International Character Set Support, emacs, The
GNU Emacs Manual}.
@node Vi, Selecting Text, Emacs, Text Editing
@comment node-name, next, previous, up
@section Running a Vi Tutorial
@cindex running a Vi tutorial
@cindex Vi, running a tutorial
@pindex vi
@flushleft
@sf{Debian}: @file{nvi}
@sf{WWW}: @url{ftp://mongoose.bostic.com/pub/nvi.tar.gz}
@sf{WWW}: @url{http://www.cs.cmu.edu/~vaschelp/Editors/Vi/}
@end flushleft
@*
The Vi editor comes with a hands-on, self-paced tutorial, which you can
use in @code{vi} to learn how to use it. It's stored as a compressed
file in the @file{/usr/doc/nvi} directory; copy this file to your home
directory, uncompress it, and open it with @code{vi} to start the
tutorial.
@itemize @bullet
@item
To run the @code{vi} tutorial, type the following from your home
directory:
@example
@cartouche
$ @kbd{cp /usr/doc/nvi/vi.beginner.gz . @key{RET}}
$ @kbd{gunzip vi.beginner @key{RET}}
$ @kbd{vi vi.beginner @key{RET}}
@end cartouche
@end example
@end itemize
@sp .25
@noindent
@strong{NOTE:} An advanced tutorial is also available in
@file{/usr/doc/nvi}.
@node Selecting Text, Stream Editing, Vi, Text Editing
@comment node-name, next, previous, up
@section Selecting Text
@cindex selecting text
@cindex text, selecting
@cindex X selection
@pindex gpm
@pindex lynx
@noindent
In X, you can cut and paste text between other windows, including
@code{xterm} and Emacs windows. The most recently selected text is
called the @dfn{X selection}.
In the console, you can cut and paste text in the same virtual console
or into a different virtual console. To do this, you need the @code{gpm}
package installed and set up for your mouse (it's a default, recommended
package).
The operations described in this section work the same both in X and in
virtual consoles. You cannot presently cut and paste text between X and
a virtual console.
Three buttons on the mouse are used for cutting and pasting. If you have
a two-button mouse, your administrator can set it to emulate three
buttons---to specify the middle button, press the left and right buttons
simultaneously.
Click the left mouse button and drag the mouse over text to select
it. You can also double-click the left mouse button on a word to select
that word, and triple-click the left mouse button on a line to select
that line. Furthermore, you can click the left mouse button at one end
of a portion of text you want to select, and then click the right mouse
button at the other end to select all of the text between the points.
@sp .25
@noindent
@strong{NOTE:} In an @code{xterm} window, when you're running a tool or
application locally in a shell (such as the @code{lynx} Web browser),
the left mouse button alone won't work. When this happens, press and
hold the @key{SHIFT} key while using the mouse to select text.
@menu
* Cutting Text:: Cutting out a selection of text.
* Pasting Text:: Pasting in a selection of text.
@end menu
@node Cutting Text, Pasting Text, Selecting Text, Selecting Text
@comment node-name, next, previous, up
@subsection Cutting Text
@cindex cutting text
@cindex text, cutting
@cindex killing text
@cindex mark
@noindent
You don't have to select text to cut it. At a shell prompt or in Emacs,
type @kbd{C-k} to cut the text from the cursor to the end of the line.
In Emacs parlance, cutting text is known as @dfn{killing} text. Emacs
has additional commands for killing text:
@itemize @bullet
@item
When you have selected an area of text with the mouse as described
previously, you can type @kbd{@key{Shift}-@key{DEL}} to delete it.
@item
You can also click the left mouse button at one end of an area of text
and then double-click the right mouse button at the other end of the
area to kill the area of text.
@item
Finally, to kill a large portion of text in an Emacs buffer, set the
@dfn{mark} at one end of the text by moving point to that end and typing
@kbd{C-@key{SPC}}. Then, move point to the other end of the text, and
type @kbd{C-w} to kill it.
@end itemize
@node Pasting Text, , Cutting Text, Selecting Text
@comment node-name, next, previous, up
@subsection Pasting Text
@cindex pasting text
@cindex text, pasting
@cindex yanking text
@pindex xpaste
@flushleft
@sf{Debian}: @file{xpaste}
@end flushleft
@*
@noindent
To paste the text that was last selected with the mouse, click the
middle mouse button at the place you want to paste to. You can also use
the keyboard by moving the cursor to where you want to paste and then
typing @kbd{@key{Shift}-@key{INS}}. These commands work both in X and in
the console.
In X, to display the contents of the X selection in its own window, run
the @code{xpaste} X client; its only purpose in life is to display this
text in its window.
In Emacs, pasting text is called @dfn{yanking} the text. Emacs offers
the additional key, @kbd{C-y} (``yank''), to yank the text that was
last selected or killed. This key also works in the @code{bash} shell,
where it pastes the last text that was killed with @kbd{C-k} in that
shell session, if any.
@node Stream Editing, Concatenating Text, Selecting Text, Text Editing
@comment node-name, next, previous, up
@section Editing Streams of Text
@cindex editing streams of text
@cindex text, editing streams of
@cindex streams, text
@cindex @cite{GNU Awk User's Guide, The}
@cindex @cite{Picking Up Perl}
@pindex sed
@pindex gawk
@pindex perl
@noindent
Some of the recipes in this book that work on text use @code{sed}, the
``stream editor.'' It is not a text editor in the usual sense---you
don't open a file in @code{sed} and interactively edit it; instead, it
performs editing operations on a @emph{stream} of text sent to its
standard input, and it writes the results to the standard output. This
is more like a filter than an editor, and @code{sed} is a useful tool
for formatting and searching through text.
@uref{http://seders.icheme.org/, ``The seder's grab-bag''} is a useful
collection of @code{sed} information including a FAQ and many example
scripts.
The @code{sed} @uref{http://www-h.eng.cam.ac.uk/help/tpl/unix/sed.html,
``one-liners''} are useful commands for editing and processing text.
@inforef{Top, GNU SED, sed.info}, for more information on @code{sed}
usage.
Other tools that are good for stream editing include the AWK and Perl
programming languages; to learn more about using these powerful
languages, I recommend the following books:
@itemize @bullet
@item
@uref{http://www.gnu.org/manual/gawk-3.0.3/gawk.html, @cite{The GNU Awk
User's Guide}}
@item
@uref{http://www.ebb.org/PickingUpPerl/, @cite{Picking Up Perl}}
@end itemize
@node Concatenating Text, Including Text, Stream Editing, Text Editing
@comment node-name, next, previous, up
@section Concatenating Text
@cindex concatenating text
@cindex text, concatenating
@pindex cat
@pindex zcat
@noindent
The @code{cat} tool gets its name because it con@emph{cat}enates all of
the text given to it, outputting the result to the standard output. It
is useful for concatenating files of text together.
For example, suppose you have two files, @file{early} and @file{later}.
The file @file{early} contains this text:
@example
This Side of Paradise
The Beautiful and Damned
@end example
And the file @file{later} contains this text:
@example
The Great Gatsby
Tender Is the Night
The Last Tycoon
@end example
@itemize @bullet
@item
To concatenate these files into a new file, @file{novels}, type:
@example
$ @kbd{cat early later > novels @key{RET}}
@end example
@end itemize
This command redirects the standard output to a new file, @file{novels},
which would then contain the following text:
@example
This Side of Paradise
The Beautiful and Damned
The Great Gatsby
Tender Is the Night
The Last Tycoon
@end example
The files @file{early} and @file{later} are not altered.
Had you typed @kbd{cat later early > novels} instead, the files would be
concatenated in that reversed order instead, beginning with
@file{later}; so the file @file{novels} would contain the following:
@example
The Great Gatsby
Tender Is the Night
The Last Tycoon
This Side of Paradise
The Beautiful and Damned
@end example
The following sections give other recipes for concatenating text.
@sp .25
@noindent
@strong{NOTE:} You can also use @code{cat} to concatenate files that are
@emph{not} text, but its most popular usage is with text files. Another
way to concatenate files of text in an automated way is to use file
@emph{inclusion}---see @ref{Including Text, , Including Text Files}.
A similar tool, @code{zcat}, reads the contents of compressed files.
@menu
* Writing Text:: Writing text to a file.
* Appending Text:: Appending text to the end of a file.
* Inserting Text:: Inserting text to the beginning of a file.
@end menu
@node Writing Text, Appending Text, Concatenating Text, Concatenating Text
@comment node-name, next, previous, up
@subsection Writing Text to Files
@cindex writing text to files
@cindex text, writing to files
@cindex files, writing text to
@cindex micro-editing, text
@noindent
Sometimes, it's too much trouble to call up a text editor for a
particular job---you just want to write a text file with two lines in
it, say, or you just want to append a text file with one line. There are
ways of doing these kind of micro-editing jobs without a text editor.
To write a text file without using a text editor, redirect the standard
output of @code{cat} to the file to write. You can then type your text,
typing @kbd{C-d} on a line of its own to end the file. This is useful
when you want to quickly create a small text file, but that is about it;
usually, you open or create a text file in a text editor, as described
in the previous sections in this chapter.
@itemize @bullet
@item
To make a file, @file{novels}, with some text in it, type:
@example
@cartouche
$ @kbd{cat > novels @key{RET}
This Side of Paradise @key{RET}
The Beautiful and Damned @key{RET}
The Great Gatsby @key{RET}
Tender Is the Night @key{RET}
C-d}
$
@end cartouche
@end example
@end itemize
In this example, the text file @file{novels} was created and contains
four lines of text (the last line with the @kbd{C-d} is never part of
the file).
Typing text like this without an editor will sometimes do in a pinch
but, if you make a mistake, there is not much recourse besides starting
over---you can type @kbd{C-u} to erase the current line, and @kbd{C-c}
to abort the whole thing and not write the text to a file at all, but
that's about it.
@node Appending Text, Inserting Text, Writing Text, Concatenating Text
@comment node-name, next, previous, up
@subsection Appending Text to a File
@cindex appending text to a file
@cindex text, appending to a file
@cindex file, appending text to a
@noindent
To add text to a text file without opening the file in a text editor,
use @code{cat} with the append operator, @samp{>>}. (Using @samp{>}
instead would overwrite the file.)
@itemize @bullet
@item
To add a line of text to the bottom of file @file{novels}, type:
@example
$ @kbd{cat >> novels @key{RET}
The Last Tycoon @key{RET}
C-d}
@end example
@end itemize
In this example, no files were specified to @code{cat} for input, so
@code{cat} used the standard input; then, one line of text was typed,
and this text was appended to file @file{novels}, the file used in the
example of the previous recipe. So now this file would contain the
following:
@example
This Side of Paradise
The Beautiful and Damned
The Great Gatsby
Tender Is the Night
The Last Tycoon
@end example
@node Inserting Text, , Appending Text, Concatenating Text
@comment node-name, next, previous, up
@subsection Inserting Text at the Beginning of a File
@cindex inserting text at the beginning of a file
@cindex text, inserting at the beginning of a file
@cindex file, inserting text at the beginning of a
@pindex ins
@flushleft
@sf{WWW}: @url{http://dsl.org/comp/tinyutils/}
@end flushleft
@*
@noindent
Inserting text at the @emph{beginning} of a text file without calling up
a text editor is a bit trickier than appending text to a file's
end---but it @emph{is} possible.
To insert one or more lines of text at the beginning of a file, use
@code{ins}. Give the name of the file in which to insert text as an
argument; @code{ins} will read lines of text from the standard input and
insert them at the beginning of the file. (It works by opening the file
in @code{ed}, a simple line editor.)
Give the EOF---that is, type @kbd{C-d} on a line by itself---to signify
the end of the lines of text to insert.
@itemize @bullet
@item
To insert several lines of text at the beginning of the file
@file{novels}, type:
@example
@cartouche
$ @kbd{ins novels @key{RET}
The Novels of F. Scott Fitzgerald @key{RET}
--------------------------------- @key{RET}
C-d}
$
@end cartouche
@end example
@end itemize
This command inserts two lines of text at the beginning of
@code{novels}, the file used in the previous examples in this
section. This file would now contain the following:
@example
The Novels of F. Scott Fitzgerald
---------------------------------
This Side of Paradise
The Beautiful and Damned
The Great Gatsby
Tender Is the Night
The Last Tycoon
@end example
@node Including Text, , Concatenating Text, Text Editing
@comment node-name, next, previous, up
@section Including Text Files
@cindex including text files
@cindex text files, including
@cindex inclusion
@cindex include file
@pindex m4
@flushleft
@sf{Debian}: @file{m4}
@end flushleft
@*
@noindent
File @dfn{inclusion} is where the contents of a file can be included at
a particular place within some other file, just by specifying the file's
name at that place in the other file.
This is useful if you want or need to frequently rearrange divisions or
sections of a document, if you need to keep a document in more than one
arrangement, or if you have some sections of text that you frequently
insert in more than one document. For these situations, you can keep
each section in a separate file and build an @dfn{include file} that
contains the file names for the various sections in the order you want
to generate that file.
To include a file in a text file, specify the file to be included on a
line of its own, like this:
@example
include(@var{file})
@end example
When you process this file for inclusion, the line with the
@samp{include} statement is replaced with the contents of the file
@var{file} (whose path is relative to the current directory of the
include file).
Use the @code{m4} tool, the GNU macro processor, to process an include
file. It takes as an argument the name of the include file, and it
outputs the inclusion to the standard output. You can use redirection to
redirect the output to a file.
For example, suppose the file @file{soups} contains this text:
@example
@cartouche
Clam Chowder
Lobster Bisque
Vegetable
@end cartouche
@end example
And suppose the file @file{sandwiches} contains this text:
@example
@cartouche
BLT
Ham on Rye
Roast Beef
@end cartouche
@end example
And finally, suppose the file @file{menu} contains this text:
@example
@cartouche
Diner Menu For Today
Soups
-----
include(soups)
Sandwiches
----------
include(sandwiches)
@end cartouche
@end example
@itemize @bullet
@item
To process the file and write to the file @file{monday.txt}, type:
@example
$ @kbd{m4 menu > monday.txt @key{RET}}
@end example
@end itemize
This command writes a new file, @file{monday.txt}, which looks like
this:
@example
@cartouche
Diner Menu For Today
Soups
-----
Clam Chowder
Lobster Bisque
Vegetable
Sandwiches
----------
BLT
Ham on Rye
Roast Beef
@end cartouche
@end example
@sp .25
@noindent
@strong{NOTE:} You can write more than one include file that will use
your files---and the files themselves can have include files of their
own.
This is a fairly simple use of @code{m4}; it can do much more, including
run commands, manipulate text, and run custom macros. @inforef{Top, GNU
m4, m4.info} for more information on this tool.
|