Emacs



         


For the Apple Macintosh computer model, see eMac.

Emacs is a text editor with a comprehensive set of features that is particularly popular with programmers and other technical computer users. The original Emacs was written in 1976 by Richard Stallman, as a set of Editor MACroS for the TECO editor. It has evolved from its dumb terminal origins into something resembling a full blown word processor sporting a complete graphical user interface. A large number of extensions are available which can turn Emacs into anything from a web browser to a tool for writing and compiling computer programs.

Many Emacs clones have appeared over the years, but most have faded into obscurity. The definitive version of Emacs today is GNU Emacs which is also written by Richard Stallman, starting in 1984. The most popular alternative is XEmacs, which forked from GNU Emacs in 1991, and has synced with GNU Emacs regularly since.

The lower-case word emacs (plural emacsen) is sometimes used to mean the class of editors with behavior similar to the original Emacs. The capitalized word Emacs is often used synonymously with GNU Emacs.

Emacs is typically on one side of the editor wars (the other being vi).

[Top]

Emacs history

Emacs began at the Artificial Intelligence Laboratory at MIT. Prior to its introduction, TECO was the default editor in ITS, the operating system on the AI Lab's PDP-6 and PDP-10 computers.

Unlike modern text editors, the TECO line editor separated typing, editing, and document display. Typing characters into TECO did not place those characters directly into a document. Instead, modifying a document involved writing a series of instructions in the TECO command language, during which time the edits these commands made were not shown in context -- altered text was not shown imbedded within the unchanged portion of the document. Displaying the edited version of the document required a command be typed. This behavior is similar to the program ed, which is still in use.

Carl Mikkelsen, one of the hackers at the MIT AI Lab, added a display-editing mode to TECO, which allowed the screen display to be updated each time the user entered a keystroke. This more-intuitive behavior, which is used by most modern text editors, had been pioneered by the "E" editor written at the Stanford AI Lab. In 1974, Richard Stallman, another hacker, added a macro feature to the TECO display-editing mode. This allowed the user to define keystrokes which would perform multiple TECO commands.

The users at the AI Lab soon accumulated a large collection of custom macros. In 1976, Guy Steele began an effort to unify the many divergent macro sets. The project was completed by Stallman, who also wrote facilities for extension and self-documentation. The resulting program was called EMACS (all caps). Though built on TECO, its behavior was different enough to be considered a text editor in its own right.

"EMACS" stood for "Editor MACroS". According to Stallman, he picked the name Emacs "because < E > was not in use as an abbreviation on ITS at the time." It has also been pointed out that "Emack & Bolio's" was the name of a popular ice cream store in Boston, within walking distance of MIT. The text-formatting program used on ITS was called BOLIO.

EMACS soon became the standard editor on ITS. It was also ported from ITS to the Tenex and TOPS-20 operating systems by Stallman and Michael McMahon.

Several Emacs-like editors were written in the following years, including EINE (EINE Is Not EMACS) and ZWEI (ZWEI Was EINE Initially) by Michael McMahon and Daniel Weinreb. In 1978, Bernard Greenberg wrote Multics Emacs at Honeywell's Cambridge Information Systems Lab. This editor was written in MacLisp, a dialect of the Lisp programming language. User-supplied extensions were also written in Lisp. The choice of Lisp provided more extensibility than ever before, and has been followed by most subsequent emacsen. Later emacsen include Hemlock, Deuce, and Fred.

Gosling Emacs, the first Emacs-like editor to run on Unix, was written by James Gosling in 1981. It was written in C and used a stripped-down version of Lisp, known as Mocklisp, as an extension language.

In 1984, Stallman began writing a new emacs implementation, GNU Emacs, which became the first program in the nascent GNU project. GNU Emacs was written in C and used Emacs Lisp for extension. The first widely distributed version of GNU Emacs was 15.34, which appeared in 1985. Like Gosling Emacs, GNU Emacs ran on Unix; however, GNU Emacs had more features, in particular a full-featured Lisp as extension language. As a result, it soon replaced Gosling Emacs as the de facto Emacs editor on Unix.

Beginning in 1991, Lucid Emacs was developed by Jamie Zawinski and others at Lucid Inc., based on an early alpha version of GNU Emacs 19. The codebases soon diverged, and the separate development teams gave up trying to merge them back into a single program. This was one of the most famous early forks of a free software program. Lucid Emacs has since been renamed XEmacs; it and GNU Emacs remain the two most popular varieties in use today.

Emacs versions used to have a "1" in front of them (1.21.3.1), but the changes made to Emacs were all considered so minor that the number would never change. Therefore, the "1" was dropped, and the version numbers made slightly simpler (21.3.1).

[Top]

Description of GNU Emacs

The GNU Emacs manual describes it as "the extensible, customizable, self-documenting, real-time display editor."

[Top]

User interface

