Learning GNU Emacs, 3rd Edition

Debra Cameron

James Elliott

Marc Loy

Eric S. Raymond

Bill Rosenblatt


3rd Edition


Emacs is the most powerful text editor available today. Unlike most other editors (in particular, unlike the standard Unix editor, vi), Emacs is a complete working environment. No matter what you do, you can start Emacs in the morning, work all day and all night, and never leave it: you can use it to edit, rename, delete, and organize files; to compile programs; to run shell commands; and so on. Before windowing systems like X and Microsoft Windows became popular, Emacs often served as a complete windowing system of its own. All you needed was a terminal, and you could live within Emacs forever. Emacs is also infinitely flexible; you can write your own commands, change the keys that are associated with commands, and (if you are willing to take the time) do just about anything you want.

Why Read This Book?

Because it does so much, Emacs has a reputation for being extremely complicated. We don't think that's warranted; we teach you Emacs from the ground up, covering first the basics and then some of the more advanced features.

In this book, we have tried to reach as broad an audience as possible: from casual users to professional writers and web authors to programmers to system administrators. No matter what you do with Emacs, you will find it's easy to learn; after one or two sessions, you'll know the basics of editing any file. After you learn the basics, you can go on to learn about more advanced topics that provide the real benefits of using Emacs. These include:

• Using multiple windows and buffers so you can work on several files at once

• Customizing keyboard commands

• Tailoring Emacs to fit your work style

• Making Emacs your work environment where you can do all your everyday tasks, such as organizing files, compiling programs, and issuing shell commands

• Creating macros to streamline repetitive tasks

• Using Emacs to support programming in many languages (including C, C++, Lisp, Java, and Perl)

• Formatting files with various markup languages, such as HTML and XML

• Using word abbreviations to avoid spelling out long phrases or to correct common misspellings

Of course, many of the topics may not apply to you; some topics may be appropriate for a second reading but not for the first. Toward the end of the preface, we'll sketch several different ways to approach the book, depending on your interests and experience.

Which Emacs Is Which?

Numerous versions of Emacs are available, offering a wide range of features, but two are in widespread use today: GNU Emacs and XEmacs. (An exhaustive list of Emacs implementations can be found at http://www.finseth.com/~fin/emacs.html.) XEmacs was originally tailored for GUI usage and has a fairly wide user base, but lacks some of the features of GNU Emacs.[1]

This book covers GNU Emacs. Since its appearance, GNU Emacs has become the most popular, powerful, and flexible Emacs, and there's no reason to believe that this situation will change. If you know GNU Emacs, you will be able to adapt to any other Emacs implementation with no trouble; it's not so easy to go in the other direction.

This book, however, isn't limited to GNU Emacs users. Because of the similarities between different Emacs implementations, this book should help you get started with any Emacs editor. The basic keyboard commands change little from one editor to another—you'll find that C-n (for Ctrl-n) almost always means "move to the next line." Emacs editors tend to differ in the more advanced commands and features, but if you are using these more advanced facilities and you aren't using GNU Emacs, you should consider making the switch.

What's New in This Edition?

This third edition covers GNU Emacs 21, specifically 21.3 and even more specifically 21.3.5.[2] This new edition has been completely revised and expanded to cover new features and to meet the evolving needs of Emacs users.

Here are some of the highlights of what we've changed:

• User interface changes, including the addition of an icon-based toolbar, extensive changes to menus, and a more graphical interface (Chapter 1)

• How Emacs interacts with the operating system clipboard, including specific clipboard-related commands (Chapter 2)

• Dynamic abbreviations (Chapter 3)

• Expanded coverage of the directory editor, Dired, to help you organize and work with files more efficiently (Chapter 5)

• Changes to the way Emacs handles tabs and indentation and how to get Emacs to do what you want it to (Chapter 7)

• Artist mode for drawing with the mouse (Chapter 7)

• Inserting characters from other character sets in HTML files (Chapter 8)

• Using font-lock mode for coloring text for easier editing (Chapter 9)

• Expanded Java coverage, including how to install and use the Java Development Environment for Emacs (JDEE) (Chapter 9)

• Perl support with Cperl mode (Chapter 9)

• Managing changes to large, multiple file projects more effectively using etags (Chapter 9)

• Customizing Emacs through the interactive Custom interface or through the .emacs startup file (Chapter 10)

• Expanded coverage of how version control mode connects with a variety of change control systems, including CVS, RCS, Subversion, and SCCS (Chapter 12)

• A new chapter on platform-specific considerations, including details on how to install the latest version of Emacs on Unix, Windows, and Mac OS X (Chapter 13)

GNU Emacs and the Free Software Foundation

You don't need to know its history to use GNU Emacs, but its origins are an interesting part of computer history. The Free Software Foundation (FSF), which maintains and distributes GNU Emacs, has become an important part of computer culture.

A long time ago (1975) at MIT, Richard Stallman wrote the first Emacs editor. According to the folklore, the original Emacs editor was a set of macros for TECO, an almost incomprehensible and now obsolete line editor. The name Emacs stands for "Editing Macros." Tradition also has it that Emacs is a play on the name of a favorite ice cream store. Much has happened since 1975. TECO has slipped into deserved obscurity, and Emacs has been rewritten as an independent program. Several commercial versions of Emacs appeared, of which Unipress Emacs and CCA Emacs were the most important. For several years, these commercial implementations were the Emacs editors you were most likely to run across outside of the academic world.

Stallman's Emacs became prominent with the birth of the Free Software Foundation (FSF) and the GNU Project in 1984. GNU stands for "GNU's Not Unix" and refers to a complete Unix-like operating system (OS) that Stallman and his associates were building.

Stallman founded the FSF to guarantee that some software would always remain free. Note that Free does not necessarily mean cheap (you may have to pay a fee to cover the cost of distribution); it most definitely does mean liberated from restrictions about how it can be used and specifically how it can be shared.

Stallman is widely recognized as the founder of the free software movement, which was an important predecessor of the open source movement. Linux is now the most prominent example of open source software, and it falls under the GNU Public License or GPL (available online at http://www.gnu.org/copyleft/gpl.html). Stallman argues that much of Linux outside the kernel itself is GNU software and so he refers to it as GNU/Linux. All controversies aside, Stallman's contribution to the open source movement cannot be overestimated. GNU software and open source software distributed under the GPL are a mainstay for developers and computer users all over the world.

The FSF was created precisely to distribute programs under terms that encourage you to share, rather than hoard, software. The GPL is designed to prevent an unfortunately common practice—namely, a company taking public domain code, making a few modifications and bug fixes, and then copyrighting the modified version. Once a company does this, the program has essentially become private property and disappears from the public domain. Stallman formed the foundation because he finds this practice abhorrent. As he explains in the GNU Manifesto, "I cannot in good conscience sign a nondisclosure agreement or a software license agreement . . . So that I can continue to use computers without dishonor, I have decided to put together a sufficient body of free software so that I will be able to get along without any software that is not free." Elsewhere in the manifesto, Stallman calls sharing software the "fundamental act of friendship among programmers." Their software is free because it can be shared and will always be shareable—without restriction. FSF software is not under restrictive copyright laws, which Stallman objects to in principle. In fact, he coined the term copyleft to describe the FSF's sharable software base.[3]

Since GNU Emac ...

Быстрая навигация назад: Ctrl+←, вперед Ctrl+→