The Emacs Editor

Emacs can best be described as a working environment featuring an editor, a mailer, a newsreader, and a Lisp interpreter. The editor is tailored for program development, enabling you to format source code according to the programming language you use. Many versions of Emacs are currently available for use on Unix and Linux systems. The versions usually included with Linux distributions are either GNU Emacs or XEmacs. The current version for GNU Emacs is 20.x; it is X Window System-capable, enabling GUI features such as menus, scroll bars, and mouse-based editing operations. (See Chapter 13 for a discussion of the GNU Emacs mailer and its newsreader.) Check the update FTP sites for your distribution for new versions as they come out, and also check the GNU Web site at www.gnu.org and the Emacs Web site at www.emacs.org. You can find out more information about XEmacs at its Web site, www.xemacs.org.

Emacs derives much of its power and flexibility from its capability to manipulate buffers. Emacs can be described as a buffer-oriented editor. Whenever you edit a file in any editor, the file is copied into a work buffer, and editing operations are made on the work buffer. Emacs can manage many work buffers at once, enabling you to edit several files at the same time. You can edit buffers that hold deleted or copied text. You can even create buffers of your own, fill them with text, and later save them to a file. Emacs extends the concept of buffers to cover any task. When you compose mail, you open a mail buffer; when you read news, you open a news buffer. Switching from one task to another is simply a matter of switching to another buffer.

The Emacs editor operates much like a standard word processor. The keys on your keyboard represent input characters. Commands are implemented with special keys, such as control (ctrl) keys and alternate (alt) keys. There is no special input mode, as in Vi or Ed. You type in your text, and if you need to execute an editing command, such as moving the cursor or saving text, you use a ctrl key. Such an organization makes the Emacs editor easy to use. However, Emacs is anything but simple—it is a sophisticated and flexible editor with several hundred commands. Emacs also has special features, such as multiple windows. You can display two windows for text at the same time. You can also open and work on more than one file at a time, displaying each on the screen in its own window. You invoke the Emacs editor with the command emacs. You can enter the name of the file you want to edit, and if the file does not exist, it is created. In the next example, the user prepares to edit the file mydata with Emacs:

$ emacs mydata

The GNU Emacs editor now supports an X Window System graphical user interface. To enable X support, start Emacs within an X Window System environment, such as a KDE, GNOME, or XFce desktop. The basic GUI editing operations are supported: selection of text with click-and-drag mouse operations; cut, copy, and paste; and a scroll bar for moving through text. The Mode line and Echo areas are displayed at the bottom of the window, where you can enter keyboard commands. The scroll bar is located on the left side. To move the scroll bar down, click it with the left mouse button. To move the scroll bar up, click it with the right mouse button.

NOTE XEmacs is the complete Emacs editor with a graphical user interface and Internet applications, including a Web browser, a mail utility, and a newsreader. XEmacs is available on the Fedora repository.