Emacs provides graphical menus for the most common commands, assuming the system supports a graphical interface. The graphical interface of GNU Emacs can use either plain X toolkit, Lesstif, Carbon, or Gtk+ to provide menubars, context menus, and a point and click interaction. Many of the key bindings for the more commonly used commands are listed in the graphical menu so that new users can learn the shortcuts as they explore Emacs.

[Top]

The essentials

Emacs is self documenting. It contains its own help system and a tutorial on its use. When Emacs is started with no file to edit, instructions for invoking the tutorial are presented.

The essential Emacs commands are those which prevent loss of the current editing session, that keep the user from losing his work. These 'First Aid' commands may be invoked from a graphical menu, when there is a graphical interface, or using the keypresses shown here. According to Emacs conventions, C-x C-c means "hold down the control key while pressing x, then hold down control while pressing c".

CommandKeystrokeDescription
Save and Exit
C-x C-c
Stops emacs after asking whether to save changes. Used when all else fails.
Undo
C-/
Undo last change, and prior changes if pressed repeatedly.
Abort
C-g
Stop the running command. Used when emacs is 'frozen', asking questions you don't want to answer, or is otherwise busy doing things you don't want done.
[Top]

Commands

Regardless of whether a graphical interface is available, the user may issue editing commands by entering keystrokes. This method is often preferred for its speed. The commands needed for basic editing are bound to the expected keys: the arrow keys move the editing point, the backspace key deletes text, and so forth. More arcane commands have correspondingly cryptic keystrokes which invoke them. (Technically, nearly every keystroke invokes an Emacs Lisp command, even seemingly-simple keystrokes such as typing a, which invokes a command that inserts the character a into the text at the editing point.)

In addition to the usual commands for inserting and deleting text, Emacs provides a host of more powerful and exotic commands, such as moving the editing point to the next sentence, opening all files in a directory, and swapping the order of two adjacent characters. Some commands, like search and replace, interact with the user as they run. When this happens Emacs prompts the user with text displayed on the last line of the screen (for a graphical interface, the last line of the window). This area is called the minibuffer. To run commands not bound to control or alt key combinations the user activates the minibuffer by holding down alt and pressing x, written M-x, and then enters the name of the desired command into the minibuffer. The minibuffer has tab completion and command history. Some of the more powerful Emacs commands, like spell checking and program compilation, invoke external programs not part of Emacs.

[Top]

File management and display

Emacs keeps text in objects called buffers. The user can create new buffers and dismiss unwanted ones, and several buffers can exist at the same time. Most buffers contain text loaded from text files, to be edited by the user. Emacs autosaves the edited text in these buffers, without overwriting the original file, to support restoration of editing sessions after unexpected termination. When Emacs overwrites an existing file, as happens when the user saves a buffer's content, a backup copy of the original is made and named by appending a tilde (~) to the orignal file name. Buffers also serve other purposes; for example, help text displays in its own buffer.

The last line of a buffer, normally the line just above the minibuffer, indicates the aspects of the buffer's state, such as whether or not the text in the buffer has been saved, the name of the buffer, and the line number at the editing point. This line is called the mode line, since it also displays the modes which are active for the buffer (see below).

Each Emacs screen (which is a single window on a windowing system, or the entire screen on a text terminal) can display one or more buffers at a time. If more than one buffer is displayed, the display area is split into multiple sections, which Emacs refers to as frames.

[Top]

Editing different types of files

Emacs includes many major modes to help with the editing of different types of text and non-text files such as are source code in various programming and markup languages. A major mode often enables syntax highlighting based on the language's syntax and typographical conventions. For example, the major mode for editing C programs knows that comments in C begin with /* and end with */. This allows it to display comments in a different color than the executable parts of the program. It knows what the language's reserved words are, enabling it to display those in another color. It knows about the language's block structure, which allows it to automatically indent a line, based on how deeply nested the line is.

Within a major mode, there may be several minor modes that further customize Emacs' behaviour with respect to that major mode. For example, the major mode for C programs has a minor mode for each of the popular indent styles used in C. The Font Lock minor mode controls the degree of syntax highlighting and is available in the C major mode and many others. When in the C major mode the user can choose between several indentation and syntax highlighting conventions.

Different Emacs buffers may be in different modes. The mode of a buffer is displayed on the buffer's mode line. Some minor modes, like Font Lock, can also be set globally.

[Top]

Internationalization and accessibility to the disabled

Emacs supports the editing of text written in many human languages. There is support for many alphabets, scripts, writing systems, and cultural conventions. Spell checking is generally available, using external programs such as ispell. Many encoding systems, including UTF-8, are supported. A version with full Unicode support is currently being developed.

The Emacs user interface is in English. It has not been translated into other languages.

For visually impaired and blind users there is a subsystem called Emacspeak which may be loaded. It allows the editor to be used through audio feedback only.

[Top]

Beyond editing

