Home > Store

GNU Emacs: UNIX Text Editing and Programming

Register your product to gain access to bonus material or receive a coupon.

GNU Emacs: UNIX Text Editing and Programming


  • Your Price: $46.39
  • List Price: $57.99
  • We're temporarily out of stock, but order now and we'll send it to you later.


  • Copyright 1992
  • Dimensions: 7-3/8" x 9-1/4"
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-56345-2
  • ISBN-13: 978-0-201-56345-0

"Clarity, explanations, illustrations, command summaries; finally a useful book on Emacs!"
-Peter Salus, SUN Users Group

GNU Emacs is quickly becoming the text editor and programming environment of choice among UNIX users. This book is a succinct tutorial and comprehensive reference to standard GNU Emacs.

GNU Emac's text-editing capabilities are impressive: outline editing, spell checking, handling multiple files (buffers), indenting, text filling, sorting, passing text through shell filters, keeping backups automatically, printing buffers, etc. In addition, GNU Emacs provides the Dired facility for managing your files without leaving the Editor!

GNU Emacs' capabilities as a programming environment are unequaled by other UNIX text editors. This book discusses GNU Emacs programming modes for C, FORTRAN, LISP, and even Pascal. These modes allow you to do syntax-direct editing, compiling, comment insertion, automatic program indentation, multiple-file search-and-replace operations (with tag files), and source documenting (with ChangeLog files).

If you are new to GNU Emacs, you will find the step-by-step tutorials invaluable. You will also appreciate the gentle introduction to basic capabilities, leading you gradually toward more advanced usage.

If you are an experienced GNU Emacs user, the command summaries allow you to quickly access needed reference information, and you will pick up some tricks and new ideas from the sections and chapters on advanced usage.

If you are a vi user who wants to switch to GNU Emacs, but you don't want to struggle with the associated learning curve, you will appreciate the comprehensive appendix that maps vi commands to their GNU Emacs counterparts. It shows you how to do all you favorite vi commands in GNU Emacs!


Sample Content

Table of Contents

(All chapters conclude with a Summary.)



1. A Quick Tour of Emacs.

Starting Emacs.

Exiting Emacs.

Understanding the Emacs Screen.

Tying Text.

Typing Commands.

Using a Basic Set of Editing Commands.

Getting Online Help.

Using Emacs to Process Electronic Mail.

Using Emacs to Manage Files.

Changing Emacs’ Behavior with Variables.

2. Basic Editing Commands.

Visiting a File.

Saving a Buffer.

Listing Buffers.

Switching to a Different Buffer.

Killing A Buffer.

Setting the Mode for a Buffer.

Moving the Cursor.

Using Line Numbers.

Deleting Text.

Undoing Mistakes.

Using Regions.

Searching for Text.

Searching and Replacing Text.

Overwriting Text.

3. More Efficient Editing.

Running a Command Multiple Times.

Modifying Command Behavior with Arguments.

Inserting Control Characters into a Buffer.

Working with Words, Sentences, and Paragraphs.

Working with Pages.

Working with Blank Lines.

Getting Cursor, Line, and Page Information.

Transposing Text.

Filling Text.

Indenting Text.

Changing Letter Case.

Searching and Replacing Text.

Narrowing a Buffer.

Moving the Cursor to Previous Marks (the Mark Ring).

Using the Kill Ring.

Completing Long Command Names.

Completing File Names.

Using Abbreviations (Text Expansions).

Using Macros for Repeated Editing Tasks.

Scrolling Windows.

Wording with Multiple Windows.

Printing a Buffer.

Listing a Directory.

4. Advanced Editing.

Changing Emacs’ Behavior with Commands.

Changing Emacs’ Behavior with Command-Line Arguments.

Searching for Regular Expressions (Regexps).

Searching and Replacing Regexps.

Editing Outlines.

Manipulating Buffers.

Advanced File Operations.

Managing Auto-Saving.

Managing Emacs Backup Files.

Reverting a Buffer to Its Original Contents.

Preventing Simultaneous Editing.

Advanced Window Operations.

