Emacs

The  interface, running in a graphical environment.
Enlarge
The GNU Emacs interface, running in a graphical environment.

Emacs is a class of text editors, possessing an extensive set of features, that are popular with computer programmers and other technically-proficient computer users. The original EMACS, a set of Editor MACroS for the TECO editor, was written in 1976 by Richard Stallman, Guy Steele, and Dave Moon. It was based on TECMAC and TMACS, a pair of TECO-macro editors written by Guy Steele, Dave Moon, Richard Greenblatt, Charles Frankston, and others. Many versions of Emacs have appeared over the years, but nowadays there are two that are commonly used: GNU Emacs, written by Richard Stallman beginning in 1984, and XEmacs, which forked from GNU Emacs in 1991. Both use a powerful extension language, Emacs Lisp, which allows them to handle tasks ranging from writing and compiling computer programs to browsing the web.

Some people make a distinction between the lower-case word emacs, which is used to refer to Emacs-like editors (particularly GNU Emacs and XEmacs), and the capitalized word Emacs, which is used to refer to GNU Emacs. The word emacs is often pluralized as emacsen.

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

Contents

Using Emacs

Commands

From the Unix shell, a file is opened by typing "emacs [filename]". If the filename you entered does not exist a file will be created with that name. For example; navigating to the /etc/X11/ folder and typing "emacs xorg.conf" allows you to edit the X config file.

In the normal editing mode, Emacs behaves just like other text editors: the character keys (a, b, c, 1, 2, 3, etc.) insert the corresponding characters, the arrow keys move the editing point, backspace deletes text, and so forth. Other commands are invoked with modified keystrokes, pressing the control key and/or the meta key/alt key in conjunction with a regular key. Every editing command is actually a call to a function in the Emacs Lisp environment. Even a command as simple as typing a to insert the character a involves calling a function -- in this case, self-insert-command.

Some of the basic commands are shown below. The control key [Ctrl] is denoted by a capital C, and the meta or alt [Alt] key by a capital M.

Command Keystroke Description
forward-word M-f Move forward past one word.
undo C-/ Undo last change, and prior changes if pressed repeatedly.
keyboard-quit C-g Abort the current command.
fill-paragraph M-q Wrap text in ("fill") a paragraph.
save-buffer C-x C-s Save the current text into a file.
save-with-newname C-x C-w Save the current text as a file with the name you specify.
save-buffers-kill-emacs C-x C-c Offer to save changes, then exit Emacs.
set-marker C-[space] Set a marker from where you want to cut or copy.
cut C-w Cut all text between the marker and the cursor.
copy M-w Copy all text between the marker and the cursor.
paste C-y Paste text from the emacs clipboard

Note that the commands save-buffer and save-buffers-kill-emacs use multiple modified keystrokes. For example, C-x C-c means: while holding down the control key, press x; then, while holding down the control key, press c. This technique, allowing more commands to be bound to the keyboard than with the use of single keystrokes alone, first appeared in Emacs. It has since made its way into modern code editors like Visual Studio.

When Emacs is running a graphical interface, many commands can be invoked from the menubar or toolbar instead of using the keyboard. However, many experienced Emacs users prefer to use the keyboard because it is faster and more convenient once the necessary keystrokes have been memorized.

Some Emacs commands work by invoking an external program (such as ispell for spell-checking or gcc for program compilation), parsing the program's output, and displaying the result in Emacs.

The minibuffer

The minibuffer, normally the bottommost line, is where Emacs requests information. Text to target in a search, the name of a file to read or save, and similar information is entered in the minibuffer. Tab completion is always available in the minibuffer.

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, which the user can edit and save back to disk. Buffers are also used to store temporary text, such as the documentation strings displayed by the help library.

In both text terminal and graphical modes, Emacs is able to split the editing area into separate sections, so that more than one buffer can be displayed at a time. This has many uses. For example, one section can be used to display the source code of a program, while another displays the results from compiling the program. In graphical environments, Emacs can also launch multiple windows (which it calls "frames") for a similar purpose.

Editing modes

Emacs adapts its behavior to the type of text it is editing by entering editing modes called "major modes". Major modes are defined for ordinary text files, source code for many programming languages, HTML documents, TeX and LaTeX documents, and many other types of text. Each major mode tweaks certain Emacs Lisp variables to make Emacs behave more conveniently for the particular type of text. In particular, they usually implement syntax highlighting, using different fonts or colors to display keywords, comments, and so forth. Major modes also provide special editing commands; for example, major modes for programming languages usually define commands to jump to the beginning and the end of a function.

The behavior of Emacs can be further customized using "minor modes". While only one major mode can be associated with a buffer at a time, multiple minor modes can be simultaneously active. For example, the major mode for the C programming language defines a different minor mode for each of the popular indent styles.

Emacs history