Emacs includes many standard extensions, such as Emerge, a tool for comparing files and combining them; calender mode, for keeping appointment calendars and diaries; Gnus, a tool for e-mail and Usenet discussions; Emacs/W3, a web browser; ERC, a tool for IRC; an implementation of the game Tetris; and Doctor, an implementation of ELIZA that performs basic Rogerian psychotherapy. In addition, Emacs can serve as an IDE, allowing programmers to edit, compile, and debug their code from within a single interface. This wide range of capabilities has led to several jokes of the form: "Emacs is a wonderful operating system; it just needs a better text editor."

[Top]

Customization

Emacs is an extemely customizable editor, which can customized and extended in a variety of ways. In approximate ascending order of complexity and power, these include:

The built in customize extension lets users set common customization variables either using a graphical interface or after manually invoking the customize command. These variables store settings such as colour schemes.

Emacs' keyboard macro facility records and plays back sequences of keystrokes, including keystrokes which invoke commands. Macros let the user quickly build complex commands on an ad-hoc basis. They are especially powerful in combination with automatic command repetition.

The user can extend Emacs and customize Emacs' Lisp code from within Emacs itself. Emacs provides extensive facilities to support this, including commands for looking up the documentation of loaded functions and variables. By re-evaluating user-supplied Lisp code, the behavior of Emacs can be modified "on the fly", without having to recompile or even restart the editor. Indeed, this is what happens when Emacs runs Lisp code upon startup. Lisp is a good choice of language for this purpose because it allows functions to be treated as data, so Lisp programs easily manipulate their own functions. These properties of the Emacs Lisp development environment make it relatively simple to develop code that extends Emacs' functionality.

An example of an Emacs extension is the BambooWeb major mode, which helps with the editing of BambooWeb articles. Because it is not built into Emacs, it must be loaded when Emacs is started up.

Some of the source code of Emacs is written in the C programming language. The C code implements only the most low-level functionality, such as the display engine and the Emacs Lisp interpreter. All high-level functionality is deliberately relegated to Emacs Lisp, so that it is easier to customize. Almost no-one except the actual Emacs developers customizes Emacs by altering the C code.

It should be noted that all of Emacs - the Emacs Lisp code, the C code, and the documentation - is freely available for examination, modification, and redistribution, under the terms of the GNU General Public License.

[Top]

Internals

The contents of buffers are stored as a contiguous sequence of characters divided by a gap, known as the buffer gap, where the editing point resides. Changes are made to the buffer by moving the gap and/or altering the characters next to the gap. This design allows most editing operations to be carried out efficiently, as not much memory has to be modified. This form of storage should be contrasted with the alternative, which is to each line of the document in a small buffer.

The downside to Emacs' design is a performance overhead from loading and interpreting the Lisp code. Several joke acronyms allude to this: Eight Megabytes And Constantly Swapping (from the days when eight megabytes was a lot of memory), Emacs Makes A(ny) Computer Slow, Emacs Munches All Computer Storage and Escape-Meta-Alt-Control-Shift. (The last refers to the perceived complexity of some of its default keyboard shortcuts; similarly, Even a Master of Arts Comes Simpler.) Modern computers generally have enough memory and processor power, compared to the systems on which Emacs was first implemented, that the performance issue is largely moot. Nevertheless, this is a frequent point raised by Emacs' detractors during the editor wars. Emacs' devotees offer Emacs Makes All Computing Simple as another meaning of the name.

See Emacs Lisp for a description of the Emacs Lisp interpreter.

[Top]

Distribution

Emacs is free software, distributed under the terms of the GNU GPL.

The source code and binaries are available via FTP from the GNU project website (see below). They are also widely available from other sites on the Internet. Vendors of Unices, both free and proprietary, frequently provide Emacs bundled with the operating system.

Emacs runs on a large number of platforms, including GNU/Linux, FreeBSD, and most Unices, Mac OS, and Microsoft Windows.

[Top]

Development

Emacs is part of the GNU project, and is under active development. Several, but not all, of the developers are affiliated with the Free Software Foundation (FSF).

Until 1999, Emacs development was relatively closed, to the point where it was used as an example of the "Cathedral" development style in The Cathedral and the Bazaar. The project has since adopted a public development mailing list and anonymous CVS access. As with all GNU projects, it remains policy to accept significant code contributions only if the copyright holder assigns the code's copyright to FSF, although one exception was made to this policy for the MULE (MULtilingual Extension) code since the copyright holder is the Japanese government and copyright assignment was not possible. This does not apply to bug fixes or minor code contributions. This policy is intended to facilitate copyleft enforcement, so that FSF can defend the software in a court case if one arises.

As of 2004, the latest release of GNU Emacs is version 21.3. Development takes place in a single CVS trunk, which is at version 21.3.50. The current maintainer is Richard Stallman.

[Top]

References

[Top]




  View Live Article   This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License