Skip to Main Content
Learning GNU Emacs, 3rd Edition
book

Learning GNU Emacs, 3rd Edition

by Debra Cameron, James Elliott, Marc Loy, Eric S. Raymond, Bill Rosenblatt
December 2004
Beginner to intermediate content levelBeginner to intermediate
536 pages
19h 28m
English
O'Reilly Media, Inc.
Content preview from Learning GNU Emacs, 3rd Edition

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

F3 or C-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.

M-a

Move to the beginning of the sentence.[3]

C-Space

Set the mark.

M-e

Move to the end of the sentence.

M-w

Copy the sentence to the kill ring.

C-x b emacsrefs Enter

Move to a buffer called emacsrefs.

C-y

Insert the sentence.

Enter

Start the next sentence on a new line.

C-x b Enter

Move back to the original buffer.

F4 or C-x )

End the macro definition; Def is removed from the mode line.

[3] M-a's definition of a "sentence" is controlled by the variable sentence-end, which is a fairly complex regular expression. By default, a sentence ends with a period, question mark, or exclamation ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning the vi and Vim Editors, 7th Edition

Learning the vi and Vim Editors, 7th Edition

Arnold Robbins, Elbert Hannah, Linda Lamb
Mastering Vim

Mastering Vim

Ruslan Osipov
Modern Vim

Modern Vim

Drew Neil

Publisher Resources

ISBN: 0596006489Supplemental ContentErrata Page