Editing Your Responses in the Minibuffer.

Sorting Test.

Using Rectangles.

Using Registers.


5. Program Development in Emacs.

Supported Editing Modes.

Using Fundamental and Text Mode Commands in Programming Modes.

Moving by Function.

Marking Functions.

Indenting Programs Commenting Programs.

Matching Parentheses, Braces, and Brackets.

Forcing Balanced Parentheses.

Selectively Displaying Program Lines.

Getting Documentation on System Commands and Routines.

Editing Across Multiple Files with Tag Tables.

Keeping Track of Changes to source with a ChangeLog.

Compiling Programs.

Sexp Commands (Advanced Usage).

6. Editing in C Mode.

Invoking C Mode.

Assumptions About C Source.

Moving Among Functions.

Marking Functions.

Indenting Programs.

Commenting Programs.

Working with Sexps and Lists (Advanced Usage).

Customizing Indentation (Advanced Usage).

Customizing Commenting (Advanced Usage).

7. Editing in FORTRAN Mode.

Invoking FORTRAN Mode.

Assumptions About FORTRAN Source.

Moving Among Subprograms and Statements.

Marking Subprograms.

Indenting Programs.

Labeling Lines.

Commenting Programs.

Using FORTRAN Keyword Abbreviations.

Working with Sexps and Lists (Advanced Usage).

What Are Sexps and Lists in FORTRAN Mode?

Customizing Indentation (Advanced Usage).

Customizing Commenting (Advanced Usage).

8. Editing in Lisp Modes.

Lisp Major Modes.

Assumptions About Lisp Source.

Moving Among Defuns.

Moving Among Sexps and Lists.

List and Sexp Motion Commands.

Marking Text.

Transposing Sexps.

Killing Sexps.

Indenting Programs.

Commenting Programs.

Evaluating Lisp Code.

Customizing Indentation (Advanced Usage).

Customizing Commenting (Advanced Usage).


9. Getting Online Help.

Running Help Commands.

Getting Instructions for Using Help.

Getting Command Information.

10. Using Emacs for Electronic Mail.

The RMAIL Facility and Other UNIX Mail Facilities.

Reading Mail Messages.

Exiting from the RMAIL Buffer Moving Around Your Mail Messages.

Saving Messages to Files.

Removing Messages.

Getting New Mail.

Using a Mail Summary to Scan Messages.

Composing and Sending Messages.

Using Mode Line Status Messages (Labels).

Using Multiple Mailbox Files.

Reading Digest Messages.

Associating UNIX Mailbox Files with RMAIL Mailbox Files (Advanced Usage).

11. Managing Files and Buffers.

Using the Dired Facility to Manage Files.

Managing Multiple Buffers with Buffer-Menus.

12. Miscellaneous Emacs Features.

Checking Your Spelling.

Rerunning Commands from the Command History.

Recovering Files After System Crashes.

Using UNIX Commands in Emacs.

Running a UNIX Shell in an Emacs Buffer.

Nroff Major Mode.

TeX Modes: LaTeX and Plain TeX.

Picture Mode.

Doctor Mode.


13. Customizing the Emacs Environment.

Using a .emacs Start-Up File.

Using Variables to Change Emacs’ Behavior.

Changing Command Key Bindings.

Forcing Confirmation for a Function.

More About Variable (Advanced Usage).

More About Key Bindings (Advanced Usage).

Examples of .emacs Customizations.

14. Administering Emacs.

Finding Emacs and identifying Its Parts.

Using New (or Notes) to Get Emacs Information.

Installing Emacs.

A: Editing in Pascal Mode.

Obtaining a Pascal Mode.

Enabling Pascal Mode.

Assumptions About Pascal Source.

Moving the Cursor.

Indenting Programs.

Commands That Build Pascal Constructs.

Creating a New Program.

Commenting Programs.

Working with Sexps and Lists (Advanced Usage).

Customizing Indentation.

Customizing Commenting (Advanced Usage).

B: Emacs-Lisp Programming.

An Overview of Emacs-Lisp Programming.

