-*-Fonts: HL12,HL12B,HL12BI,TR12B; Mode: Fundamental -*- You are looking at the ZMacs tutorial. Comments on this document should be sent to Dulcey@MIT-OZ. ZMacs is the editor used on the Lisp Machine. It is based on ZWEI, an editing subsystem. Certain other programs on the Lisp Machine, such as ZMail and Converse, also use ZWEI. When you are editing text in these programs, it will be with the same commands documented here. They also have other commands of their own. ZMacs commands generally involve the 1Control* key or the 1Meta* key. Rather than write out 1Meta* or 1Control* each time we want you to prefix a character, we'll use the following abbreviations: 1C-2char** means hold the 1Control* key while typing the character 2char*. Thus, 1C-F* would be: hold the 1Control* key and type 1F*. 1M-2char** means hold the 1Meta* key down while typing 2char*. 1C-M-2char** means hold both the 1Control* key and the 1Meta* key down while typing 2char*. Important note: if you must exit at some point, you can use the 1System* key to take you elsewhere. 1System* 1E* will get you back here. The characters "1>>*" at the left margin indicate directions for you to try using a command. The first thing that you need to know is how to move around from place to place in the file. 1C-V *moves you forward to the next screen of text. 1M-V* takes you back to the previous screen. 1>>* Now type 1C-V* (Next Screen) to move to the next screen. (go ahead, do it by depressing the 1Control* key and 1V* together). Then type 1M-V *to get back here. From now on, you'll be expected to do this whenever you finish reading the screen. Note that there is an overlap when going from screen to screen; this provides some continuity when moving through the file. 2SUMMARY* The following commands are useful for viewing screenfuls: 1C-V* Move forward one screenful 1M-V* Move backward one screenful 1C-L* Clear screen and redisplay everything putting the text near the cursor at the center. 1>>* Find the cursor and remember what text is near it. Then type a 1C-L*. Find the cursor again and see what text is near it now. 2BASIC CURSOR CONTROL* Getting from screenful to screenful is useful, but how do you reposition yourself within a given screen to a specific place? There are several ways you can do this. One way (not the best, but the most basic) is to use the commands previous, backward, forward and next. As you can imagine these commands (which are given to ZMacs as 1C-P*, 1C-B*, 1C-F*, and 1C-N* respectively) move the cursor from where it currently is to a new place in the given direction. Here, in a more graphical form are the commands: Previous line, 1C-P* : : Backward, 1C-B* .... Current cursor position .... Forward, 1C-F* : : Next line, 1C-N* You'll probably find it easy to think of these by letter. 1P* for previous, 1N* for next, 1B* for backward and 1F* for forward. These are the basic cursor positioning commands and you'll be using them ALL the time so it would be of great benefit if you learn them now. 1>>* Do a few 1C-N*'s to bring the cursor down to this line. 1>>* Move into the line with 1C-F*'s and then up with 1C-P*'s. See what 1C-P* does when the cursor is in the middle of the line. Lines are separated by a 1Return* character. 1>>* Try to 1C-B* at the beginning of a line. Do a few more 1C-B*'s. Then do 1C-F*'s back to the end of the line and beyond. When you go off the top or bottom of the screen, the text beyond the edge is shifted onto the screen so that your instructions can be carried out while keeping the cursor on the screen. 1>>* Try to move the cursor off the bottom of the screen with 1C-N* and see what happens. If moving by characters is too slow, you can move by words. 1M-F* moves forward a word and 1M-B* moves back a word. 4>>* Type a few 1M-F*'s and 1M-B*'s. Intersperse them with 1C-F*'s and 1C-B*'s. Notice the parallel between 1C-F* and 1C-B* on the one hand, and 1M-F* and 1M-B* on the other hand. Very often 1Meta* characters are used for operations related to English text whereas 1Control* characters operate on the basic textual units that are independent of what you are editing (characters, lines, etc). There is a similar parallel between lines and sentences: 1C-A* and 1C-E* move to the beginning or end of a line, and 1M-A* and 1M-E* move to the beginning or end of a sentence. 1>>* Try a couple of 1C-A*'s, and then a couple of 1C-E*'s. Try a couple of 1M-A*'s, and then a couple of 1M-E*'s. See how repeated 1C-A*'s do nothing, but repeated 1M-A*'s keep moving farther. Do you think that this is right? Two other simple cursor motion commands are 1M-<*, which moves to the beginning of the file, and 1M->*, which moves to the end of the file. You probably don't need to try them, since finding this spot again will be boring. The location of the cursor in the text is also called "point". To paraphrase, the cursor shows on the screen where point is located in the text. Here is a summary of simple moving operations including the word and sentence moving commands: 1C-F* Move forward a character 1C-B* Move backward a character 1M-F* Move forward a word 1M-B* Move backward a word 1C-N* Move to next line 1C-P* Move to previous line 1C-A* Move to beginning of line 1C-E* Move to end of line 1M-A* Move back to beginning of sentence 1M-E* Move forward to end of sentence 1M-<* Go to beginning of file 1M->* Go to end of file 1>>* Try all of these commands now a few times for practice. Since the last two will take you away from this screen, you can come back here with 1M-V*'s and 1C-V*'s. These are the most often used commands. Like all other commands in ZMacs, these commands can be given arguments which cause them to be executed repeatedly. The way you give a command a repeat count is by holding down the 1Control* key, the 1Meta* key, or both, while typing digits; then type the command. For instance, 1C-8* 1C-F* moves forward eight characters. 1>>* Try giving a suitable argument to 1C-N* or 1C-P* to come as close as you can to this line in one jump. Two exceptions to this is the screen moving commands, 1C-V* and 1M-V*. When given an argument, they scroll the screen up or down by that many lines, rather than screenfuls. 1>>* Try typing 1C-8* 1C-V* now. Did it scroll the screen up by 8 lines? If you would like to scroll it down you can give an argument to 1M-V*. Another exception is the redisplay comand 1C-L*. When given an argument, it causes the line where the cursor is located to be displayed that many lines from the top of the screen. 1>>* Try typing 1C-0 C-L*. This line should move to the top of the screen. 2WHEN ZMacs IS HUNG* If ZMacs gets into an infinite (or simply very long) computation which you don't want to finish, you can stop it safely by typing 1C-Abort*. You can also use 1C-Abort* to discard a numeric argument or the beginning of a command that you don't want to finish. 3 1>>** Type 1C-100* to make a numeric arg of 100, then type 1C-Abort*. Now type 1C-F*. How many characters does it move? 2INSERTING AND DELETING* If you want to type text, just do it. Characters which you can see, such as 1A*, 17*, 1**, etc. are taken by ZMacs as text and inserted immediately. Type 1Return* to insert a line separator. You can delete the last character you typed by typing 1Rubout*. 1Rubout* is a key on the keyboard.1 *More generally, 1Rubout* deletes the character immediately before the current cursor position. (The Delete key doesn't delete anything. In fact, it doesn't do anything at all!) 1>>* Do this now, type a few characters and then delete them by typing 1Rubout* a few times. Don't worry about this file being changed; you won't affect the master tutorial. This is just a copy of it. 1>>* Now start typing text until you reach the right margin, and keep typing. When a line of text gets too big for one line on the screen, the line of text is "continued" onto a second screen line. The exclamation mark at the right margin indicates a line which has been continued. 1>>* Use 1Rubout*s to delete the text until the line fits on one screen line again. The continuation line goes away. 1>>* Move the cursor to the beginning of a line and type 1Rubout*. This deletes the line separator before the line and merges the line onto the previous line. The resulting line may be too long to fit, in which case it has a continuation line. 1>>* Type 1Return* to insert the separator again. Remember that most ZMacs commands can be given a repeat count; Note that this includes characters which insert themselves. 1>>* Try that now -- type 1C-8* 1** and see what happens. You've now learned the most basic way of typing something in ZMacs and correcting errors. You can delete by words or lines as well. Here is a summary of the delete operations: 1Rubout* delete the character just before the cursor 1C-D* delete the next character after the cursor 1M-Rubout* kill the word immediately before the cursor 1M-D* kill the next word after the cursor 1C-K* kill from the cursor position to end of line 1M-K* kill to the end of the current sentence Notice that 1Rubout* and 1C-D* vs 1M-Rubout* and 1M-D* extend the parallel started by 1C-F* and 1M-F* (well, 1Rubout* isn't 2really* a control character, but let's not worry about that). 1C-K* and 1M-K* are like 1C-E* and 1M-E*, sort of, in that lines are opposite sentences. Now suppose you kill something, and then you decide that you want to get it back? Well, whenever you kill something bigger than a character, ZMacs saves it for you. To yank it back, use 1C-Y*. Note that you don't have to be in the same place to do 1C-Y*; This is a good way to move text around. Also note that the difference between 2Killing* and 2Deleting* something is that 2Killed* things can be yanked back, and 2Deleted* things cannot. Generally, the commands that can destroy a lot of text save it, while the ones that attack only one character, or nothing but blank lines and spaces, do not save. For instance, type 1C-N* a couple times to postion the cursor at some line on this screen. 1>>* Do this now, move the cursor and kill that line with 1C-K*. Note that a single 1C-K* kills the contents of the line, and a second 1C-K* kills the line itself, and make all the other lines move up. If you give 1C-K* a repeat count, it kills that many lines AND their contents. The text that has just disappeared is saved so that you can retrieve it. To retrieve the last killed text and put it where the cursor currently is, type 1C-Y*. 1>>* Try it; type 1C-Y* to yank the text back. Think of 1C-Y* as if you were yanking something back that someone took away from you. Notice that if you do several 1C-K*'s in a row the text that is killed is all saved together so that one C1-Y *will yank all of the lines. 1>>* Do this now, type 1C-K* several times. Now to retrieve that killed text: 1>>* Type 1C-Y*. Then move the cursor down a few lines and type 1C-Y* again. You now see how to copy some text. What do you do if you have some text you want to yank back, and then you kill something else? 1C-Y* would yank the more recent kill. But the previous text is not lost. You can get back to it using the 1M-Y* command. After you have done 1C-Y* to get the most recent kill, typing 1M-Y* replaces that yanked text with the previous kill. Typing 1M-Y* again and again brings in earlier and earlier kills. When you have reached the text you are looking for, you can just go away and leave it there. If you 1M-Y* enough times, you come back to the starting point (the most recent kill). 3***** Mention that the last eight kills are saved (rather than being so* 3vague about it).* 1>>* Kill a line, move around, kill another line. Then do 1C-Y* to get back the second killed line. Then do 1M-Y* and it will be replaced by the first killed line. Do more 1M-Y*'s and see what you get. Keep doing them until the second kill line comes back, and then a few more. If you like, you can try giving 1M-Y* positive and negative arguments. 2THE MOUSE* The 2Mouse *(the little white box with three buttons on top which is connected to your keyboard by a cable) can be used to perform various functions in ZMacs. The 2Mouse Cursor* tells you where the mouse is currently pointing. It is an arrow which points North-North-East while ZMacs is running. If you move the mouse, the pointer moves around the screen. Also, if you point the mouse at a character (rather than at empty screen), the character is 2highlighted* by surrounding it with a box. 1>>* Roll the mouse around. Watch the mouse cursor move around the screen, and how characters are highlighted when you point at them. You can move the position of the cursor by clicking the left mouse button once. The cursor moves to wherever the mouse cursor is. Clicking the left button twice rapidly performs the inverse operation; the mouse cursor moves to meet the cursor. 1>>* Try moving around the cursor and the mouse cursor with mouse clicks. The mouse can also be used to 2scroll* the text in your buffer (the same thing that comands like 1C-V* do). If you move the mouse to the upper right corner of the screen, you will notice that the mouse cursor changes to a fat arrow. Rolling the mouse toward the top of the screen here will let you see more text at the top of the screen. Similarly, moving the mouse to the lower right corner will let you see more text at the bottom. 1>>* Move the text around a bit with the mouse now. Moving the mouse to the left side of the screen allows various other sorts of scrolling. The mouse cursor will change to a fat double-ended arrow to indicate this. Clicking the left button will move the line pointed at to the top of the screen. Clicking the right button will move the line which is at the top of the screen to the location where the mouse cursor is. Note that a left click will undo the effect of a right click, and vice versa, if you do not move the mouse (and you did not reach the beginning or the end of the buffer). 1>>* Move up and down the screen with left-side clicks. 2FILES* In order to make the text you edit permanent, you must put it in a file. Otherwise, it will go away when your invocation of ZMacs goes away. You put your editing in a file by 2finding* the file. What finding means is that you see the contents of the file in your ZMacs; and, loosely speaking, what you are editing is the file itself. However, the changes still don't become permanent until you 2save* the file. This is so you can have control to avoid leaving a half-changed file around when you don't want to. If you are using a host which supports version numbers for files (such as ITS, TOPS-20, or VAX-VMS), saving will create a new version of your file; the original will still be intact until you delete it. If you look near the botton of the screen you will see a line that starts with "ZMACS (Fundamental) PS:TEACH-ZMACS.TEXT OZ:" (if you are logged in to OZ. The form of the name may be different if you are logged in to a different host.) This is the name of your own copy of the text of the ZMacs tutorial; the file you are now looking at. Whatever file you find, that file's name will appear in that precise spot. The commands for finding and saving files are unlike the other commands you have learned in that they consist of two characters. They both start with the character 1Control-X*. There is a whole series of commands that start with 1Control-X*; many of them have to do with files, buffers, and related things, and all of them consist of 1Control-X* followed by some other character. Another thing about the command for finding a file is that you have to say what file name you want. We say the command "reads an argument from the terminal" (in this case, the argument is the name of the file). After you type the command 1C-X* 1C-F* Find File ZMacs will ask you for the file name. You should end the name with the Return key. This command will read the file into its own new buffer. (If you use Find File on a file which is already in your ZMacs, you will simply be switched to that buffer; the file is not read in again.) After this command, you will see the contents of the file in your ZMacs. You can edit the contents. When you wish to make the changes permanent, issue the command 1C-X C-S* Save File The file will be saved. If the host file system supports version numbers, a new version of the file will be created. When the operation is finished, ZMacs prints the name and version saved. You should save fairly often, so that you will not lose very much work if your Lisp Machine should crash. (If the host computer crashes, you can simply wait for it to work again, then retry the save.) 1C-X C-W* Write File This causes the buffer to be written out to a file, like Save File does. The difference is that you will be asked for a name to write it under. This lets you put your new text in a different place from the original. (This is especially useful if your host does not support version numbers!) The buffer will also be renamed to the new file name, so any subsequent Save File commands will also output to the new file. To make a new file, just find it "as if" it already existed. Then start typing in the text. When you ask to save the file, ZMacs will really create the file with the text that you have inserted. From then on, you can consider yourself to be editing an already existing file. 1>>* Try finding a new file now. (The name will depend on which host you are logged into.) Put some text into it, and save it. When you are done, you can come back here with 1C-M-L*. (More generally, 1C-M-L* returns you to the buffer you were editing most recently before the current one.) 2EXTENDING THE COMMAND SET* There are many, many more ZMacs commands than could possibly be put on all the control and meta characters. ZMacs gets around this with the 1X* (2eXtend*) command. This comes in two flavors: 1C-X* Character 2eXtend*. Followed by one character. 1M-X* Named command 2eXtend*. Followed by a long name. These are commands that are generally useful but used less than the commands you have already learned about. You have already seen two of them: the file commands 1C-X* 1C-F* to Find and 1C-X* 1C-S* to Save. There are many 1C-X* commands. The ones you need immediately are: 1C-X* 1C-F* Find file. 1C-X* 1C-S* Save file. 1C-X C-W* Write file. Named extended commands are commands which are used even less frequently, or commands which are used only in certain modes. These commands are usually called 2functions*. An example is the function 1Replace String*, which globally replaces one string with another. When you type 1M-X*, ZMacs prompts you at the bottom of the screen with 1M-X* and you should type the name of the function you wish to call; in this case, 1Replace String*. Just type "1REPL*" and ZMacs will complete the name. You will be prompted for the string to replace; type it followed by 1Return*. Then you will be prompted for the new string; type it followed by 1Return*. 1>>* Move the cursor to the blank line two lines below this one. Then type 1M-X* 1replchangedaltered*. Notice how this line has changed: you've replaced the word 1changed* with 1altered* wherever it occurs after the cursor. 2MODE LINE* If ZMacs sees that you are typing commands slowly it shows them to you at the bottom of the screen in an area called the echo area. The echo area contains the bottom three lines of the screen. The line immediately above them is called the 2mode line*. The mode line says something like ZMACS (Text) Filename (ver) * It may contain additional information under some circumstances. For example, the mode line you see while editing this file displays the current 2font*. The mode line is a very useful information line. You already know what the filename means -- it is the file you have found.1 *The star means that you have made changes to the text. Right after you find or save a file, there is no star. The part of the mode line inside the parentheses is to tell you what modes you are in. (The default mode is Lisp. However, a file may specify which mode it likes in an Attributes List. This appears as the first line of the file. This file specifies Fundamental mode.) It is an example of a 2major mode*. There are several major modes in ZMacs for editing different languages and text, such as LISP mode, Text mode, etc. At any time one and only one major mode is active, and its name can always be found in the mode line just where "Fundamental" is now. Each major mode makes a few commands behave differently. For example, there are commands for creating comments in a program, and since each programming language has a different idea of what a comment should look like, each major mode has to insert comments differently. Each major mode is the name of an extended command, which is how you get into the mode. For example, 1M-X Lisp* 1Mode* is how to get into Lisp mode. If you are going to edit English language text, you should use Text mode. 1>>* Type 1M-X Text Mode* to get to Text mode. Notice how the mode line changes. Don't worry, none of the commands you have learned changes ZMacs in any great way. Major modes are usually like that: commands don't change into completely unrelated things, but they work a little bit differently. Major modes are called major because there are also 2minor modes*. They are called minor because they aren't alternatives to the major modes, just minor modifications of them. Each minor mode can be turned on or off by itself, regardless of what major mode you are in, and regardless of the other minor modes. So you can use no minor modes, or one minor mode, or any combination of several minor modes. One minor mode which is very useful, especially for editing English text, is Auto Fill mode. When this mode is on, ZMacs breaks the line in between words automatically whenever the line gets too long. You can turn this mode on by doing 1M-X Auto Fill Mode*. When the mode is on, you can turn it off by doing 1M-X Auto Fill Mode*. If the mode is off, this function turns it on, and if the mode is on, this function turns it off. This is called 2toggling*. 1>>* Type 1M-X Auto Fill Mode* now. Then insert a line of "asdf " over again until you see it divide into two lines. You must put in spaces between them because Auto Fill breaks lines only at spaces. Notice that "Fill" appears in the mode line in addition to the name of the major mode, not instead of it. The margin is usually set at 576 pixels (dots on the screen), but you can change it with the 1C-X* 1F* command. You move the cursor where you want the fill column to be, then type 1C-X* 1F*. You can also give 1C-X* a numeric argument. If it less than 200., it specifies the fill column in characters. An argument >= 200. specifies a fill column in pixels. 1>>* Move the cursor to column 20 (or thereabouts) and type 1C-X F*. Then type some lines and watch ZMacs fill them. 1>>* Set the fill column back to its original value by typing 1C-X F* with an argument of 1576*. 2SEARCHING* ZMacs can do 2searches* for strings (these are groups of contiguous characters or words) either forward through the file or backward through it. To search for the string means that you are trying to locate it somewhere in the file and have ZMacs show you where the occurrences of the string exist. This type of search is somewhat different from what you may be familiar with. It is a search that is performed as you type in the thing to search for. The command to initiate a search is 1C-S* for forward search, and 1C-R* for reverse search. BUT WAIT! Don't do them now. When you type 1C-S* you'll notice that the string "I-search" appears as a prompt in the echo area. This tells you that ZMacs is in what is called an 2incremental search* waiting for you to type the thing that you want to search for. 1Altmode* terminates a search. 1>>* Now type 1C-S* to start a search. 2Slowly*, one letter at a time, type the word 1cursor*, pausing after you type each character to notice what happens to the cursor. 1>>* Type 1C-S* to find the next occurrence of 1cursor*. 1>>* Now type 1Rubout* four times and see how the cursor moves. 1>>* Type 1Altmode* to terminate the search. Did you see what happened? ZMacs, in an incremental search, tries to go to the occurrence of the string that you've typed out so far. To go to the next occurrence of 'cursor' just type 1C-S* again. If no such occurrence exists ZMacs beeps and tells you that it is a failing search. If you are in the middle of an incremental search and type 1Rubout*, you'll notice that the last character in the search string is erased and the search backs up to the last place of the search. For instance, suppose you currently have typed 1cu* and you see that your cursor is at the first occurrence of 1cu*. If you now type 1Rubout*, the 1u* on the search line is erased and you'll be repositioned in the text to the occurrence of 1c* where the search took you before you typed the 1u*. This provides a useful means for backing up while you are searching. If you are in the middle of a search and happen to type a control character (other than a 1C-S* or 1C-R*, which tell ZMacs to search for the next occurrence of the string, or a 1C-Q*, which can be used to input certain 1Top* and 1Greek* characters for compatibility with certain other systems), the search is terminated, and the character is executed. 1Abort* will simply end the search, like 1Altmode*. The 1C-S* starts a search that looks for any occurrence of the search string 2after* the current cursor position. But what if you want to search for something earlier in the text? To do this, type 1C-R* for Reverse search. Everything that applies to 1C-S* applies to 1C-R* except that the direction of the search is reversed. 2GETTING MORE HELP* In this tutorial we have tried to supply just enough information to get you started using ZMacs. There is so much available in ZMacs that it would be impossible to explain it all here. However, you may want to learn more about ZMacs since it has numerous desirable features that you don't know about yet. ZMacs has a great deal of internal documentation. All of these commands can be accessed through the 1Help* character. To use the 2Help* features, type 1Help*, and then a character saying what kind of help you want. If you are 2really* lost, type 1Help* 1Help* and ZMacs will tell you what kinds of help it can give. If you have typed the 1Help* character and decide you don't want any help, just type 1Abort* to abort. The most basic Help feature is 1Help* C. Type 1Help*, a 1C*, and a command character, and ZMacs prints a description of the command. When you are finished reading it, type a 1Space* or an= 1Abort** to bring your text back on the screen. >> Type 1Help* 1C* 1Control-P*. When you are finished reading the output, type a 1Space*. The message should be something like 1 * Control-P is Up Real Line, implemented by COM-UP-REAL-LINE: Move up vertically to previous real line. Moves as far as possible horizontally toward the goal column for successive commands. The "name of the function" is important for people who are customizing ZMacs. It is what appears in the ZMacs Chart as the documentation for the command character. For now you can ignore it. Multi-character commands such as 1C-X* 1C-F* are also allowed after 1Help* 1C*. Here are some other useful 1Help* options: 1Help* 1D* Describe a function. You type in the name of the function. To see your text again when it is done, type a 1Space* or 1Abort*. 1>>* Try typing 1Help* 1D Replace String*. Then type a1 Space* when you are finished reading it. 1Help* 1A* Apropos. Type in a keyword and ZMacs will list all the functions containing that keyword. For some functions it will also list a one or two character command which has the same effect. 1>>* Type 1Help* 1A File*. You will see a list of all functions (1M-X* commands) with "file" in their names. You will also see commands like 1C-X* 1C-F* and 1C-X* 1C-S*, listed under the corresponding function names. When it says "**MORE**" at the bottom of the screen, type a 1Space* to see the rest of the list, or 1Abort* to abort the rest of the listing. 2CONCLUSION* Remember, to exit, use the 1System* key. (1System* 1Help* will tell you what system commands are accepted.) Make sure to save any files you need saved before exiting. Unfortunately, there is no ZMacs manual yet. You may, however, find an EMACS manual to be useful. Most of the commands documented there also work in ZMacs. This tutorial is meant to be understandable to all new users, so if you found something unclear, don't sit and blame yourself - complain!