(This page has no text content)
(This page has no text content)
Other Resources from O’Reilly Related titles Unix in a Nutshell Learning the vi Editor GNU Emacs Pocket Reference sed and awk Essential CVS Version Control with Subversion oreilly.com oreilly.com is more than a complete catalog of O’Reilly books. You’ll also find links to news, events, articles, weblogs, sample chapters, and code examples. oreillynet.com is the essential portal for developers interested in open and emerging technologies, including new platforms, pro- gramming languages, and operating systems. Conferences O’Reilly brings diverse innovators together to nurture the ideas that spark revolutionary industries. We specialize in document- ing the latest tools and systems, translating the innovator’s knowledge into useful skills for those in the trenches. Visit con- ferences.oreilly.com for our upcoming events. Safari Bookshelf (safari.oreilly.com) is the premier online refer- ence library for programmers and IT professionals. Conduct searches across more than 1,000 books. Subscribers can zero in on answers to time-critical questions in a matter of seconds. Read the books on your Bookshelf from cover to cover or sim- ply flip to the page you need. Try it today with a free trial.
Learning GNU Emacs THIRD EDITION Debra Cameron, James Elliott, Marc Loy, Eric Raymond, and Bill Rosenblatt Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo
Learning GNU Emacs, Third Edition by Debra Cameron, James Elliott, Marc Loy, Eric Raymond, and Bill Rosenblatt Copyright © 2005 O’Reilly Media, Inc. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (safari.oreilly.com). For more information, contact our corporate/insti- tutional sales department: (800) 998-9938 or corporate@oreilly.com. Editors: Debra Cameron and Mike Loukides Production Editor: Jamie Peppard Cover Designer: Edie Freedman Interior Designer: Melanie Wang Printing History: October 1991: First Edition. April 1992: Minor corrections. September 1996: Second Edition. December 2004: Third Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Learning GNU Emacs, the image of the gnu, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. This book uses RepKover™, a durable and flexible lay-flat binding. ISBN: 0-596-00648-9 ISBN13: 978-0-596-00648-8 [M] [1/08]
v Table of Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix 1. Emacs Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Introducing Emacs! 1 Understanding Files and Buffers 3 A Word About Modes 3 Starting Emacs 5 About the Emacs Display 6 Emacs Commands 10 Opening a File 11 Saving Files 15 Leaving Emacs 15 Getting Help 16 Summary 18 2. Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Moving the Cursor 22 Deleting Text 27 Marking Text to Delete, Move, or Copy 32 Emacs and the Clipboard 37 Editing Tricks and Shortcuts 39 Canceling Commands and Undoing Changes 41 Making Emacs Work the Way You Want 45 3. Search and Replace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Different Kinds of Searches 49 Search and Replace 55
vi | Table of Contents Checking Spelling Using Ispell 64 Word Abbreviations 74 4. Using Buffers, Windows, and Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Understanding Buffers, Windows, and Frames 82 Working with Multiple Buffers 85 Working with Windows 88 Working with Frames 93 More About Buffers 95 More About Windows 102 Holding Your Place with Bookmarks 106 5. Emacs as a Work Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Executing Commands in Shell Buffers 114 Using Dired, the Directory Editor 123 Printing from Emacs 140 Reading Manpages in Emacs 141 Using Time Management Tools 141 6. Writing Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Defining a Macro 151 Tips for Creating Good Macros 154 A More Complicated Macro Example 155 Editing a Macro 157 The Macro Ring 160 Binding Your Macro to a Key 160 Naming, Saving, and Executing Your Macros 161 Building More Complicated Macros 161 Executing Macros on a Region 167 Beyond Macros 168 7. Simple Text Formatting and Specialized Editing . . . . . . . . . . . . . . . . . . . . . . 170 Using Tabs 170 Indenting Text 176 Centering Text 186 Using Outline Mode 187 Rectangle Editing 194 Making Simple Drawings 204
Table of Contents | vii 8. Markup Language Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 Comments 219 Font-Lock Mode 220 Writing HTML 220 Writing XML 243 Marking up Text for TEX and LATEX 258 9. Computer Language Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 Emacs as an IDE 264 Writing Code 266 C and C++ Support 275 Java Support 284 The Java Development Environment for Emacs (JDEE) 285 Perl Support 294 SQL Support 296 The Lisp Modes 298 10. Customizing Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 Using Custom 307 Modifying the .emacs File Directly 326 Modifying Fonts and Colors 330 Customizing Your Key Bindings 335 Setting Emacs Variables 339 Finding Emacs Lisp Packages 340 Starting Modes via Auto-Mode Customization 341 Making Emacs Work the Way You Think It Should 342 11. Emacs Lisp Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 Introduction to Lisp 345 Lisp Primitive Functions 353 Useful Built-in Emacs Functions 358 Building an Automatic Template System 374 Programming a Major Mode 381 Customizing Existing Modes 389 Building Your Own Lisp Library 395 12. Version Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398 The Uses of Version Control 398 Version Control Concepts 399
viii | Table of Contents How VC Helps with Basic Operations 401 Editing Comment Buffers 403 VC Command Summary 403 VC Mode Indicators 404 Which Version Control System? 405 Individual VC Commands 405 Customizing VC 411 Extending VC 412 What VC Is Not 413 Using VC Effectively 413 Comparing with Ediff 414 13. Platform-Specific Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421 Emacs and Unix 421 Emacs and Mac OS X 427 Emacs and Windows 433 14. The Help System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440 Using the Tutorial 440 Help Commands 441 Help with Complex Emacs Commands 445 Navigating Emacs Documentation 446 Completion 453 A. Emacs Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457 B. Emacs Lisp Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464 C. Bugs and Bug Fixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470 D. Online Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472 E. Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
This is the Title of the Book, eMatter Edition Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved. ix Preface 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 envi- ronment. 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 sys- tems like X and Microsoft Windows became popular, Emacs often served as a com- plete 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 will- ing 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 administra- tors. 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
This is the Title of the Book, eMatter Edition Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved. x | Preface • 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 com- mon misspellings Of course, many of the topics may not apply to you; some topics may be appropri- ate 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.* 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 specifi- cally 21.3.5.† This new edition has been completely revised and expanded to cover new features and to meet the evolving needs of Emacs users. * Quite a few issues come up in discussions of GNU Emacs versus XEmacs, with character encoding schemes, user interface differences, and copyright issues among them. We’re not interested in taking sides in the bat- tles between these emacsen. † Typically we would not find the need to be quite so specific, but the user interface changed at Emacs 21.3.5; in particular you’ll notice different toolbar icons if you have an earlier version.
This is the Title of the Book, eMatter Edition Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved. Preface | xi Here are some of the highlights of what we’ve changed: • User interface changes, including the addition of an icon-based toolbar, exten- sive 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 interest- ing 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
This is the Title of the Book, eMatter Edition Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved. xii | Preface favorite ice cream store. Much has happened since 1975. TECO has slipped into deserved obscurity, and Emacs has been rewritten as an independent program. Sev- eral commercial versions of Emacs appeared, of which Unipress Emacs and CCA Emacs were the most important. For several years, these commercial implementa- tions were the Emacs editors you were most likely to run across outside of the aca- demic world. Stallman’s Emacs became prominent with the birth of the Free Software Founda- tion (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 associ- ates 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 restric- tions 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 underestimated. GNU software and open source soft- ware 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 unfor- tunately 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 disap- pears 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 con- science 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 soft- ware 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.* * FSF programs such as Emacs are often distributed with commercial systems. Even in these cases, the General Public License guarantees your right to use and give away their programs without restriction. Of course, the license does not apply to other proprietary software with which GNU tools have been shipped.
This is the Title of the Book, eMatter Edition Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved. Preface | xiii Since GNU Emacs was first released, many other pieces of the GNU operating envi- ronment have fallen into place: C and C++ compilers (gcc and g++), a very powerful debugger (gdb), substitutes for lex and yacc (called flex and bison, respectively), a Unix shell (bash, which stands for “Bourne-Again Shell”), the Gimp (a graphics tool comparable to Adobe PhotoShop), GNOME (a desktop environment for Linux), and many other programs and libraries. Many important open source projects that origi- nally used variants of the GPL or other licensing schemes have adopted the GPL as their license, including Python, Mozilla, and Zope. Author David Wheeler argues that all open source projects should release their software under a GPL-compatible license* (see http://www.dwheeler.com/essays/gpl-compatible.html for his views and some statistics about GPL’d software). With Linux, GNU tools, and other GPL’d software, it’s possible to have a complete operating environment consistent with the values set forth by the FSF. An Approach to Learning Emacs This book is designed to get you started with Emacs as quickly as possible, whether you are an experienced computer user or a novice. The first two chapters give you the basics you need to know, and the rest of the book builds on these basics. After the first two chapters, you don’t have to read the rest consecutively; you can skip to the topics that interest you. Additionally, the book is designed to give you just the level of hand-holding you want; you can either read the book in detail or skim it, looking for tables of commands and examples. Here are some reading paths you could take: These reading paths are offered only as a guideline. Emacs is one gigantic, function- ally rich editor. We’ve divided it up into digestible bites for you, so you don’t have to * GPL-compatible is a critical distinction for many organizations. As our reviewer Mike Trent points out, many organizations release their software under a modified GPL because the GPL’s license is actually “viral.” That is, if one line of GPL’d code appears in a project, the entire project must be GPL’d. This means corporations interested in protecting their assets but still wanting to share code with the open source community cannot use the GPL without some modification. If Read You are a casual user Preface, Chapters 1–3, 14 You are a programmer or system administrator Preface, Chapters 1–5, 9–12 You are a writer or production person Preface, Chapters 1–3, 7, 8, 14 You want to customize Emacs Chapter 10 and possibly Chapter 11 You write HTML or XML Preface, Chapters 1–3, 8 You want to use operating system commands in Emacs Chapter 5 You use Emacs on Windows or Mac OS X Chapter 13
This is the Title of the Book, eMatter Edition Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved. xiv | Preface be put off by its size and scope. The best way to learn Emacs is incrementally; learn a little now, then learn more features as you get curious about them. If you need to do something and don’t know how to do it in Emacs, Emacs probably already does it; if it doesn’t, you can learn how to write a Lisp function to add it to Emacs (see Chapter 11 for details). The online help system is an excellent place to learn about new features on the fly; online help is discussed in Chapter 1 and in more detail in Chapter 14. Here’s a list of some features you might want to learn about on a rainy day: • How to use multiple Emacs buffers, windows, and frames (Chapter 4) • Word abbreviation mode (Chapter 3) • Macros (Chapter 6) • How to map function keys to Emacs commands (Chapter 10) • How to issue (and edit) shell commands (Chapter 5) • How to organize files in Emacs (Chapter 5) • Using ediff to compare files (Chapter 12) Here’s a quick summary of what’s in each chapter: Chapter 1, Emacs Basics, tells you how to start Emacs and how to work with files. It also provides a quick introduction to the online help system. Chapter 2, Editing, explains commands for moving around, copying and pasting text, and undoing changes. It also introduces very basic customization. Chapter 3, Search and Replace, covers more editing features, including search and replace, word abbreviation mode, and spell checking. Chapter 4, Using Buffers, Windows, and Frames, describes how to use multiple buff- ers and windows, both Emacs-style windows (that divide a single OS window) and traditional OS windows (which Emacs refers to as frames). It also discusses how to bookmark your place in large files. Chapter 5, Emacs as a Work Environment, talks about issuing commands from within Emacs, working with files and directories, and using basic time management tools such as the calendar and diary. Chapter 6, Writing Macros, discusses using macros to eliminate repetitive tasks. Chapter 7, Simple Text Formatting and Specialized Editing, covers basic text format- ting (such as tabs, indentation, and centering) as well as some of the more rarefied features, like outline mode and rectangle editing. Chapter 8, Markup Language Support, describes Emacs support for HTML, XML, TEX, and LATEX..
This is the Title of the Book, eMatter Edition Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved. Preface | xv Chapter 9, Computer Language Support, covers Emacs as a programming environ- ment, including editing support for C, Java, Lisp, Perl, and SQL, as well as the inter- face to compilers and the Unix make utility. It also describes the Java Development Environment for Emacs (JDEE). Chapter 10, Customizing Emacs, describes Emacs’s customization facilities. The interactive Custom tool allows you to change variables without editing your star- tup file. The chapter also explains how to set up your .emacs customization file. It describes how to modify your display, keyboard commands, and editing environ- ment as well as how to load Lisp packages for extra functionality. Chapter 11, Emacs Lisp Programming, describes the basics of Emacs Lisp, the lan- guage you can use to further customize Emacs. Chapter 12, Version Control, describes VC mode for version control and its interface to CVS, RCS, Subversion, and SCCS. Chapter 13, Platform-Specific Considerations, discusses how to install Emacs on Unix, Windows, and Mac OS X. It also provides platform-specific information for Windows and Mac OS X. Chapter 14, The Help System, describes Emacs’s rich, comprehensive online help facilities. Appendix A, Emacs Variables, lists many important Emacs variables, including all the variables mentioned in this book. Appendix B, Emacs Lisp Packages, lists some of the most useful Lisp packages that come with Emacs. Appendix C, Bugs and Bug Fixes, tells you how (and when) to report bugs you find in Emacs. It also describes how to contribute to the GNU Project, whether through code enhancements or monetarily. Appendix D, Online Resources, gives a tour of some important Emacs-related web sites. Appendix E, Quick Reference, provides brief descriptions of the most important Emacs commands discussed in this book. The book concludes with a glossary that defines Emacs terms you’ll encounter, an index, and a detachable quick reference card that summarizes important commands for easy access.
This is the Title of the Book, eMatter Edition Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved. xvi | Preface What We Haven’t Included GNU Emacs is a large and powerful editor; in this book, we give you only a sample of what it does. Many features have been left out, and more features are added all the time. Some topics, however, are not covered: Compatibility modes GNU Emacs provides compatibility modes for vi, for example. We’ve left a dis- cussion of these modes out. If you really want to use vi or another editor, do so. You’re better off getting to know Emacs on its own terms rather than pretend- ing it is something else. Many programming language modes In this book, we discuss editing modes for C++, Java, Lisp, Perl, and SQL. There are many modes for other languages, including rare languages like Scheme. There’s no way we could discuss everything. Advanced Lisp programming GNU Emacs incorporates a complete Lisp interpreter. We give a very basic and brief introduction to Emacs Lisp; Chapter 11 should be enough to get you started, but it really only scratches the surface. We recommend the FSF’s Emacs Lisp Reference Manual, now included in the Emacs distribution. Using Emacs to access the Internet When our last edition came out, it was common to use Emacs to access Internet resources or read email. Now that isn’t so common; better mailers, browsers, and other tools are commonly in use on all platforms. Unicode support At present, Emacs is on its way to full Unicode support; that is the most impor- tant change slated for the next major release. At this writing, Unicode support is spotty. Games and amusements GNU Emacs includes an eclectic bunch of games and amusements, including the ability to pipe random quotations from Zippy the Pinhead into the famous “Eliza” pseudopsychoanalyst. Emacs 21 includes a Games menu under Tools with several cool ways to waste time in Emacs (and it doesn’t even include Emacs’s version of pong, one of our favorites). Alas, we had to draw the line somewhere. The Meta Key Emacs commands consist of a modifier, such as Control, which you hold down as you would the Shift key, and a series of keystrokes. For example, Control-x Control-s saves a file.
This is the Title of the Book, eMatter Edition Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved. Preface | xvii The other modifier Emacs uses is the Meta key. Few keyboards have keys labeled Meta. Because of this, in previous editions of this book, we refused to talk about the Meta key and substituted Esc in all our instructions. In this edition, we want you to learn where the Meta key is. Typically Meta keys are to the immediate left and right of the Space bar. On Linux and Windows keyboards, the Alt key is the Meta key. On Mac keyboards, the Apple key, often called Com- mand is the Meta key by default. Why learn about and use the Meta key? The reason is speed. We emphasize key bindings in this book. New users may find icons and menus helpful, but in the long run, learning how to keep your hands on the keyboard allows you to gain speed and boosts your productivity. The Meta key will help you gain that speed and make it easy for you to use Emacs help, which refers to Meta. Depending on your style, you may still prefer to use Esc instead of Meta. Just bear in mind that with Esc you press and release the key, then press the next key. Conventions Used in This Book This section covers the conventions used in this book. Keystroke Notation Emacs commands consist of a modifier, such as Ctrl or Meta, followed by one or two characters. Commands shown in this book abbreviate Ctrl to C and Meta to M: C-g Hold down the Ctrl key and press g. M-x Hold down the Meta key and press x. Sometimes Meta is followed by a literal hyphen character. In these cases, we spell out Meta: Meta - Hold down the Meta key and press -. To complete a command you may need to press Enter. (This key may be labeled Return.) Enter Press the Enter key. Esc Can be used as an alternative to Meta. Press Esc, release it, then press the next key.
This is the Title of the Book, eMatter Edition Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved. xviii | Preface A few mouse commands use the Shift key as a modifier, often in combination with the Ctrl key. This is abbreviated as: S-right Hold down Shift and click the right mouse button. C-S-right Hold down Shift and Ctrl and click the right mouse button. All Emacs commands, even the simplest ones, have a full name; for example, forward- word is equivalent to the keystrokes M-f, and forward-char is equivalent to C-f. This tying of a command to a keystroke combination is called a key binding. Some com- mands have only full names, with no corresponding key binding. When we discuss a command, we’ll give both its full name and the keystrokes (if any) that you can type to invoke it. Command Tables To find a group of commands quickly, look for tables in each section that summa- rize commands. These tables are formatted like this: The first column shows the default key binding for the command, the second col- umn shows the command’s full name, and the third column describes what the command does. For example, pressing C-n (also known as the next-line com- mand) moves the cursor to the next line in the file. Some commands, like C-x C-f, can also be reached through menus. If there is a menu option for a particular com- mand, it is given in italics below the keystrokes for the command. For example, you can use the find-file command by typing C-x C-f or by selecting Open File from the File menu. Sometimes you’ll see (none) in the keystrokes column, which doesn’t mean you can’t use the command, but rather that the command isn’t bound to particular keystrokes. To use commands with no keystrokes, type M-x, followed by the command’s full name, and press Enter. (Try typing M-x pong Enter sometime.) Keystrokes Command name Action C-n next-line Move to the next line. C-x C-f File ➝ Open File find-file Open a specified file. (none) yow Print ineffable wisdom from the Pinhead in the minibuffer.
Comments 0
Loading comments...
Reply to Comment
Edit Comment