Getting Documentation on Emacs-Lisp Defuns and Variables.

Evaluating Lisp Code.

Loading Emacs-Lisp Libraries.

Compiling Emacs-Lisp Code.

Debugging Emacs-Lisp Code (Advanced Usage).

Converting Mocklisp to Emacs-Lisp (for Mocklisp Users).


C: Switching from vi to Emacs.

The vi Emulation Mode in Emacs.

Starting the Editor.

Saving Text and Exiting.

Line Number Information Commands.

Inserting Text.

Undoing Commands.

Repeating Commands.

Rerunning Previous Commands.

Moving the Cursor.

Deleting Text.

Using Marks.

Searching for Text Search and Replace Text.

Indenting Text.

Copying and Moving Blocks of Text.

Changing (Overwriting) Text.

Scrolling Text.

Using Shell Commands.

Using Macros.

Using Abbreviations.

Miscellaneous Commands.

D: Emacs Command Reference.




Case Conversion.

C Mode.


Cursor Motion.

Debugger (Emacs-Lisp).

Deletion and Killing.


Display Management.

Editor Emulation (EDT, vi, Gosling Emacs).

Emacs-Lisp Programming.







Key Bindings.

Killing and Yanking (Moving and Copying).

Lisp Modes.

Location and Date/Time.



Minibuffer Editing.


Nroff Mode.

Numeric Prefix.

Outline Editing.



Picture Mode.






Searching and Replacing.


Sexps and Lists (Balanced Expressions).





TeX Mode.






Index. 0201563452T04062001


GNU Emacs is a powerful, integrated computing environment for UNIX that lets you perform a wide range of editing, programming, and file management tasks. If you have never used Emacs, this book will gently but rapidly introduce you to its most serviceable features. If you are a casual Emacs user, we will attempt to show you ways to edit and manage your files more efficiently. And for experienced users, we have included advanced techniques and reference information to help you unlock the power and flexibility of the environment. Always our emphasis is on practical information, on the commands and features we have found in our own experience to be most useful and powerful.

What is GNU Emacs?

The name, Emacs, is an acronym derived from "Editor MACroS." A macro is a command that reduces a multi-step process to just a few keystrokes. Emacs uses the Control key and other keys to define a set of one, two, or three keystroke macros (commands) that execute all of its functions. The original set of macros from which Emacs evolved was developed by Richard Stallman and Guy Steele at MIT. Stallman later went on to form the Free Software Foundation, an organization that develops and distributes Emacs and other free software products.

"GNU"-pronounced "G-Nu"-is a self-referencing acronym derived from the phrase, "GNU's Not UNIX." GNU is the Free Software Foundation's name for a complete set of UNIX-compatible programs, of which Emacs is a part. When completed, GNU will replace many of the standard components of the UNIX operating system.

While many UNIX users regard GNU Emacs as an excellent alternative to the vi editor, true Emacs aficionados understand that Emacs is not merely an editor, but a complete environment for performing many common computing tasks. Some of the tasks you can perform in the Emacs environment include:

  • Text Editing. Emacs provides unrivaled text-editing power. You can edit multiple documents simultaneously, use specialized editing modes designed specifically for your editing task, create your own powerful keyboard macros, and spell-check your document, to name just a few capabilities.

  • Software Development. Emacs provides several programming language modes, including C, FORTRAN, and Lisp (Pascal mode, while not included with GNU Emacs, is available from other sources; see Appendix A). Emacs provides a complete environment for editing, formatting, and compiling source code.

  • File Management. Emacs provides facilities for manipulating files and directories on your UNIX system.

  • Outlining. Emacs lets you create and edit outlines, using Emacs' special outline mode.

  • Electronic Mail Processing. the Emacs mail handler lets you compose, send, and receive electronic mail (e-mail) messages.

  • Environment Customization. Emacs itself is open to customization and extension to suit you individual preferences and needs. You can replace one command key-sequence with another, and develop and integrate you own commands.

About This Book

This book is designed to be a practical companion to Emacs, with examples, tutorials, reference information, and advice for new and experienced users alike. Some of its key features include:

  • Graduated Instructions. New users will quickly learn the basics by working through the "Quick Tour" in Chapter 1, which introduces the key Emacs features and commands. Subsequent chapters build upon this foundation by introducing more efficient and advanced editing techniques.

  • Extensive Tutorials and Examples. Every important feature is thoroughly explained, then demonstrated with an example or short tutorial that you can try on your own Emacs system.

  • Comprehensive Emacs Reference. Advanced users will appreciate the command and function reference in Appendix D, as well as the summary of commands and concepts provided at the end of each chapter.

  • vi-to-Emacs Migration Guide. For vi users who want to move to Emacs, Appendix C lists Emacs equivalents for most vi editor commands.

  • Language-specific Programming Chapters. Individual chapters are provided for programming with C, FORTRAN, Lisp, and Pascal, including advanced instructions for customizing indentation and commenting styles.

  • Customization Instructions. Advanced Emacs users will find helpful advice for customizing and extending Emacs, with a supporting introduction to Emacs-Lisp in Appendix B.

Because Emacs is such an extensive and versatile system, you should read this book selectively, focusing on the material that relates to your immediate needs.

Part 1, "Text Editing in Emacs," helps you build the basic skills you will need regardless of how you intend to use Emacs. It also describes more efficient and advanced editing techniques for those who need them. This part of the book along with the reference information in Appendix D, may be all you need to read if you are interested solely in proficient text editing.

Chapters in this section include:

Chapter 1: A Quick Tour of Emacs. This chapter briefly surveys all aspects of the Emacs environment. Here you will learn to use some common editing commands and be introduced to the online help facility, the electronic mail handler, and the file management facility.

Chapter 2: Basic Editing Commands. This chapter teaches you how to load and save files, insert and delete text, move around your documents, cut and past regions of text, and perform keyword searches. The features described here are prerequisites to using the more advanced capabilities described in the later chapters.

Chapter 3: More Efficient Editing. This chapter describes more efficient ways to edit your documents, including performing operations multiple times, editing words, sentences, paragraphs and pages, using abbreviations and macros, and working with multiple windows.

Chapter 4: Advanced Editing. This chapter describes advanced text-editing features, such as changing Emacs' default behavior, searching for regular expressions, and editing outlines, as well as advanced file, buffer, and window operations.

Part 2, "Programming in Emacs," describes how to use Emacs as a software development environment. Read Chapter 5 to get an overview of features that are common to all programming languages. Then read Chapter 6 (C), Chapter 7 (FORTRAN), Chapter 8 (Lisp), or Appendix A (Pascal) depending upon which programming language you are using. Chapters in this section include:

Chapter 5: Program Development in Emacs. This chapter describes features that are common to all Emacs programming language modes, such as moving around your program, indenting and commenting programs, using tag tables to edit across multiple files, keeping track of source-code changes with ChangeLogs, and compiling programs.

Chapter 6: Editing in C Mode. This chapter describes features that are particular to editing C programs, such as moving among and marking C functions, indenting and commenting C programs, working with sexps and lists, and customizing C indentation and commenting styles.

Chapter 7: Editing in FORTRAN Mode. This chapter describes features that are particular to editing FORTRAN programs, such as moving among and marking subprograms, indenting and commenting FORTRAN programs, labeling lines, using keyword abbreviations, working with sexps and lists, and customizing FORTRAN indentation and commenting styles.

Chapter 8: Editing in Lisp Modes. This chapter describes features that are particular to editing Lisp programs, such as moving among defuns, sexps, and lists, marking text, transposing sexps, killing sexps, indenting and commenting Lisp programs, evaluating Lisp code, and customizing Lisp indentation and commenting styles.

Part 3, "Additional Emacs Features," describes various supporting Emacs features such as the online help facility, electronic mail facility, file and buffer management facilities, and spelling checker. Scan these chapters for the features that interest you. Chapters in this section include:

Chapter 9: Getting Online Help. This chapter describes how to get online help for Emacs commands, functions, and variables, and how to run the Emacs online tutorial.

Chapter 10: Using Emacs for Electronic Mail. This chapter describes how to use the Emacs electronic mail facility, RMAIL, to read and send e-mail messages.

Chapter 11: Managing Files and Buffers. This chapter describes how to use the Dired facility to manage your files, and the Buffer-Menu facility to manage your buffers.

Chapter 12: Miscellaneous Emacs Features. This chapter summarizes the remaining features of Emacs, including the spelling checker, the auto-save feature, and the UNIX shell mode. Specialized modes for editing TeX, Troff and pictures are also discussed.

Part 4, "Customizing and Administering Emacs," describes how to customize, extend, install, configure, and maintain the Emacs environment. Chapters in this section include:

Chapter 13: Customizing the Emacs Environment. This chapter describes several ways to customize Emacs to suit your needs and preferences. You will learn how to edit the .emacs start-up file, use variables to change Emacs' behavior, and change command key bindings.

Chapter 14: Administering Emacs. This chapter provides UNIX system administrators with advice on installing and maintaining Emacs.

Finally, four appendices provide additional details on specialized Emacs topics:

Appendix A: Editing in Pascal Mode. This appendix describes how to use a non-standard Pascal mode for editing Pascal programs in Emacs.

Appendix B: Emacs-Lisp Programming. This provides a brief introduction to Emacs-Lisp programming. It is intended for experienced Lisp programmers who want to write Emacs-Lisp functions to modify or extend the Emacs environment.

Appendix C: Switching from vi to Emacs. This appendix helps vi users make the transition to Emacs by listing the Emacs equivalents for many common vi commands.

Appendix D: Emacs Command Reference. This appendix provides a comprehensive quick reference to Emacs commands, functions, and variables.

A Word About Versions

This book describes the features of version 18.57 of industry-standard GNU Emacs as provided by the Free Software Foundation. You may be using a different version-or even a different implementation-of Emacs than ours.

During the past several years, programmers have modified, customized, extended, ported, and adapted Emacs until many implementations exist today (gnumacs, GNU, Emacs, x11macs, gnuvo, and MicroEmacs, for example). Even if you are using version 18.57 of GNU Emacs, it's possible that someone has customized your Emacs to work differently than standard Emacs, has added specialized extensions, or has removed functionality that was deemed unnecessary. As a result, some of the commands we describe may be invoked by different key sequences on your systems or may work differently. If your system behaves differently than this book describes, you should consult your UNIX system administrator about modifications made to your system.

Versions of Emacs have also been developed that run on the MS-DOS operating system on PCs (for example, MG, MicroEmacs, and Freemacs), and on other specialized hardware and operating systems. These implementations of Emacs are not discussed in this book, but most attempt to emulate many of the features and commands of GNU Emacs.

Don't be discouraged by these possible differences. If you have a recent version of Emacs, it will probably behave in much the same way as we describe. And the online help system, if kept up-to-date, may clarify any differences you discover.

Key Naming Conventions

Finally, before using Emacs, you should understand the key naming conventions used in this book and in the Emacs online help system. Some of these may be confusing if you have never used Emacs; if so, periodically refer back to this section as you gain experience working through the first few chapters.

Table 1.1 describes the default operation of commonly used Emacs keys.


We would like to thank the many people who have contributed their time and talents to this project.

We are indebted to Alan Apt, our editor at Addison-Wesley, who had the foresight to recognize the need for such a book as this. And to our reviewers--Darryl Okahata, David Wolpert, Eddie Williamson, Jim Bigelow, Peter Salus, and Adil Lotia--we owe several of the book's features, and have them to thank for its accuracy and thoroughness. We would also like to thank the administrative and production staff at Addison-Wesley--Shirley McGuire and Peggy McMahon--for taking care of all the little and not so little details.

At Hewlett-Packard, we have Michael Kolesar, Marl Godfrey, and Bob Silvey to thank for including us in the first crop of Hewlett-Packard Press books.

Last and most, we appreciate the patience and support of our families over the course of this long and occasionally arduous project.



Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership