Editing with Emacs



next up previous contents index
Next: Emacs Command Summary Up: GETTING FRIENDLY WITH Previous: vi Command Summary

Editing with Emacs

The editor GNU Emacs is ``free'' and we recommend it, especially for use with a mouse. If your system does not have Emacs, ask your system administrator to get it from someone or from ``the network,'' that is, by anonymous ftp to `prep.ai.mit.edu' (see Computer-Computer Interactions). Or you can support a good cause and ``order the latest version of GNU Emacs and other GNU software on tape from the Free Software Foundation. The Foundation can supply industry standard 1/2 inch tapes, Exabyte tapes, and 1/4 inch cartridge tapes in several popular formats. The fee is around $200 per tape, varying slightly according to media type. For full information, phone the Foundation at (617) 876-3296.'' Note that the software itself is free, yet the fee is needed to support the distribution service and the development of more free software like GNU Emacs. Thus it is ``free'' in the distribution sense, that is, sometimes ``users pay money for copies of GNU software, and sometimes they get copies at no charge. But regardless of how they got the software, they have the freedom to copy and change it.''  

In GNU's own words, it is ``the GNU incarnation of the advanced, self documenting, customizable, extensible real-time display editor Emacs. (The ``G'' in ``GNU'' is not silent.)'' Emacs is a display editor since it shows you what the file looks like (even as you are changing it). It is real time in that the display is updated as you enter commands-as well as your file if you have invoked auto-save. It is advanced since it contains features similar to those of word processors and PCs-which makes it particularly useful for manipulating computer and human languages. It is self-documenting since it contains a built-in help facility (just enter [Ctrl]-h = ^ h) as well as a free manual. And finally, it is customizable and extensible in being able to modify and create commands to your liking. To help you get started, a sample .emacs file is given in Appendix 6.

If your system has the Emacs editor, it probably also has the GNU Emacs Manual as part of the package. This is good because you can read more than the terse summary we give here to understand Emacs' general philosophy or to use some of its more advanced features. In addition, an excellent learning tool is the tutorial bundled as part of Emacs. To have it process you, even before you know what you are doing, give the commands:

% emacs Get the editor going.
^ h t Help, tutorial.

To edit filename or create it if it does not exist:

% emacs filename

In contrast to vi, Emacs is normally in the insert mode and is insensitive to the case of the commands. You can start entering or deleting text wherever the pointer is, and you can move the pointer with the arrow keys or the mouse. To change to command mode, you use the control key (sometimes labeled CNTRL, Ctrl, cntrl, or CTL) or the meta key (sometimes labeled Alt or EDIT).

If there is no Meta, Alt, or Edit key, type [esc], release the escape key, and then type the character. Here, the escape key may be mapped to ` (accent grave) or something else on your system. (The Emacs manual and help commands use the notation c-x and m-x.)

Hints: Remember to practice with a scratch file and use the undo command ^ x u to fix errors. If you have really messed up the file in the Emacs buffer, do NOT save it (^ x^ s) as this replaces the original; instead, save it to a scratch file (^ x ^ w temp) or not at all. If Emacs seems ``messed up'' to you and you cannot get it back on track, try ^ g to make it return to a normal state. If that does not fix it, you can quit Emacs with ^ x ^ c-but answer carefully the questions Emacs asks you if you do not want the disk file replaced (and remember to use ^ h for help). 

Part of the attraction of Emacs is that you can view and edit several files simultaneously-or even different parts of the same file-and cut and paste among them. While this is not hard to do, we have found the Emacs terminology confusing at times, in part since it differs from the vi editor. For one thing, the display you see on the screen has at least three windows. The big window on top is where the text of your file is normally found, while the small windows below are the mode line and echo line. You can divide that big window into many smaller windows and then use them independently, activating a particular window by placing your cursor in it (or clicking your mouse).    

Confusion arises from the fortunate fact that you do not really edit a file, but rather are editing a copy of the file in the computer's memory. The region of memory where Emacs stores the copy of your file is called a buffer, and every time you ask Emacs to find another file it copies it from the disk to another buffer (unless an unmodified copy of your disk file is already in one of its buffers). Accordingly, there may well be more files in the Emacs buffers than you are viewing in your window(s). Opening and closing the windows which look at these buffers has no effect on the buffers (although killing that buffer does), and likewise the modifications you make to the file in the buffer (to the buffer) have no effect on your disk file until you tell Emacs to save the buffer copy as a disk copy. This is the point where you should be very careful and don't do this if you are too tired or rushed.





next up previous contents index
Next: Emacs Command Summary Up: GETTING FRIENDLY WITH Previous: vi Command Summary