Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!necntc!ncoast!allbery From: nwd@j.cc.purdue.edu (Daniel Lawrence) Newsgroups: comp.sources.misc Subject: MicroEmacs 3.9 Manual (1 of 6) Message-ID: <5814@ncoast.UUCP> Date: Wed, 25-Nov-87 23:13:39 EST Article-I.D.: ncoast.5814 Posted: Wed Nov 25 23:13:39 1987 Date-Received: Mon, 30-Nov-87 00:54:55 EST Sender: allbery@ncoast.UUCP Lines: 1110 Approved: allbery@ncoast.UUCP X-Archive: comp.sources.misc/8711/12 [Sorry for the hiatus. A short trip out of state turned out to be longer than I expected; ``the best-laid plans,'' and so on. This shar archive arrived in pieces; you must save the messages, chop off headers and trailers, concatenate, THEN unshar. Somewhat bogus, by my reckoning.... ++bsa] # This is a shar archive. # Remove everything above this line. # Run the file through sh, not csh. # (type `sh this_file') # If you do not see the message # `this_file completed!' # then the file was incomplete. echo extracting - emacs.mss sed 's/^X//' > emacs.mss << 'FRIDAY_NIGHT' X@style(indent 8 chars, spacing 1 lines) X@pagefooting() X X X X X X X X X X X X X @big(MicroEMACS) X X Full Screen Text Editor X Reference Manual (preliminary draft) X X Version 3.9e X November 4, 1987 X X (C)opyright 1987 by Daniel M. Lawrence X Reference Manual (C)opyright 1987 X by Brian Straight and Daniel M. Lawrence X All Rights Reserved X X @i(MicroEMACS 3.9e can be copied and distributed freely X for any non-commercial purposes. MicroEMACS 3.9e can X only be incorporated into commercial software with X the permission of the current author.) X@newpage X@newpage X@flushleft(@big[Introduction]) X X MicroEMACS is a tool for creating and changing documents, Xprograms, and other text files. It is both relatively easy for the Xnovice to use, but also very powerful in the hands of an expert. XMicroEMACS can be extensively customized for the needs of the Xindividual user. X X MicroEMACS allows several files to be edited at the same time. XThe screen can be split into different windows, and text may be moved Xfreely from one window to the next. Depending on the type of file being Xedited, MicroEMACS can change how it behaves to make editing simple. XEditing standard text files, program files and word processing documents Xare all possible at the same time. X X There are extensive capabilities to make word processing and Xediting easier. These include commands for string searching and Xreplacing, paragraph reformatting and deleting, automatic word wrapping, Xword move and deletes, easy case controlling, and automatic word counts. X X For complex and repetitive editing tasks editing macroes can be Xwritten. These macroes allow the user a great degree of flexibility in Xdetermining how MicroEMACS behaves. Also, any and all the commands can Xbe used by any keystroke by changing, or rebinding, what commands Xvarious keys are connected, or bound, to. X X Special features are also available to perform a diverse set of Xoperations such as file encryption, automatic backup file generation, Xentabbing and detabbing lines, executing of DOS commands and filtering Xof text through other programs (like SORT to allow sorting text). X X@flushleft(@big[History]) X X EMACS was originally a text editor written by Richard Stahlman Xat MIT in the early 1970s for Digital Equipment computers. Various Xversions, rewrites and clones have made an appearence since. X X This version of MicroEMACS is derived from code written by Dave XG. Conroy in 1985. Later modifications were performed by Steve Wilhite Xand George Jones. In December of 1985 Daniel Lawrence picked up the Xthen current source (version 2.0) and made extensive modifications and Xadditions to it over the course of the next two years. Updates and Xsupport for the current version are still availible. The current Xprogram author can be contacted by writing to: X X@begin(verbatim) X USMAIL: Daniel Lawrence X 617 New York St X Lafayette, IN 47901 X X UUCP: ihnp4!pur-ee!pur-phy!duncan!lawrence X ARPA: nwd@@j.cc.purdue.edu X FIDO: Fido 201/2 The Programmer's Room (317) 742-5533 X@end(verbatim) X@string(ChapterTitle="") X@set(page = 0) X@pageheading(odd, left "@title[Chapter]", right "MicroEMACS Reference Manual") X@pageheading(even, left "MicroEMACS Reference Manual", right "@title[Chapter]") X@pagefooting(odd, left="@value(page)") X@pagefooting(even, right="@value(page)") X@chapter(Basic Concepts) X X The current version of MicroEMACS is 3.9e (Third major re-write, Xninth public release, fifth minor edit), and for the rest of this Xdocument, we shall simply refer to this version as "EMACS". Any Xmodifications for later versions will be listed in the appendixes at the Xend of this manual. X X@section(Keys and the Keyboard) X X Many times throughout this manual we will be talking about X@index(special keys) commands and the keys on the keyboard needed to use Xthem. There are a number of "special" keys which can be used and are Xlisted here: X X@begin(description) X@\NewLine which is also called RETURN or ENTER, this key is used to X@index(newline) end different commands. X X^@\The control key can be used before any alphabetic character and some Xsymbols. For example, ^C means to hold down the key and type X@index(control key) the C key at the same time. X X^X@\The CONTROL-X key is used at the beginning of many different X@index(control-x) commands. X XMETA or M-@\This is a special EMACS key used to begin many commands as X@index(meta key) well. This key is pressed and then released before Xtyping the next character. On most systems, this is the key, but Xit can be changed. (consult appendix E to learn what key is used for XMETA on your computer). X@end(description) X XWhenever a command is described, the manual will list the actual Xkeystrokes needed to execute it in @b(boldface) using the above Xconventions, and also the name of the command in @i(italics). X@section(Getting Started) X X In order to use EMACS, you must call it up from your system or Xcomputer's command prompt. On UNIX and MSDOS machines, just type X"emacs" from the main command prompt and follow it with the or X key (we will refer to this key as for "new-line" for the Xremainder of this manual). On the Macintosh, the Amiga, the ATARI ST Xand other icon based operating systems, double click on the uEMACS icon. XShortly after this, a screen similar to the one below should appear. X X@section(Parts and Pieces) X X The screen is divided into a number of areas or @b. On Xsome systems the top window contains a function list of unshifted and X@index(windows) shifted function keys. We will discuss these keys later. X@index(mode line) Below them is an EMACS @b which, as we will Xsee, informs you of the present mode of operation of the editor--for Xexample "(WRAP)" if you set EMACS to wrap at the end of each line. X@index(text window) Under the mode line is the @b where text Xappears and is manipulated. Since each window has its own mode line, Xbelow the text window is it's mode line. The last line of the screen is Xthe @b(command line) where EMACS takes commands and reports on what it Xis doing. X X@begin(verbatim) X=============================================================================== Xf1 search-> f2 <-search | MicroEMACS: Text Editor Xf3 hunt-> f4 <-hunt | Xf5 fkeys f6 help | Available function key Pages include: Xf7 nxt wind f8 pg[ ] | WORD PROG BOX Xf9 save f10 exit | [use the f8 key to load Pages] X=============================================================================== X-- MicroEMACS 3.9e () -- Function Keys --------------------------------------- X=============================================================================== X X X X X X X X X X X X X=============================================================================== X-- MicroEMACS 3.9e () -- Main ------------------------------------------------ X=============================================================================== X Fig 1: EMACS screen on an IBM-PC X@end(verbatim) X X@section(Entering Text) X XEntering text in EMACS is simple. Type the following sentence fragment: X X@quotation X X@flushleft(The text is displayed at the top of the text window. Now type:) X X@quotation X XNotice the text to the left of the cursor disappears and a '$' sign Xappears. Don't panic--your text is safe!!! You've just discovered that XEMACS doesn't "wrap" text to the next line like most word processors Xunless you hit . But since EMACS is used for both word processing, Xand text editing, it has a bit of a dual personality. You can change X@index(modes) the way it works by setting various @b(modes). In this Xcase, you need to set @b(WRAP) mode, using the @i(add-mode) X@index(add-mode) command, by typing @b(^X-M). The command line at the Xbase of the screen will prompt you for the mode you wish to add. Type X@b followed by the key and any text you now enter will be Xwrapped. However, the command doesn't wrap text already entered. To Xget rid of the truncated line, delete characters with the Xkey until the '$' goes away. Now type in the words you deleted, watch Xhow EMACS goes down to the next line at the right time. @i{(In some Xversions of EMACS, @b is a default mode in which case you don't Xhave to worry about the instructions relating to adding this mode.)} X XNow let's type a longer insert. Hit a couple of times to tab Xdown from the text you just entered. Now type the following paragraphs. XPress twice to indicate a paragraph break. X X@quotation X X@section X XNow let's practice moving around in this text. To move the cursor back Xto the word "Winding," enter @b @i(previous-word) X@index(previous-word). This command moves the cursor backwards by one Xword at a time. Note you have to press the key combination every time Xthe cursor steps back by one word. Continuously pressing META and Xtoggling B produces an error message. To move forward to the word X"stairs" enter @b, which moves the cursor forward by one word at a Xtime. X XNotice that EMACS commands are usually mnemonic--F for forward, B for Xbackward, for example. X XTo move the cursor up one line, enter @b<^P> @i(previous-line) X@index(previous-line), down one line @b<^N> @i(next-line) X@index(next-line). Practice this movement by moving the cursor to the Xword "terrifying" in the second line. X XThe cursor may also be moved forward or backward in smaller increments. XTo move forward by one character, enter @b<^F> @i(forward-character) X@index(forward-character), to move backward, @b<^B> X@i(backward-character) @index(backward-character). EMACS also allows Xyou to specify a number which is normally used to tell a command to Xexecute many times. To repeat most commands, press META and then the Xnumber before you enter the command. Thus, the command META 5 ^F X(@b) will move the cursor forward by five characters. Try moving Xaround in the text by using these commands. For extra practice, see how Xclose you can come to the word "small" in the first paragraph by giving Xan argument to the commands listed here. X XTwo other simple cursor commands that are useful to help us move around Xin the text are @b @i(next-paragraph) @index(next-paragraph) which Xmoves the cursor to the second paragraph, and @b X@i(previous-paragraph) @index(previous-paragraph) which moves it back to Xthe previous paragraph. The cursor may also be moved rapidly from one Xend of the line to the other. Move the cursor to the word "few" in the Xsecond line. Press @b<^A> @i(beginning-of-line) X@index(beginning-of-line). Notice the cursor moves to the word "events" Xat the beginning of the line. Pressing @b<^E> @i(end-of-line) X@index(end-of-line) moves the cursor to the end of the line. X XFinally, the cursor may be moved from any point in the file to the end Xor beginning of the file. Entering @b{M->} @i(end-of-file) X@index(end-of-file) moves the cursor to the end of the buffer, @b{M-<} X@i(beginning-of-file) @index(beginning-of-file) to the first character Xof the file. X X@i(On the IBM-PC, the ATARI ST and many other machines, the cursor keys X@index(cursor keys) can also be used to move the cursor about. Also, if Xthere is one available, moving the mouse will move the cursor.) X XPractice moving the cursor in the text until you are comfortable with Xthe commands we've explored in this chapter. X X@section(Saving your text) X XWhen you've finished practicing cursor movement, save your file. Your X@index(buffer) file currently resides in a @b. The buffer is a Xtemporary storage area for your text, and is lost when the computer is Xturned off. You can save the buffer to a file by entering @b<^X-^S> X@i(save-file) @index(save-file). Notice that EMACS informs you that Xyour file has no name and will not let you save it. X XTo save your buffer to a file with a different name than it's current Xone (which is empty), press @b<^X^W> @i(write-file) @index(write-file). XEMACS will prompt you for the filename you wish to write. Enter the Xname @b and press return. On a micro, the drive light will Xcome on, and EMACS will inform you it is writing the file. When it Xfinishes, it will inform you of the number of lines it has written to Xthe disk. X XCongratulations!! You've just saved your first EMACS file! X@newpage X@heading(Chapter @value(chapter) Summary) X X In chapter @value(chapter), you learned how to enter text, how Xto use wrap mode, how to move the cursor, and to save a buffer. The Xfollowing is a table of the commands covered in this chapter and their Xcorresponding key bindings: X X@begin{verbatim} X@u(Key Binding Keystroke Effect) X Xabort-command @b<^G> aborts current command X Xadd-mode @b<^XM> allows addition of EMACS X mode such as @b(WRAP) X Xbackward-character @b<^B> moves cursor left one character X Xbeginning-of-file @b{M-<} moves cursor to beginning of file X Xbeginning-of-line @b<^A> moves cursor to beginning of line X Xend-of-file @b{M->} moves cursor to end of file X Xend-of-line @b<^E> moves cursor to end of line X Xforward-character @b<^F> moves cursor right one character X Xnext-line @b<^N> moves cursor to next line X Xnext-paragraph @b moves cursor to next paragraph X Xnext-word @b moves cursor forward one word X Xprevious-line @b<^P> moves cursor backward by one line X Xprevious-paragraph @b moves cursor to previous paragraph X Xprevious-word @b moves cursor backward by one word X Xsave-file @b<^X-^S> saves current buffer to a file X Xwrite-file @b<^X-^W> save current buffer under a new name X@end(verbatim) X@newpage X@chapter(Basic Editing--Simple Insertions and Deletions) X X@section X XIn the first chapter, you learned how to create and save a file in XEMACS. Let's do some more editing on this file. Call up emacs by Xtyping in the following command. X X@b X X@i(On icon oriented systems, double click on the uEMACS icon, usually a Xfile dialog box of some sort will appear. Choose @b(FANG.TXT) from the Xappropriate folder.) X XShortly after you invoke EMACS, the text should appear on the screen Xready for you to edit. The text you are looking at currently resides in Xa @b. A buffer is a temporary area of computer memory which is X@index(buffer) the primary unit internal to EMACS -- this is the place Xwhere EMACS goes to work. The mode line at the bottom of the screen Xlists the buffer name, @b and the name of the file with which Xthis buffer is associated, @b X XThe computer talks to you through the use of its @b(screen). This X@index(screen) screen usually has an area of 24 lines each of 80 Xcharacters across. You can use EMACS to subdivide the screen into Xseveral separate work areas, or @b(windows), each of which can be X@index(window) 'looking into' different files or sections of text. Using Xwindows, you can work on several related texts at one time, copying and Xmoving blocks of text between windows with ease. To keep track of what Xyou are editing, each window is identified by a @b(mode line) on the X@index(mode line) @index(buffer) last line of the window which lists the Xname of the @b(buffer) which it is looking into, the file from which the Xtext was read, and how the text is being edited. X XAn EMACS @b tells EMACS how to deal with user input. As we have Xalready seen, the mode 'WRAP' controls how EMACS deals with long lines X(lines with over 79 characters) while the user is typing them in. The X'VIEW' mode, allows you to read a file without modifying it. Modes are Xassociated with buffers and not with files; hence, a mode needs to be Xexplicitly set or removed every time you edit a file. A new file read Xinto a buffer with a previously specified mode will be edited under this Xmode. If you use specific modes frequently, EMACS allows you to set Xthe modes which are used by all new buffers, called @b modes. X X@section X XYour previously-saved text should look like this: X X@quotation X XLet's assume you want to add a sentence in the second paragraph after Xthe word "base." Move the cursor until it is on the "W" of "Winding". XNow type the following: X X@quotation X XIf the line fails to wrap and you end up with a '$' sign in the right Xmargin, just enter @b{M-Q} @i(fill-paragraph) @index(fill-paragraph) to Xreformat the paragraph. This new command attempts to fill out a Xparagraph. Long lines are divided up, and words are shuffled around to Xmake the paragraph look nicer. X XNotice that all visible EMACS characters are self-inserting -- all you Xhad to do was type the characters to insert and the existing text made Xspace for it. With a few exceptions discussed later, all non-printing Xcharacters (such as control or escape sequences) are commands. To Xinsert spaces, simply use the space bar. Now move to the first line of Xthe file and type @b{^O} @i(open-line) @index(open-line) (Oh, not zero). XYou've just learned how to insert a blank line in your text. X X@section X XEMACS offers a number of deletion options. For example, move the cursor Xuntil it's under the period at the end of the insertion you just did. XPress the backspace key. Notice the "n" on "lantern" disappeared. The Xbackspace implemented on EMACS is called a @b backspace--it Xremoves text immediately before the current cursor position from the Xbuffer. Now type @b<^H> @i(delete-previous-character) X@index(delete-previous-character). Notice that the cursor moves back Xand obliterates the "r"--either command will backspace the cursor. X XType in the two letters you erased to restore your text and move the Xcursor to the beginning of the buffer @b{M->} @i(beginning-of-file) X@index(beginning-of-file). Move the cursor down one line to the Xbeginning of the first paragraph. X XTo delete the forward character, type @b{^D} @i(delete-next-character) X@index(delete-next-character). The "F" of "Fang" disappears. Continue Xto type @b{^D} until the whole word is erased EMACS also permits the Xdeletion of larger elements of text. Move the cursor to the word X"center" in the first line of text. Pressing @b{M-} X@i(delete-previous-word) @index(delete-previous-word) kills the word Ximmediately before the cursor. @b{M-^H} has the same effect. X XNotice that the commands are very similar to the control commands you Xused to delete individual letters. As a general rule in EMACS, control Xsequences affect small areas of text, META sequences larger areas. The Xword forward of the cursor position can therefore be deleted by typing X@b{M-D} @i(delete-next-word) @index(delete-next-word). Now let's take Xout the remainder of the first line by typing @b{^K} X@i(kill-to-end-of-line) @index(kill-to-end-of-line). You now have a Xblank line at the top of your screen. Typing @b{^K} again or @b{^X-^O} X@i(delete-blank-lines) @index(delete-blank-lines) deletes the blank line Xand flushes the second line to the top of the text. Now exit EMACS by Xtyping @b{^X-^C} @i(exit-emacs) @index(exit-emacs). Notice EMACS Xreminds you that you have not saved your buffer. Ignore the warning and Xexit. This way you can exit EMACS without saving any of the changes you Xjust made. X X@heading(Chapter @value(chapter) Summary) X XIn Chapter @value(chapter), you learned about the basic 'building Xblocks' of an EMACS text file--buffers, windows, and files. X X@begin{verbatim} X@u(Key binding Keystroke Effect) Xdelete-previous-character X @b{^H} deletes character immediately before X the current cursor position X Xdelete-next-character @b{^D} deletes character immediately after X current cursor position X Xdelete-previous-word @b{M-^H} deletes word immediately before X current cursor position X Xdelete-next-word @b{M-D} deletes word immediately after X current cursor position X Xkill-to-end-of-line @b<^K> deletes from current cursor X position to end of line X Xinsert-space @b<^C> inserts a space to right of cursor X Xopen-line @b{^O} inserts blank line X Xdelete-blank-lines @b{^X-^O} removes blank line X Xexit-emacs @b{^X-^C} exits emacs X@end(verbatim) X@chapter(Using Regions) X X@section(Defining and Deleting a Region) X XAt this point its time to familiarize ourselves with two more EMACS Xterms--the @b and the @b. The point is located directly X@index(point) @index(mark) behind the current cursor position. The mark X(as we shall see shortly) is user defined. These two elements together Xare called the current @b(region) and limit the @b of text on Xwhich EMACS performs many of its editing functions. X XLet's begin by entering some new text. Don't forget to add @b(wrap) Xmode if its not set on this buffer. Start EMACS and open a file called X@b{PUBLISH.TXT}. Type in the following text: X X@quotation{One of the largest growth areas in personal computing is Xelectronic publishing. There are packages available for practically Xevery machine from elegantly simple programs for the humble Commodore 64 Xto sophisticated professional packages for PC and Macintosh computers. X XElectronic publishing is as revolutionary in its way as the Gutenburg Xpress. Whereas the printing press allowed the mass production and Xdistribution of the written word, electronic publishing puts the means Xof production in the hands of nearly every individual. From the class Xmagazine to the corporate report, electronic publishing is changing the Xway we produce and disseminate information. X XPersonal publishing greatly increases the utility of practically every Xcomputer. Thousands of people who joined the computer revolution of Xthis decade only to hide their machines unused in closets have Xdiscovered a new use for them as dedicated publishing workstations.} X XNow let's do some editing. The last paragraph seems a little out of Xplace. To see what the document looks like without it we can cut it Xfrom the text by moving the cursor to the beginning of the paragraph. XEnter @b(M-) @i(set-mark) @index(set-mark). EMACS will respond Xwith "[Mark set]". Now move the cursor to the end of the paragraph. XYou have just defined a region of text. To remove this text from the Xscreen, type @b<^W> @i(kill-region) @index(kill-region). The paragraph Xdisappears from the screen. X XOn further consideration, however, perhaps the paragraph we cut wasn't Xso bad after all. The problem may have been one of placement. If we Xcould tack it on to the end of the first paragraph it might work quite Xwell to support and strengthen the argument. Move the cursor to the end Xof the first paragraph and enter @b<^Y> @i(yank) @index(yank). Your Xtext should now look like this: X X@quotation{One of the largest growth areas in personal computing is Xelectronic publishing. There are packages available for practically Xevery machine from elegantly simple programs for the humble Commodore 64 Xto sophisticated professional packages for PC and Macintosh computers. XPersonal publishing greatly increases the utility of practically every Xcomputer. Thousands of people who joined the computer revolution of Xthis decade only to hide their machines unused in closets have Xdiscovered a new use for them as dedicated publishing workstations. X XElectronic publishing is as revolutionary in its way as the Gutenburg Xpress. Whereas the printing press allowed the mass production and Xdistribution of the written word, electronic publishing puts the means Xof production in the hands of nearly every individual. From the class Xmagazine to the corporate report, electronic publishing is changing the Xway we produce and disseminate information.} X X@section(Yanking a Region) X XThe text you cut initially didn't simply just disappear, it was cut into Xa buffer that retains the 'killed' text appropriately called the @b. @b<^Y> "yanks" the text back from this buffer into the current Xbuffer. If you have a long line (indicated, remember, by the "$" Xsign), simply hit @b{M-Q} to reformat the paragraph. X XThere are other uses to which the kill buffer can be put. Using the X@index(kill buffer) method we've already learned, define the last Xparagraph as a region. Now type @b @i(copy-region) X@index(copy-region). Nothing seems to have happened; the cursor stays Xblinking at the point. But things have changed, even though you may not Xbe able to see any alteration. X XTo see what has happened to the contents of the kill buffer, move the Xcursor down a couple of lines and "yank" the contents of the kill buffer Xback with @b<^Y>. Notice the last paragraph is now repeated. The Xregion you defined is "tacked on" to the end of your file because X@b @b a region to the kill buffer while leaving the Xoriginal text in your working buffer. Some caution is needed however, Xbecause the contents of the kill buffer are updated when you delete any Xregions, lines or words. If you are moving large quantities of text, Xcomplete the operation before you do any more deletions or you could Xfind that the text you want to move has been replaced by the most recent Xdeletion. Remember--a buffer is a temporary area of computer memory Xthat is lost when the machine is powered down or switched off. In order Xto make your changes permanent, they must be saved to a file before you Xleave EMACS. Let's delete the section of text we just added and save Xthe file to disk. X X@heading(Chapter @value(chapter) Summary) X XIn Chapter @value(chapter), you learned how to achieve longer insertions Xand deletions. The EMACS terms @b and @b were introduced Xand you learned how to manipulate text with the kill buffer. X X@begin{verbatim} X@begin(group) X@u(Key Binding Keystroke Effect) X XDelete-Region @b{^W} Deletes region between point and mark and X places it in KILL buffer X XCopy-Region @b{M-W} Copies text between point and mark into X KILL buffer X XYank-Text @b{^Y} Inserts a copy of the KILL buffer into X current buffer at point X@end(group) X@end(verbatim) X@chapter(Search and Replace) X X@section X XLoad EMACS and bring in the file you just saved. Your file should look Xlike the one below. X X@quotation{One of the largest growth areas in personal computing is electronic Xpublishing. There are packages available for practically every machine Xfrom elegantly simple programs for the humble Commodore 64 to Xsophisticated professional packages for PC and Macintosh computers. XPersonal publishing greatly increases the utility of practically every Xcomputer. Thousands of people who joined the computer revolution of Xthis decade only to hide their machines unused in closets have Xdiscovered a new use for them as dedicated publishing workstations. X XElectronic publishing is as revolutionary in its way as the Gutenburg Xpress. Whereas the printing press allowed the mass production and Xdistribution of the written word, electronic publishing puts the means Xof production in the hands of nearly every individual. From the class Xmagazine to the corporate report, electronic publishing is changing the Xway we produce and disseminate information.} X XLet's use EMACS to search for the word "revolutionary" in the second Xparagraph. Because EMACS searches from the current cursor position Xtoward the end of buffers, and we intend to search forward, move the Xcursor to the beginning of the text. Enter @b<^S> @i(search-forward) X@index(search-forward). Note that the command line now reads X X"Search [] :" X XEMACS is prompting you to enter the @b -- the text you Xwant to find. Enter the word @b and hit the @b Xkey. The cursor moves to the end of the word "revolutionary." X XNotice that you must enter the key to start the search. If you X@index() simply press the command line responds with "". XAlthough this may seem infuriating to users who are used to pressing the Xreturn key to execute any command, EMACS' use of to begin Xsearches allows it to pinpoint text with great accuracy. After every Xline wrap or carriage return, EMACS 'sees' a new line character (). XIf you need to search for a word at the end of a line, you can specify Xthis word uniquely in EMACS. X XIn our sample text for example, the word "and" occurs a number of times, Xbut only once at the end of a line. To search for this particular Xoccurence of the word, move the cursor to the beginning of the buffer Xand type @b(^S). Notice that EMACS stores the last specified X@index(default string) search string as the @b string. If you Xpress @b{} now, EMACS will search for the default string, in this Xcase, "revolutionary." X XTo change this string so we can search for our specified "and" simply Xenter the word @b{and} followed by @b{}. The command Xline now shows: X X"search [and]:" X XPress @b{} and the cursor moves to "and" at the end of the second Xlast line. X X@section X XIf the mode EXACT is active in the current buffer, EMACS searches on a case Xsensitive basis. Thus, for example you could search for @b{Publishing} Xas distinct from @b{publishing}. X X X@section X XBackward searching is very similar to forward searching except that it Xis implemented in the reverse direction. To implement a reverse search, Xtype @b{^R} @i(search-reverse) @index(search-reverse). Because EMACS Xmakes no distinction between forward and backward stored search strings, Xthe last search item you entered appears as the default string. Try Xsearching back for any word that lies between the cursor and the Xbeginning of the buffer. Notice that when the item is found, the point Xmoves to the beginning of the found string (i.e., the cursor appears Xunder the first letter of the search item). X XPractice searching for other words in your text. X X@section X XSearching and replacing is a powerful and quick way of making changes to Xyour text. Our sample text is about electronic publishing, but the Xcorrect term is 'desktop' publishing. To make the necessary changes we Xneed to replace all occurences of the word "electronic" with "desktop." XFirst, move the cursor to the top of the current buffer with the @b(M-<) Xcommand. Then type @b[M-R] @i(replace-string) @index(replace-string). XThe command line responds: X X"Replace []:" X Xwhere the square brackets enclose the default string. Type the word X@b and hit @b{}. The command line responds: X X"with []" X Xtype @b{desktop}. EMACS replaces all instances of the original Xword with your revision. Of course, you will have to capitalize the Xfirst letter of "desktop" where it occurs at the beginning of a Xsentence. X XYou have just completed an @b. In this Xoperation, EMACS replaces every instance of the found string with the Xreplacement string. X X@section X XYou may also replace text on a case by case basis. The @b{M-^R} X@i(query-replace-string) @index(query-replace-string) command causes XEMACS to pause at each instance of the found string. X XFor example, assume we want to replace some instances of the word X"desktop" with the word "personal." Go back to the beginning of the Xcurrent buffer and enter the @b(M-^R) @i(query-replace) X@index(query-replace) command. The procedure is very similar to that Xwhich you followed in the unconditional search/replace option. When the Xsearch begins however, you will notice that EMACS pauses at each Xinstance of "publishing" and asks whether you wish to replace it with Xthe replacement string. You have a number of options available for Xresponse: X X@begin(verbatim) X@u( Response Effect) X Y(es) Make the current replacement and skip to the next X occurence of the search string X X N(o) Do not make this replacement but continue X X ! Do the rest of the replacements with no more queries X X U(ndo) Undo just the last replacement and query for it X again (This can only go back ONE time) X X ^G Abort the replacement command (This action does not X undo previously-authorized replacements X X . Same effect as ^G, but cursor returns to the point at X which the replacement command was given X X ? This lists help for the query replacement command X@end(verbatim) X XPractice searching and searching and replacing until you feel Xcomfortable with the commands and their effects. X@begin(group) X@heading(Chapter @value(chapter) Summary) X XIn this chapter, you learned how to search for specified strings of text Xin EMACS. The chapter also dealt with searching for and replacing Xelements within a buffer. X X@begin(verbatim) X@u(Key Binding Keystroke Effect) X XSearch-Forward @b{^S} Searches from point to end of buffer. X Point is moved from current location to X the end of the found string X XSearch-Backward @b{^R} Searches from point to beginning of buffer. X Point is moved from current location to X beginning of found string X XReplace @b{M-R} Replace ALL ocurrences of search string with X specified (null) string from point to the X end of the current buffer X XQuery-Replace @b{M-^R} As above, but pause at each found string X and query for action X@end(verbatim) X@end(group) X@chapter(Windows) X X@section@index{Windows, Creating} X XWe have already met windows in an earlier chapter. In this chapter, we Xwill explore one of EMACS' more powerful features -- text manipulation Xthrough multiple windowing. Windows offer you a powerful and easy way Xto edit text. By manipulating a number of windows and buffers on the Xscreen simultaneously, you can perform complete edits and revisions on Xthe computer screen while having your draft text or original data Xavailable for reference in another window. X XYou will recall that windows are areas of buffer text that you can see X@index(windows) on the screen. Because EMACS can support several screen Xwindows simultaneously you can use them to look into different places in Xthe same buffer. You can also use them to look at text in different Xbuffers. In effect, you can edit several files at the same time. X XLet's invoke EMACS and pull back our file on desktop publishing by Xtyping X X@quotation X XWhen the text appears, type the @b{^X-2} @i(split-window) X@index{split-window} command. The window splits into two windows. The Xwindow where the cursor resides is called the @b window -- in Xthis case the bottom window. Notice that each window has a text area Xand a mode line. The @b(command line) @index{command line} is however, Xcommon to all windows on the screen. X XThe two windows on your screen are virtually mirror images of each other Xbecause the new window is opened into the same buffer as the one you are Xin when you issue the @i{open-window command} @index{open-window}. All Xcommands issued to EMACS are executed on the current buffer in the Xcurrent window. X XTo move the cursor to the upper window (i.e., to make that window the Xcurrent window, type @b{^X-P} @i(previous-window) @index{previous-window}. XNotice the cursor Xmoves to the upper or @b window. Entering @b{^X-O} X@i(next-window) moves to the @b{next} window. Practice moving between Xwindows. You will notice that you can also move into the Function Key Xmenu by entering these commands. X XNow move to the upper window. Let's open a new file. On the EMACS disk Xis a tutorial file. Let's call it into the upper window by typing: X X@quotation<^X-^F> X Xand press return. X XEnter the filename @b. X XIn a short time, the tutorial file will appear in the window. We now have Xtwo windows on the screen, each looking into different buffers. We have Xjust used the @b(^X-^F) @i(find-file) @index{find-file} Xcommand to find a file and bring Xit into our current window. X XYou can scroll any window up and down with the cursor keys, or with the Xcommands we've learned so far. However, because the area of visible Xtext in each window is relatively small, you can scroll the current Xwindow a line at a time. X XType @b{^X-^N} @i(move-window-down)@index{move-window-down} X XThe current window scrolls down by one line -- the top line of text Xscrolls out of view, and the bottom line moves towards the top of the Xscreen. You can imagine, if you like, the whole window slowly moving Xdown to the end of the buffer in increments of one line. The command X@b{^X-^P} @i(move-window-up)@index{move-window-up} Xscrolls the window in the opposite Xdirection. X XAs we have seen, EMACS editing commands are executed in the current Xwindow, but the program does support a useful feature that allows you to Xscroll the @b window. X@b @i(scroll-next-up)@index{scroll-next-up} Xscrolls the next Xwindow up, @b{M-^V} @i(scroll-next-down)@index{scroll-next-down} Xscrolls it downward. From the Xtutorial window, practice scrolling the window with the desktop Xpublishing text in it up and down. X XWhen you're finished, exit EMACS without saving any changes in your Xfiles. X X XExperiment with splitting the windows on your screen. Open windows into Xdifferent buffers and experiment with any other files you may have. Try Xediting the text in each window, but Xdon't forget to save any changes you want to keep -- you still have to Xsave each buffer separately. X X@section(Deleting Windows)@index{Windows, Deleting} XWindows allow you to perform complex editing tasks with ease. However, Xthey become an inconvenience when your screen is cluttered with open Xwindows you have finished using. The simplest solution is to delete Xunneeded windows. The command @b{^X-0} @i{delete-window} Xwill delete the window you are currently working in and move you to the Xnext window. X XIf you have a number of windows open, you can delete all but the current Xwindow by entering @b{^X-1} @i{delete-other-windows}. X X@section(Resizing Windows)@index{Windows, Resizing} X XDuring complex editing tasks, you will probably find it convenient to Xhave a number of windows on the screen simultaneously. However this Xsituation may present inconveniences because the more windows you have Xon the screen the smaller they are; in some cases, a window may show Xonly a couple of lines of text. To increase the flexibility and utility Xof the window environment, EMACS allows you to resize the window you are Xworking in (called, as you will recall, the @b window) to a Xconvenient size for easier editing, and then shrink it when you no Xlonger need it to be so large. X XLet's try an example. Load in any EMACS text file and split the current Xwindow into two. Now type @b{^X-^(Shift-6)}, X@i{grow-window}@index{grow-window}. Your current window should be Xthe lower one on the screen. Notice that it increases in size upwards Xby one line. If you are in the upper window, it increases in size in a Xdownward direction. The command @b{^X-^Z}, X@i{shrink-window}@index{shrink-window} correspondingly decreases window Xsize by one line at a time. X XEMACS also allows you to resize a window more precisely by entering a Xnumeric argument specifying the size of the window in lines. To resize Xthe window this way, press the META key and enter a numeric argument X(remember to keep it smaller than the number of lines on your screen Xdisplay) then press @b{^X-W} @i{resize-window}@index{resize-window}. XThe current window will be enlarged or shrunk to the number of lines Xspecified in the numeric argument. For example entering: X X@quotation{@b[M-8 ^X-W]}will resize the current window to 8 lines. X X@section(Repositioning within a Window) X XThe cursor may be centered within a window by entering @b{M-! or M-^L} X@i{redraw-display} @index{redraw-display}. This command is especially Xuseful in allowing you to quickly locate the cursor if you are moving Xfrequently from window to window. You can also use this command to move Xthe line containing the cursor to any position within the current Xwindow. This is done by using a numeric argument before the command. XType @b(M- M-^L) where is the number of the line within the Xwindow that you wish the current line to be displayed. X XThe @b{^L} @i{Refresh-screen} @index{refresh-screen} command is useful Xfor 'cleaning up' a 'messy' screen that can result of using EMACS on a Xmainframe system and being interupted by a system message. X@newpage X@u X XIn Chapter @value(chapter) you learned how to manipulate windows and the Xediting flexibility they offer. X X@begin(verbatim) X@u(Key Binding Keystroke Effect) X XOpen-Window @b{^X-2} Splits current window into two windows if X space available X XClose-Windows @b{^X-1} Closes all windows except current window X XNext-Window @b{^X-O}[oh] Moves point into next (i.e. downward) window X XPrevious-Window @b{^XP} Moves point to previous (i.e. upward) window X XMove-Window-Down @b{^X-^N} Scrolls current window down one line X XMove-Window-Up @b{^X-^P} Scrolls current window up one line X XRedraw-display @b{M !} or Window is moved so line with point X @b{M ^L} (with cursor) is at center of window X XGrow-Window @b{M-X ^} or Current window is enlarged by one X @b{M ^L} line and nearest window is shrunk by X one line X XShrink-Window @b{^X-^Z} Current window is shrunk by one line X and nearest window is enlarged by one line X XClear-and-redraw @b{^L} Screen is blanked and redrawn. Keeps X screen updates in sync with your commands X XScroll-Next-Up @b{M-^Z} Scrolls next window up by one line X XScroll-Next-Down @b{M-^V} Scrolls next window down by one line X XDelete-Window @b{^X-0} Deletes current window X XDelete-Other-Windows @b{^X-1} Deletes all but current window X XResize-Window @b{^X-^W} Resizes window to a given numeric argument X@end(verbatim) X@chapter(Buffers) X X@index(buffer) We have already learned a number of things about buffers. XAs you will recall, they are the major internal entities in EMACS -- the Xplace where editing commands are executed. They are characterized by Xtheir @b, their @b, and by the file with which they are Xassociated. Each buffer also "remembers" its @b(mark) and @b(point). XThis convenient feature allows you to go to other buffers and return to Xthe original location in the "current" buffer. X XAdvanced users of EMACS frequently have a number of buffers in the Xcomputer's memory simultaneously. In the last chapter, for example, you Xopened at least two buffers -- one into the text you were editing, and Xthe other into the EMACS on-line tutorial. If you deal with complex Xtext files -- say, sectioned chapters of a book, you may have five or Xsix buffers in the computer's memory. You could select different Xbuffers by simply calling up the file with @b{^X-^F} @i(find-file) X@index(find-file), and let EMACS open or reopen the buffer. However, XEMACS offers fast and sophisticated buffering techniques that you will Xfind easy to master and much more convenient to use. X XLet's begin by opening three buffers. You can open any three you Xchoose, for example call the following files into memory: @b(fang.txt), X@b(publish.txt), and @b(emacs.tut) in the order listed here. When Xyou've finished this process, you'll be looking at a screen showing the XEMACS tutorial. Let's assume that you want to move to the fang.txt Xbuffer. Enter: X X@b{^X-X} @i(next-buffer) @index(next-buffer) X XThis command moves you to the @u buffer. Because EMACS cycles Xthrough the buffer list, which is alphabetized, you will now be in the X@b(fang.txt) buffer. Using @b(^X-X) again places you in the X@b(publish.txt) buffer. @i(If you are on a machine that supports Xfunction keys, using @b[^X-X] again places you in the @b(Function Keys) Xbuffer). Using @b(^X-X) one last time cycles you back to the beginning Xof the list. X XIf you have a large number of buffers to deal with, this cycling process Xmay be slow and inconvenient. The command @b{^X-B} @i(select-buffer) X@index(select-buffer) allows you to specify the buffer you wish to be Xswitched to. When the command is entered, EMACS prompts, "Use buffer:". XSimply enter the buffer name (NOT the file name), and that buffer will Xthen become the current buffer. X XMultiple buffer manipulation and editing is a complex activity, and you Xwill probably find it very inconvenient to re-save each buffer as you Xmodify it. The command @b{^X-^B} @i(list-buffers) @index(list-buffers) Xcreates a new window that gives details about all the buffers currently Xknown to EMACS. Buffers that have been modified are identified by the X"buffer changed" indicator (an asterisk in the second column). You can Xthus quickly and easily identify buffers that need to be saved to files Xbefore you exit EMACS. The buffer window also provides other Xinformation -- buffer specific modes, buffer size, and buffer name are Xalso listed. To close this window, simply type the close-windows Xcommand, @b{^X-1}. X XTo delete any buffer, type @b{^X-K} @i(delete-buffer) X@index(delete-buffer). EMACS prompts you "Kill buffer:". Enter the Xbuffer name you want to delete. As this is destructive command, EMACS Xwill ask for confirmation if the buffer was changed and not saved. XAnswer Y(es) or N(o). As usual @b{^G} cancels the command. X X@newpage X@heading(Chapter @value(chapter) Summary) X XIn Chapter @value(chapter) you learned how to manipulate buffers. X X@begin{verbatim} X@u(Key Binding Keystroke Effect) XNext-Buffer @b(^X-^X) Switch to the next buffer in the X buffer list X XSelect-Buffer @b(^X-B) Switch to a particular buffer X XList-Buffers @b(^X-^B) List all buffers X XDelete-Buffer @b(^X-K) delete a particular buffer if it X is off-screen X@end(verbatim) X@chapter(Modes) X X EMACS allows you to change the way it works in order to Xcustomized it to the style of editing you are using. It does this by Xproviding a number of different @b(modes) @index(modes). These modes Xcan effect either a single buffer, or any new buffer that is created. XTo add a mode to the current buffer, type @b(^X-M) @i(add-mode) X@index(add-mode). EMACS will then prompt you for the name of a mode to Xadd. When you type in a legal mode name, and type a , EMACS will Xadd the mode name to the list of current mode names in the modeline of Xthe current buffer. X X To remove an existing mode, typing the @b(^X-^M) @i(delete-mode) X@index(delete-mode) will cause EMACS to prompt you for the name of a Xmode to delete from the current buffer. This will remove that mode from Xthe mode list on the current modeline. X X Global modes are the modes which are inherited by any new Xbuffers which are created. For example, if you wish to always do string Xsearching with character case being significant, you would want global Xmode EXACT to be set so that any new files read in inherent the EXACT Xmode. Global modes are set with the @b(M-M) @i(add-global-mode) X@index(add-global-mode) command, and unset with the @b(M-^M) X@i(delete-global-mode) @index(delete-global-mode) command. Also, the Xcurrent global modes are displayed in the first line of a X@b(^X-^B) @i(list-buffers) @index(list-buffers) command. X X On machines which are capable of displaying colors, X@index(color) the mode commands can also set the background and Xforeground character colors. Using @i(add-mode) or @i(delete-mode) with Xa lowercase color will set the background color in the current window. XAn uppercase color will set the foreground color in the current window. XColors that EMACS knows about are: white, cyan, magenta, yellow, blue, Xred, green, and black. If the computer you are running on does not have Xeight colors, EMACS will attempt to make some intelligent guess at what Xcolor to use when you ask for one which is not there. X X@section(ASAVE mode)@index(ASAVE mode) X X Automatic Save mode tells EMACS to automatically write out the Xcurrent buffer to its associated file on a regular basis. Normally this Xwill be every 256 characters typed into the file. The environment Xvariable $ACOUNT counts down to the next auto-save, and $ASAVE is the