Emacs
Emacs or EMACS is a family of text editors that are characterized by their extensibility. The manual for the most widely used variant, GNU Emacs, describes it as "the extensible, customizable, self-documenting, real-time display editor". Development of the first Emacs began in the mid-1970s, and work on its direct descendant, GNU Emacs, continues actively.
Emacs has over 10,000 built-in commands and its user interface allows the user to combine these commands into macros to automate work. Implementations of Emacs typically feature a dialect of the Lisp programming language that provides a deep extension capability, allowing users and developers to write new commands and applications for the editor. Extensions have been written to manage email, files, outlines, and RSS feeds, as well as clones of ELIZA, Pong, Conway's Life, Snake and Tetris.
The original EMACS was written in 1976 by David A. Moon and Guy L. Steele Jr. as a set of Editor MACroS for the TECO editor. It was inspired by the ideas of the TECO-macro editors TECMAC and TMACS.
The most popular, and most ported, version of Emacs is GNU Emacs, which was created by Richard Stallman for the GNU Project. XEmacs is a variant that branched from GNU Emacs in 1991. GNU Emacs and XEmacs use similar Lisp dialects and are for the most part compatible with each other.
Emacs is, along with vi, one of the two main contenders in the traditional editor wars of Unix culture. Emacs is among the oldest free and open source projects still under development.
History
Emacs development began during the 1970s at the MIT AI Lab, whose PDP-6 and PDP-10 computers used the Incompatible Timesharing System operating system that featured a default line editor known as Tape Editor and Corrector. Unlike most modern text editors, TECO used separate modes in which the user would either add text, edit existing text, or display the document. One could not place characters directly into a document by typing them into TECO, but would instead enter a character in the TECO command language telling it to switch to input mode, enter the required characters, during which time the edited text was not displayed on the screen, and finally enter a character to switch the editor back to command mode. This behavior is similar to that of the program ed.Richard Stallman visited the Stanford AI Lab in 1972 or 1974 and saw the lab's E editor, written by Fred Wright. He was impressed by the editor's intuitive WYSIWYG behavior, which has since become the default behavior of most modern text editors. He returned to MIT where Carl Mikkelsen, a hacker at the AI Lab, had added to TECO a combined display/editing mode called Control-R that allowed the screen display to be updated each time the user entered a keystroke. Stallman reimplemented this mode to run efficiently and then added a macro feature to the TECO display-editing mode that allowed the user to redefine any keystroke to run a TECO program.
E had another feature that TECO lacked: random-access editing. TECO was a page-sequential editor that was designed for editing paper tape on the PDP-1 and typically allowed editing on only one page at a time, in the order of the pages in the file. Instead of adopting E's approach of structuring the file for page-random access on disk, Stallman modified TECO to handle large buffers more efficiently and changed its file-management method to read, edit, and write the entire file as a single buffer. Almost all modern editors use this approach.
The new version of TECO quickly became popular at the AI Lab and soon accumulated a large collection of custom macros whose names often ended in MAC or MACS, which stood for macro. Two years later, Guy Steele took on the project of unifying the diverse macros into a single set. Steele and Stallman's finished implementation included facilities for extending and documenting the new macro set. The resulting system was called EMACS, which stood for Editing MACroS or, alternatively, E with MACroS. Stallman picked the name Emacs "because
Stallman saw a problem in too much customization and de facto forking and set certain conditions for usage. He later wrote:
The original Emacs, like TECO, ran only on the PDP-10 running ITS. Its behavior was sufficiently different from that of TECO that it could be considered a text editor in its own right, and it quickly became the standard editing program on ITS. Mike McMahon ported Emacs from ITS to the TENEX and TOPS-20 operating systems. Other contributors to early versions of Emacs include Kent Pitman, Earl Killian, and Eugene Ciccarelli. By 1979, Emacs was the main editor used in MIT's AI lab and its Laboratory for Computer Science.
Implementations
Early implementations
In the following years, programmers wrote a variety of Emacs-like editors for other computer systems. These included EINE and ZWEI, which were written for the Lisp machine by Mike McMahon and Daniel Weinreb, and Sine, which was written by Owen Theodore Anderson. Weinreb's EINE was the first Emacs written in Lisp. In 1978, Bernard Greenberg wrote Multics Emacs almost entirely in Multics Lisp at Honeywell's Cambridge Information Systems Lab. Multics Emacs was later maintained by Richard Soley, who went on to develop the NILE Emacs-like editor for the NIL Project, and by Barry Margolin. Many versions of Emacs, including GNU Emacs, would later adopt Lisp as an extension language.James Gosling, who would later invent NeWS and the Java programming language, wrote Gosling Emacs in 1981. The first Emacs-like editor to run on Unix, Gosling Emacs was written in C and used Mocklisp, a language with Lisp-like syntax, as an extension language.
GNU Emacs
Richard Stallman began work on GNU Emacs in 1984 to produce a free software alternative to the proprietary Gosling Emacs. GNU Emacs was initially based on Gosling Emacs, but Stallman's replacement of its Mocklisp interpreter with a true Lisp interpreter required that nearly all of its code be rewritten. This became the first program released by the nascent GNU Project. GNU Emacs is written in C and provides Emacs Lisp, also implemented in C, as an extension language. Version 13, the first public release, was made on March 20, 1985. The first widely distributed version of GNU Emacs was version 15.34, released later in 1985. Early versions of GNU Emacs were numbered as 1.x.x, with the initial digit denoting the version of the C core. The 1 was dropped after version 1.12, as it was thought that the major number would never change, and thus the numbering skipped from 1 to 13. In September 2014, it was announced on the GNU emacs-devel mailing list that GNU Emacs would adopt a rapid release strategy and version numbers would increment more quickly in the future.GNU Emacs was later ported to Unix. It offered more features than Gosling Emacs, in particular a full-featured Lisp as its extension language, and soon replaced Gosling Emacs as the de facto Unix Emacs editor. Markus Hess exploited a security flaw in GNU Emacs' email subsystem in his 1986 cracking spree in which he gained superuser access to Unix computers.
Most of GNU Emacs functionality is implemented through a scripting language called Emacs Lisp. Because about 70% of GNU Emacs is written in the Elisp extension language, one only needs to port the C core which implements the Elisp interpreter. This makes porting Emacs to a new platform considerably less difficult than porting an equivalent project consisting of native code only.
GNU Emacs development was relatively closed until 1999 and 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. Development took place in a single CVS trunk until 2008 and was then switched to the Bazaar DVCS. On November 11, 2014, development was moved to Git.
Richard Stallman has remained the principal maintainer of GNU Emacs, but he has stepped back from the role at times. Stefan Monnier and Chong Yidong were maintainers from 2008 to 2015. John Wiegley was named maintainer in 2015 after a meeting with Stallman at MIT. As of early 2014, GNU Emacs has had 579 individual committers throughout its history.
XEmacs
Lucid Emacs, based on an early alpha version of GNU Emacs 19, was developed beginning in 1991 by Jamie Zawinski and others at Lucid Inc. One of the best-known early forks in free software development occurred when the codebases of the two Emacs versions diverged and the separate development teams ceased efforts to merge them back into a single program. Lucid Emacs has since been renamed XEmacs. Its development has slowed, with the most recent stable version 21.4.22 released in January 2009, while GNU Emacs has implemented many formerly XEmacs-only features.Other forks of GNU Emacs
Other notable forks include:- Aquamacs – based on GNU Emacs which focuses on integrating with the Apple Macintosh user interface
- Meadow – a Japanese version for Microsoft Windows
- SXEmacs – Steve Youngs' fork of XEmacs
Various Emacs editors
Other projects aim to implement Emacs in a different dialect of Lisp or a different programming language altogether. Although not all are still actively maintained, these clones include:
- MicroEMACS, which was originally written by Dave Conroy and further developed by Daniel Lawrence and which exists in many variations.
- mg, originally called MicroGNUEmacs and, later, mg2a, a public-domain offshoot of MicroEMACS intended to more closely resemble GNU Emacs. Now installed by default on OpenBSD.
- JOVE, Jonathan Payne's non-programmable Emacs implementation for UNIX-like systems.
- MINCE, a version for CP/M and later DOS, from Mark of the Unicorn. MINCE evolved into Final Word, which eventually became the Borland Sprint word processor.
- Perfect Writer, a CP/M implementation derived from MINCE that was included circa 1982 as the default word processor with the very earliest releases of the Kaypro II and Kaypro IV. It was later provided with the Kaypro 10 as an alternative to WordStar.
- Freemacs, a DOS version that uses an extension language based on text macro expansion and fits within the original 64 KiB flat memory limit.
- Zile. Zile was a recursive acronym for Zile Is Lossy Emacs, but the project was rewritten in Lua and now gives the expansion as Zile Implements Lua Editors. The new Zile still includes an implementation of Emacs in Lua called Zemacs. There is also an implementation of vi called Zi.
- Zmacs, for the MIT Lisp Machine and its descendants, implemented in ZetaLisp.
- Climacs, a Zmacs-influenced variant implemented in Common Lisp.
- Epsilon, an Emacs clone by Lugaru Software. Versions for DOS, Windows, Linux, FreeBSD, Mac OS X and O/S 2 are bundled in the release. It uses a non-Lisp extension language with C syntax and used a very early concurrent command shell buffer implementation under the single-tasking MS-DOS.
- PceEmacs is the Emacs-based editor for SWI-Prolog.
- Amacs, an Apple II ProDOS version of Emacs implemented in 6502 assembly by Brian Fox.
- Hemlock, originally written in Spice Lisp, then Common Lisp. A part of CMU Common Lisp. Influenced by Zmacs. Later forked by Lucid Common Lisp, LispWorks and Clozure CL projects. There is also a Portable Hemlock project, which aims to provide a Hemlock, which runs on several Common Lisp implementations.
- umacs, an implementation under OS-9
Editors with Emacs emulation
- Joe's Own Editor emulates Emacs keybindings when invoked as jmacs.
- JED has an emulation mode for Emacs.
- Eclipse provides a set of Emacs keybindings.
- IntelliJ IDEA provides a set of Emacs keybindings.
- Epsilon Defaults to Emacs emulation and supports a vi mode.
- The Cocoa text system uses some of the same terminology and understands many Emacs navigation bindings. This is possible because the native UI uses the Command key instead of the Control key.
- GNU Readline is a line editor that understands the standard Emacs navigation keybindings. It also has a vi emulation mode.
- GNOME Builder has an emulation mode for Emacs.
- MATLAB provides Emacs keybindings for its editor.
Features
GNU Emacs is a real-time display editor, as its edits are displayed onscreen as they occur. This is standard behavior for modern text editors but EMACS was among the earliest to implement this functionality instead of having to issue a separate command to insert new edits into the existing text as in vi.
General architecture
Almost all of the functionality in Emacs, including basic editing operations such as the insertion of characters into a document, is achieved through functions written in a dialect of the Lisp programming language. The dialect used in GNU Emacs is known as Emacs Lisp. The ELisp layer sits atop a stable core of basic services and platform abstraction written in the C programming language. In this Lisp environment, variables and functions can be modified with no need to recompile or restart Emacs.Emacs operates on data structures called buffers containing text with additional attributes; every buffer maintains its own point and mark, the name of the file it is visiting and the set of active modes, which control editor behaviour through variables. Elisp code can be executed interactively through named commands, which can be bound to key presses or accessed by name; some commands evaluate arbitrary Elisp code from buffers.
Buffers are displayed in windows, which are tiled portions of the terminal screen or the GUI window. Unless configured otherwise, windows include scroll bars, line numbers, a header line at the top and a mode line at the bottom.
Multiple windows can be opened onto the same buffer, for example to see different parts of a long text, and multiple buffers can share the same text, for example to take advantage of different major modes in a mixed-language file. The mode can also be changed manually as needed with
M-x <mode name>
.Customizability
- Keystrokes can be recorded into macros and replayed to automate complex, repetitive tasks. This is often done on an ad-hoc basis, with each macro discarded after use, although macros can be saved and invoked later.
- At startup, Emacs executes an Emacs Lisp script named . This personal customization file can be arbitrarily long and complex, but typical content includes:
- * Setting global variables or invoking functions to customize Emacs behaviour, for example
- * Key bindings to override standard ones and to add shortcuts for commands that the user finds convenient but don't have a key binding by default. Example:
- * Loading, enabling and initializing extensions
- * Configuring event hooks to run arbitrary code at specific times, for example to automatically recompile source code after saving a buffer
- * Executing arbitrary files, usually to split an overly long configuration file into manageable and homogeneous parts
- The customize extension allows the user to set configuration properties such as the color scheme interactively, from within Emacs, in a more user-friendly way than by setting variables in : it offers search, descriptions and help text, multiple choice inputs, reverting to defaults, modification of the running Emacs instance without reloading, and other conveniences similar to the preferences functionality of other programs. The customized values are saved in automatically.
- Themes, affecting the choice of fonts and colours, are defined as elisp files and chosen through the customize extension.
Self-documenting
Emacs also has a built-in tutorial. Emacs displays instructions for performing simple editing commands and invoking the tutorial when it is launched with no file to edit. The tutorial is by Stuart Cracraft and Richard Stallman.
Culture
Church of Emacs
The Church of Emacs, formed by Richard Stallman, is a parody religion created for Emacs users. While it refers to vi as the editor of the beast, it does not oppose the use of vi; rather, it calls it proprietary software anathema. The Church of Emacs has its own newsgroup, alt.religion.emacs, that has posts purporting to support this parody religion. Supporters of vi have created an opposing Cult of vi.Stallman has jokingly referred to himself as St I GNU cius, a saint in the Church of Emacs.
Emacs pinky
There is folklore attributing a repetitive strain injury colloquially called Emacs pinky to Emacs' strong dependence on modifier keys, although there have not been any studies done to show Emacs causes more such problems than other keyboard-heavy computer programs.Users have addressed this through various approaches. Some users recommend simply using the two Control keys on typical PC keyboards like Shift keys while touch typing to avoid overly straining the left pinky. Software-side methods include:
- Customizing the key layout so that the Control key is transposed with the caps lock key. Similar techniques include defining the caps lock key as an additional Control key or transposing the Control and Meta keys.
- Software, such as xwrits or the built-in type-break-mode in Emacs, that reminds the user to take regularly scheduled breaks.
- Using the ErgoEmacs keybindings.
- Customizing the whole keyboard layout to move statistically frequent Emacs keys to more appropriate places.
- Packages such as
ace-jump-mode
or elisp extensions that provide similar functionality of tiered navigation, first asking for a character then replacing occurrences of the character with access keys for cursor movement. -
evil-mode
, an advanced Vim emulation layer. -
god-mode
, which provides an approach similar to vim's with a mode for entering Emacs commands without modifier keys. - Using customized key layout offered by Spacemacs, a project where
Space
key is used as the main key for initiating control sequences. The project also heavily incorporates bothevil-mode
andgod-mode
. - StickyKeys, which turns key sequences into key combinations.
- Emacs' built-in
viper-mode
that allows use of the vi key layout for basic text editing and the Emacs scheme for more advanced features. - Giving a dual role to a more-comfortably accessed key such as the Space bar so that it functions as a Control key when pressed in combination with other keys. Ergonomic keyboards or keyboards with a greater number of keys adjacent to the space bar, such as Japanese keyboards, allow thumb control of other modifier keys too like Meta or Shift.
- Using a limited ergonomic subset of keybindings, and accessing other functionality by typing
M-x <command-name>
. M-x itself can also be rebound. - Driving Emacs through voice input.
The Emacs pinky is a relatively recent development. The Space-cadet keyboard on which Emacs was developed had oversized Control keys that were adjacent to the space bar and were easy to reach with the thumb.