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.3 A More Complicated Macro Example

6.3 A More Complicated Macro Example

Sometimes you may want to find all the references to a particular topic in a file. Table 6-2 lists steps for creating a macro that takes takes every sentence in the buffer that contains the word Emacs and copies it to another buffer. If you try this macro, you'll need to type some text about Emacs into a buffer. You can also get a test file to work with by opening the Emacs NEWS file (using C-h n), then writing it to a file (C-x C-w NEWS). This buffer is in view mode by default; change to text mode by typing M-x text-mode Enter.

Table 6-2. Steps for macro that creates a buffer of Emacs references

Keystrokes

Action

F3orC-x (

Start macro definition; Def appears on the mode line.

C-s emacs

Find the word Emacs.

Enter

Stop the search after it is successful; if the search is unsuccessful, it rings the bell and stops the macro.

Now, assume that you've already constructed the macro outlined in Table 6-2 and that you can invoke it with F4. The following screen shows what happens when you run it five times and then display the emacsrefs buffer.

Type: M-5 F4 or M-5 C-x e, followed by C-x b Enter

By executing the macro repeatedly, we've created a buffer that contains references to the Emacs editor.

As in the previous example, you can jump back and forth between an unlimited number of buffers while defining a macro. Macros don't need to be confined to one buffer. Macros that work with several buffers are more difficult to debug; when several buffers are involved, it becomes harder for you to keep track of where the cursor and the mark are. It is also easy to make mistaken assumptions about what buffer you're visiting; hence, it's a good idea to specify the buffer name explicitly. However, after you get accustomed to working with macros and multiple buffers, you'll be amazed at how much work you can do with almost no effort.

Windows are sometimes useful in macros, but, again, you have to watch out. It's better to start a macro with one window on the screen, have the macro open other windows, and finally close all but one window (C-x 1). If you write a macro with two windows on the screen and later try to execute it with four windows on the screen, the results will be unpredictable at best! In general, moving to a named buffer, C-x bbuffername, is preferable to moving to the "other" window using C-x o (too vague to be generally useful). The other window could be anything—a *Help* buffer, *Completion* buffer, *shell* buffer, and so on. Moving to a named buffer always gets you to the right place, no matter how (or whether) the buffer is displayed.