GNU Emacs is the most popular and widespread of the Emacs family of editors. It is also the most powerful and flexible. Unlike all other text editors, GNU Emacs is a complete working environment—you can stay within Emacs all day without leaving.

, 3rd Edition tells readers how to get started with the GNU Emacs editor. It is a thorough guide that will also "grow" with you: as you become more proficient, this book will help you learn how to use Emacs more effectively. It takes you from basic Emacs usage (simple text editing) to moderately complicated customization and programming.The third edition of

describes Emacs 21.3 from the ground up, including new user interface features such as an icon-based toolbar and an interactive interface to Emacs customization. A new chapter details how to install and run Emacs on Mac OS X, Windows, and Linux, including tips for using Emacs effectively on those platforms.

, third edition, covers:

Learning GNU Emacs

Learning GNU Emacs

Learning GNU Emacs

• How to edit files with Emacs

• Using the operating system shell through Emacs

• How to use multiple buffers, windows, and frames

• Customizing Emacs interactively and through startup files

• Writing macros to circumvent repetitious tasks

• Emacs as a programming environment for Java, C++, and Perl, among others

• Using Emacs as an integrated development environment (IDE)

• Integrating Emacs with CVS, Subversion and other change control systems for projects with multiple developers

• Writing HTML, XHTML, and XML with Emacs

• The basics of Emacs Lisp

The book is aimed at new Emacs users, whether or not they are programmers. Also useful for readers switching from other Emacs implementations to GNU Emacs.

6.4 Editing a Macro

6.4 Editing a Macro

You can edit a macro and make changes to it in a few different ways. For this example, we chose an all-purpose editing command, edit-kbd-macro, which is bound to C-x C-k e. Several macro editing commands are available, but this one works for all types of macros, so it's good to learn.

Our macro could use a bit of tweaking. First of all, finding references to Emacs in our copy of the Emacs NEWS file is pretty lame. Perhaps we're interested in using a mouse more frequently with Emacs and would like to know about changes to that part of the interface. We'll edit the macro to search for the word mouse. We'll also modify it so it marks a paragraph rather than a sentence since a sentence doesn't really provide enough context to be helpful.

Let's start editing the macro.

Type: C-x C-k e

Emacs prompts you for the type of macro to edit.

Emacs asks you if you want to edit the last keyboard macro (C-x e), a named macro (M-x), the last 100 keystrokes as a macro, termed "lossage" (C-h l), or keys (meaning the keystrokes you bound a macro to). Yes, that's a lot of choices, and later in the chapter we describe named macros and binding macros to keys (you can experiment on your own with creating a macro from lossage). For now, just choose C-x e to edit the last keyboard macro.

Type: C-x e

Emacs opens an *Edit Macro* buffer.

Notice two fields near the top of this buffer, Command: and Key:. Right now, Command: says last-kbd-macro. If this were a named macro, the command would be the name you gave your macro. Additionally, for frequent use, you can bind your macro to a key, at which point the Key: field lists the keystrokes to execute this macro. Right now it says none because we haven't defined any keystrokes yet.

Note that Emacs inserts comments all through the macro. It's attempting to map keystrokes to commands. You do not need to update these comments or add comments if you add commands to your macro; Emacs does that itself.

To tweak our macro, we change the search string on the second line from emacs to mouse. Note that we can just press C-k to wipe out the line and type mouse. Now change M-a to M-{ and M-e to M-}. We change the buffer name from emacsrefs to mouseinfo.

We've made the edits from the previous paragraph. The screen looks like this:

A modified macro that captures information about using a mouse in Emacs.

To exit the macro editing buffer, we have to type C-c C-c and go back to our NEWS buffer. Let's do that and then execute the macro again to see what happens.