Emacs began life at the MIT AI Lab during the 1970s. Prior to its introduction, the default editor on ITS, the operating system on the AI Lab's PDP-6 and PDP-10 computers, was a line editor known as TECO. Unlike modern text editors, TECO treated typing, editing, and document display separately. Typing characters into TECO did not place those characters directly into a document; one had to write a series of instructions in the TECO command language telling it to enter the required characters, during which time the edited text was not displayed on the screen. This behavior is similar to the program ed, which is still in use.

Carl Mikkelsen, one of the hackers at the AI Lab, added a display-editing mode to TECO, allowing 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, allowing the user to define certain keystrokes for performing multiple TECO commands.

The users at the AI Lab soon accumulated a large collection of custom macros. In 1976, Guy Steele took on the project of unifying the diverse macro sets into a single set. This task was completed by Stallman, who also wrote facilities for extending and documenting the new macro set. The resulting system was called EMACS, which 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. Stallman, however, denies that the ice cream was at all a factor in the naming of the editor, as he generally did not go to that store and had not liked their ice cream the one time he did try it.

Although EMACS was built on TECO, its behavior was different enough to be considered a text editor in its own right. It quickly became the standard editing program 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"), which were written by Michael McMahon and Daniel Weinreb. In 1978, Bernard Greenberg wrote Multics Emacs at Honeywell's Cambridge Information Systems Lab. Multics Emacs 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.

One early Emacs-like editor to run on Unix was Gosling Emacs, written by James Gosling in 1981. It was written in C and used an inconsequential dialect of Lisp, known as Mocklisp, as an extension language.

In 1984, Stallman began working on GNU Emacs, the first program in the nascent GNU project. GNU Emacs was written in C and used Emacs Lisp as an extension language. The first widely-distributed version of GNU Emacs was 15.34, which appeared in 1985. (Versions 2 through 12 never existed. Earlier versions of GNU Emacs had been numbered "1.x.x", but sometime after version 1.12 the decision was made to drop the "1", as it was thought the major number would never change. Version 13, the first public release, was made on March 20, 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.

Features

The remainder of this article discusses GNU Emacs and XEmacs, the only incarnations of Emacs that are widely used today. We will use the term "Emacs" to refer to both programs, as they have very similar features; XEmacs started as a fork of GNU Emacs, and subsequent versions have remained more or less compatible with GNU Emacs.

In spite of—or perhaps because of—its venerable background, Emacs is one of the most powerful and versatile text editors in existence. It should be noted that it is primarily a text editor, not a word processor; its huge feature set is geared toward helping the user to manipulate pieces of text, rather than manipulating the font of the characters or printing documents (though Emacs can do these as well). Emacs brings a host of features to bear on the seemingly-simple task of text editing, ranging from commands to manipulate words and paragraphs (deleting them, moving them, moving through them, and so forth), to syntax highlighting for making source code easier to read, to executing "keyboard macros" for performing arbitrary batches of editing commands defined by the user.

The rich variety of features found in Emacs is a result of its unusual design. Almost all of the functionality in the editor, ranging from basic editing operations such as the insertion of characters into a document to the configuration of the user interface, is controlled by a dialect of the Lisp programming language known as Emacs Lisp. In this Lisp environment, variables and even entire functions can be modified on the fly, without having to recompile or even restart the editor. As a result, the behavior of Emacs can be modified almost without limit, either directly by the user, or (more commonly) by loading bodies of Emacs Lisp code known variously as "libraries", "packages", or "extensions".

Emacs contains a large number of Emacs Lisp libraries, and more "third-party" libraries can be found on the Internet. Many libraries implement computer programming aids, reflecting Emacs' popularity among programmers. Emacs can be used as an Integrated Development Environment (IDE), allowing programmers to edit, compile, and debug their code within a single interface. Other libraries perform more unusual functions. A few examples are listed below:

The downside to Emacs' Lisp-based design is a performance overhead resulting from loading and interpreting the Lisp code. On the systems in which Emacs was first implemented, Emacs was often noticeably slower than rival text editors. 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 Computer Slow, and Eventually Mallocs All Computer Storage. However, modern computers are fast enough that Emacs is seldom felt to be slow. In fact, Emacs starts up more quickly than most modern word processors.

Platforms

Emacs is one of the most portable non-trivial computer programs in the world. It runs on a wide variety of operating systems, including most Unix-like systems (GNU/Linux, the various BSDs, Solaris, and AIX, etc.), MS-DOS, Microsoft Windows, OpenVMS, and Mac OS X.

Emacs runs on both text terminals and graphical user interface (GUI) environments. On Unix-like operating systems, Emacs uses the X Window System to produce its GUI, either directly or using a "widget toolkit" such as Motif, LessTif, or GTK+. Emacs can also use the native graphical systems of Mac OS X (using the Carbon interface) and Microsoft Windows. The graphical interface provides menubars, toolbars, scrollbars, and context menus.

Customization

Most users of Emacs customize the editor to suit their needs. There are three primary ways to customize Emacs. The first is the customize extension, which allows the user to set common customization variables, such as the colour scheme, using a graphical interface. This is intended for Emacs beginners who do not want to work with Emacs Lisp code.

The second is to collect keystrokes into macros and replay them to automate complex, repetitive tasks. This is often done on an ad-hoc basis and each macro discarded after use, although macros can be saved and invoked at need.

The third method for customizing Emacs is using Emacs Lisp. Usually, user-supplied Emacs Lisp code is stored in a file called .emacs, which is loaded when Emacs starts up. The .emacs file is often used to set variables and key bindings different from the default setting, and to define new commands that the user finds convenient. Many advanced users have .emacs files hundreds of lines long, with idiosyncratic customizations that cause Emacs to diverge wildly from the default behavior.

If a body of Emacs Lisp code is generally useful, it is often packaged as a library and distributed to other users. Many such third-party libraries can be found on the Internet; for example, there is a library called wikipedia-mode for editing Wikipedia articles. There is even a Usenet newsgroup, gnu.emacs.sources, which is used for posting new libraries. Some third-party libraries eventually make their way into Emacs, thus becoming a "standard" library.

Documentation

Emacs includes a powerful help library that can display the documentation for every single command, variable, and internal function. Because of this, Emacs is sometimes described as a "self-documenting" text editor. This description, which originated in the days when few programs contained built-in help systems, may be somewhat misleading. Emacs does not write its own documentation; what "self-documentation" means is that Emacs displays the documentation using its own interface, instead of launching a separate "help browser". This makes Emacs' documentation very accessible. For example, the user can find out about the command bound to a particular keystroke simply by entering C-h k (which runs the command describe-key), followed by the keystroke.

The Emacs help system is useful not only for beginners, but also for advanced users writing Emacs Lisp code. If the documentation for a function or variable is not enough, the help system can be used to browse the Emacs Lisp source code for both built-in libraries and installed third-party libraries. It is therefore very convenient to program in Emacs Lisp using Emacs itself.

Apart from the built-in documentation, Emacs has an unusually long, detailed and well-written manual. An electronic copy of the GNU Emacs Manual, written by Richard Stallman, is included with GNU Emacs and can be viewed with the built-in Info browser. XEmacs has a similar manual, which forked from the GNU Emacs Manual at the same time as the XEmacs software. Two other manuals, the Emacs Lisp Reference Manual by Bill Lewis, Richard Stallman, and Dan Laliberte, and Programming in Emacs Lisp by Robert Chassell, are also included. Apart from the electronic versions, all three manuals are also available in book form, published by the Free Software Foundation.

Emacs also has a built-in tutorial. When Emacs is started with no file to edit, it displays instructions for performing simple editing commands and invoking the tutorial.

Internationalization

Emacs supports the editing of text written in many human languages. There is support for many alphabets, scripts, writing systems, and cultural conventions. Emacs provides spell checking for many languages by calling external programs such as ispell. Many encoding systems, including UTF-8, are supported. XEmacs version 21.5 has full Unicode support, and similar support for GNU Emacs is being developed. However, the Emacs user interface is in English, and has not been translated into any other language.

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

License

The source code, including both the C and Emacs Lisp components, is freely available for examination, modification, and redistribution, under the terms of the GNU General Public License (GPL). Older versions of the GNU Emacs documentation were released under a modified GPL which forced the inclusion of certain text in any modified copy. In the GNU Emacs user's manual, for example, this included how to obtain GNU Emacs and Richard Stallman's political essay The GNU Manifesto. The XEmacs manuals, which were inherited from older GNU Emacs manuals when the fork occurred, have the same license. The newer versions of the GNU Emacs documentation, meanwhile, uses the GNU Free Documentation License and makes use of "invariant sections" to force the inclusion of the same documents, additionally requiring that the manuals proclaim themselves as GNU Manuals, whether or not this would be accurate.

See also

References

  • Eugene Ciccarelli (1978) An Introduction to the Emacs Editor. Cambridge, Massachusetts: MIT Artificial Intelligence Laboratory. AIM-447.
  • Stallman, Richard M. (1981). EMACS: The Extensible, Customizable, Self-Documenting Display Editor. Cambridge Massachusetts: MIT. MIT Artificial Intelligence Laboratory publication AIM-519A. PDF (ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-519A.pdf) HTML (http://www.gnu.org/software/emacs/emacs-paper.html)
  • Stallman, Richard M. (2002). GNU Emacs Manual. 15th edition. GNU Press ISBN 1-882114-85-X.
  • Chassell, Robert J. (2004). An Introduction to Programming in Emacs Lisp. GNU Press ISBN 1-882114-56-6.

External links

de:Emacs es:Emacs eo:Emacs fr:GNU Emacs ko:Emacs ia:Emacs it:Emacs he:Emacs nl:Emacs ja:Emacs pl:Emacs pt:Emacs ru:Emacs sv:Emacs zh:Emacs

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools