Harley Hahn

Harley Hahn’s Emacs Field Guide

Harley Hahn

Santa Barbara, California, USA

Any source code or other supplementary materials referenced by the author in this text are available to readers at www.apress.com/9781484217023 . For detailed information about how to locate your book’s source code, go to www.apress.com/source-code/ . Readers can also access source code at SpringerLink in the Supplementary Material section for each chapter.

ISBN 978-1-4842-1702-3

e-ISBN 978-1-4842-1703-0

DOI 10.1007/978-1-4842-1703-0

Library of Congress Control Number: 2016938804

© Harley Hahn 2016

Harley Hahn’s Emacs Field Guide

www.harley.com

The name “Harley Hahn” the Harley Hahn stylized signature, and the Harley Hahn Unisphere logo are registered trademarks of Harley Hahn.

Managing Director: Welmoed Spahr

Lead Editor: Jeffrey Pepper

Technical Reviewer: Dmitry Shkatov

Copyeditor: Lydia Hearn

Editorial Board: Steve Anglin, Pramila Balan, Louise Corrigan, Jonathan Gennick, Robert Hutchinson, Celestin Suresh John, Michelle Lowman, James Markham, Susan McDermott, Matthew Moodie, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Gwenan Spearing

Coordinating Editor: Mark Powers

Compositor: SPi Global

Indexer: SPi Global

Artist: SPi Global

For information on translations, please e-mail [email protected] , or visit www.apress.com .

Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales .

Material from this book was published with McGraw-Hill in a chapter on Emacs. This book extends that content into a complete book. We have an email from the McGraw-Hill permissions department saying that the rights were reverted long ago and that will be attached to the contract.

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

Printed on acid-free paper

Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

To Maria, for love and support.

And to Sadie (my dog) and Max (Maria’s dog), for being such good company.

A Personal Note from Harley Hahn

You are floating down a narrow, winding river. Much of the time you move slowly, drifting with the current. You have been drifting a long time. Although the current is steady, the water is warm and comfortable, and you don’t even notice it anymore. It just is. Warm, comfortable, predictable.

You are floating peacefully. Still, every now and then, you find yourself wondering: Is something missing? Am I bored? Is that all there is?

One day, you notice that the river is about to bifurcate into two different streams, and you need to make a choice. Which way do you want to go? You look carefully, squinting your eyes against the bright sun, trying to notice the details you are used to taking for granted.

Straight ahead, the water is calm. Do nothing, and you will keep drifting, safely and predictably. And why not? After all, your journey is far from over, and everything seems to be working out just fine. Part of you wants nothing more than to lay back and relax.

To the left, however, the water looks unusual. The current is faster and, in the distance, you see some rapids, although nothing you can’t handle. A memory comes back: Years ago, you used to love the rapids, bouncing up and down for a short time, then resting to catch your breath. You were living in the moment, over and over and over, just being. How long has it been since you had that feeling of really being alive? You can’t remember.

You close your eyes and imagine the map of the river, the map you thought you had memorized. However, you can’t recall a place where one river turns into two. You open your eyes, feeling puzzled, and you see that, soon, you must make a decision.

Here is a promise. If you decide to turn and travel down the unknown branch of the river away from the current, you will find me there, waiting for you, and we will explore together. In fact, I have a map that we will share. There is a lot ahead of us, and I can tell you now that what is just around the bend will take effort. However, I can also tell you it will change your life.

What to do? Should you push against the current and explore the unknown, unexpected branch of the river? Or should you keep drifting in a slow, safe, predictable direction? Even doing nothing is a decision.

My advice? Go to Chapter 1 of this book and read the first three sections.

Then make your choice.

A385558_1_En_BookFrontmatter_Figb_HTML.jpg

Acknowledgments

Writing a book requires me to spend many, many hours at home for months at a time, researching, composing and rewriting, alone at my desk, with only my dog Sadie to keep me company. (Sadie is a three-year-old border collie, who doesn’t understand why we don’t spend every day running around outside.) Publishing a book, however, is a team effort, so if you have a moment, I’d like to introduce you to my team.

Let’s start with Lydia Hearn. Lydia and I have worked on books together for a long time, and I have found her to be a truly remarkable person. She is a tenured professor at De Anza College in Cupertino, California, where she teaches English. For this book, Lydia was my copy editor, which means that it was her job to find and correct any writing mistakes I might have made. This is harder than you might imagine, because writers think so fast that their fingers can’t keep up with their thoughts, which means it is easy to make mistakes, many of which are subtle and hard to find. That is why I need Lydia, a tireless perfectionist (actually, a tired perfectionist) with boundless enthusiasm and enormous skill. Moreover, Lydia is the only person in the world that I will, voluntarily, let make changes to what I write.

Next comes Jeff Pepper, the lead editor for this book. Jeff and I started publishing books together a long, long time ago, and it is through his efforts that I have been able to create many of my most successful, high-quality books. Whenever I start a new project with Jeff, I know that he will be there with lots of advice, experience, and a good-natured approach that comes from dealing with authors and publishing people all day long, for many years. In addition, for this particular book, Jeff put in many hours—often late at night and under pressure — processing the files I would send him to ensure that everything was done just right.

The other editor on our team is Mark Powers, who served as managing editor for this book. This means that Mark handled a lot of details, including a schedule that seemed to have a life of its own. Mark has a background, not only in book publishing, but in writing graphic novels and comic books, which makes him uniquely qualified to work with the more esoteric parts of this book.

Then there is Dmitry Shkatov, a very special person whose job it was to help me look for technical mistakes. Dmitry teaches computer science at the University of the Witwatersrand in Johannesburg, South Africa. In fact, if it weren’t for Dmitry, this book would never have been written. Here is how it happened.

On July 20, 2015, Dmitry wrote me the following letter:

Dear Harley,

I was wondering whether it would be possible to somehow get access to the chapter on Emacs from the 2nd edition of your “Student Guide to Unix”, which was sadly left out of the 3rd edition.

It’s the best introduction to Emacs I have ever seen (and that’s how I came to love Emacs), and now that I’m teaching computer science to South African undergraduates, I’d like to be able to share it with my students.

Your assistance would be highly appreciated not only by me, but I am sure, by my students as well.

Not long afterwards, Jeff Pepper contacted me about writing a new book. I showed him Dmitry’s letter, and we agreed that it would be a good idea for me to write a book focusing only on Emacs. We asked Dmitry if he would be the technical editor for the book, and he said yes. This was a stroke of luck for me, because you would have to search long and hard to find someone as smart as Dmitry, who has as much experience with Emacs. Dmitry not only read everything I wrote, making important suggestions, he also took the time to discuss all manner of Emacs-related ideas, which helped me enormously.

Speaking of help, I thank Ron Lockwood-Childs and Stephanie Lockwood-Childs, highly accomplished engineers and programmers, who helped me with advice on how to set up a Linux system to run on a virtual machine, specifically for testing Emacs. In addition, I thank Jebi Koilpillai, for helping me understand and test the technical issues involved in installing Emacs under Mac OS X.

As a writer, I always hope for production people who share my desire to create the best possible book. As such, I wish to thank several hard-working, skillful employees of SPi Global, an international business service provider. These three people are Mercy Thomas (account manager), Dulcy Nirmala Chellappa (project manager), Parameswari Balasubramaniyan (page layout artist), and Samuel Devanand (production editor). Without the time-consuming, detailed work of people like Mercy, Dulcy, Parameswari, and Samuel, it would not be possible to produce high-quality books like this one. I am lucky to have had their help.

For the final acknowledgments, I call upon the wisdom of the ancient Roman poet Juvenal who once observed, if you are going to spend hours a day for months at a time writing an Emacs book, you had better make sure that you get a lot of high-quality exercise, or you are going to have a lot of trouble. (Actually, the way he put it was Mens sana in corpore sano , which means “A healthy mind in a healthy body”.)

With this in mind, I thank Sandrine Rocher-Krul, my cardioboxing teacher, for helping me to stay fit, alert, and healthy. I have taken a lot of classes in my life — as a child, as an undergraduate, in grad school, and in medical school — and without a doubt, Sandrine is the best teacher I have ever had. She has a rare confluence of motivation, skill, and creativity, which she demonstrates daily. For the same reason, I am grateful to the other students with whom I have been taking cardioboxing for so long. In particular, I thank Miguel Trujillo and Abe Solis for their continued encouragement and their help.

Contents

  1. Chapter 1:​ All About Emacs
    1. Section 1.​1:​ Getting Started Together
    2. Section 1.​2:​ Emacs Is a Text Editor
    3. Section 1.​3:​ Emacs Is a Working Environment
    4. Section:​ 1.​4:​ Where Did Emacs Come From?​
    5. Section 1.​5:​ The Free Software Foundation
    6. Section 1.6: Excerpts From The Gnu Manifesto
  2. Chapter 2:​ Unix for Emacs Users
    1. Section 2.​1:​ Operating Systems
    2. Section 2.​2:​ Unix and Linux
    3. Section 2.​3:​ Unix Terminals and Userids
    4. Section 2.​4:​ Types of Terminals
    5. Section 2.​5:​ User Interfaces
    6. Section 2.​6:​ Using a Unix Terminal
    7. Section 2.​7:​ The Unix Command Line
    8. Section 2.​8:​ The Shell Prompt
    9. Section 2.​9:​ What Unix Commands Look Like
    10. Section 2.​10:​ Making Corrections as You Type Commands
    11. Section 2.​11:​ Two Important Keys:​ <Ctrl-C> and <Ctrl-D>
    12. Section 2.​12:​ The History List; Command Line Editing
    13. Section 2.​13:​ The Unix Manual
    14. Section 2.14: Using the less Pager Program
    15. Section 2.​15:​ The Three Types of Unix Files
    16. Section 2.​16:​ The Tree-Structured Filesystem
    17. Section 2.​17:​ The Current Directory and Pathnames
    18. Section 2.​18:​ File and Directory Names
    19. Section 2.​19:​ File and Directory Names:​ OS X and Windows
  3. Chapter 3:​ Installing Emacs
    1. Section 3.​1:​ Installing Software:​ Packages vs.​ Manual Installation
    2. Section 3.​2:​ Installing Emacs Using a Linux Package Manager
    3. Section 3.​3:​ Installing Emacs Manually With Linux
    4. Section 3.​4:​ Installing Emacs With OS X
    5. Section 3.​5:​ Installing Emacs With Microsoft Windows
  4. Chapter 4:​ The Emacs Keyboard
    1. Section 4.​1:​ A Strategy for Learning Emacs
    2. Section 4.​2:​ The Ctrl Key
    3. Section 4.​3:​ The Meta (Alt) Key
    4. Section 4.​4:​ Special Key Names
    5. Section 4.​5:​ The Meta Key, Bucky Bits, and Much More
    6. Section 4.​6:​ Meta Key Problems When Using a Terminal Window
  5. Chapter 5:​ Starting and Stopping Emacs
    1. Section 5.​1:​ Starting Emacs
    2. Section 5.​2:​ Starting Emacs in a Terminal Window
    3. Section 5.​3:​ Starting Emacs as a Read-Only Editor
    4. Section 5.​4:​ Recovering Data After a System Failure
    5. Section 5.​5:​ Stopping Emacs
  6. Chapter 6:​ Commands, Buffers, Windows
    1. Section 6.​1:​ Commands and Key Bindings
    2. Section 6.​2:​ Buffers
    3. Section 6.​3:​ Windows
    4. Section 6.​4:​ The Mode Line /​ Read-Only Viewing
    5. Section 6.​5:​ The Echo Area /​ Typing Emacs Commands
    6. Section 6.​6:​ The Minibuffer
    7. Section 6.​7:​ Completion
    8. Section 6.​8:​ Disabled Commands
  7. Chapter 7:​ The Text Editing Work Environment
    1. Section 7.​1:​ How to Practice Using Emacs
    2. Section 7.​2:​ Typing and Correcting
    3. Section 7.3: The repeat and undo Commands; Redo
    4. Section 7.4: The keyboard-quit Command ( C-g )
    5. Section 7.5: Emacs for vi Users
    6. Section 7.​6:​ Commands to Control Windows
    7. Section 7.​7:​ Commands to Control Buffers
    8. Section 7.​8:​ Commands for Working With Files
  8. Chapter 8:​ The Cursor; Line Numbers; Point and Mark; The Region
    1. Section 8.​1:​ The Cursor and the Idea of Point
    2. Section 8.​2:​ Moving the Cursor
    3. Section 8.​3:​ Text Modes; Paragraphs and Sentences
    4. Section 8.​4:​ Repeating a Command:​ Prefix Arguments
    5. Section:​ 8.​5:​ Moving Through the Buffer
    6. Section 8.​6:​ Using Line Numbers
    7. Section 8.​7:​ Mark, Point, and the Region
    8. Section 8.​8:​ Using Mark and Point to Define the Region
    9. Section 8.​9:​ Operating on the Region
  9. Chapter 9:​ Kill and Delete; Move and Copy; Correct Mistakes; Spelling; Fill
    1. Section 9.​1:​ Kill and Delete:​ Two Ways to Erase Text
    2. Section 9.​2:​ Commands to Delete Text
    3. Section 9.​3:​ Commands to Kill Text
    4. Section 9.​4:​ The Kill Ring and Yanking; Moving and Copying
    5. Section 9.​5:​ Correcting Common Typing Mistakes
    6. Section 9.​6:​ Correcting Spelling Mistakes
    7. Section 9.​7:​ Filling and Formatting Text
  10. Chapter 10:​ Searching
    1. Section 10.​1:​ Introducing the Emacs Search Commands
    2. Section 10.​2:​ Incremental Searching
    3. Section 10.​3:​ Keys to Use While Searching
    4. Section 10.​4:​ Upper- and Lowercase Searching
    5. Section 10.​5:​ Non-Incremental Searching
    6. Section 10.​6:​ Word Searching
    7. Section 10.​7:​ Searching for Regular Expressions
    8. Section 10.​8:​ Regular Expressions
    9. Section 10.​9:​ Fixing Emacs Key Conflicts
    10. Section 10.​10:​ Searching and Replacing
    11. Section 10.​11:​ Recursive Editing
  11. Chapter 11: Modes; Customizing Using Your .emacs File
    1. Section 11.​1:​ Introducing Modes
    2. Section 11.​2:​ Major Modes
    3. Section 11.​3:​ Lists of Major Modes
    4. Section 11.​4:​ Minor Modes
    5. Section 11.​5:​ Setting Major and Minor Modes
    6. Section 11.​6:​ Read-Only Mode
    7. Section 11.​7:​ Learning About Modes
    8. Section 11.8: Customizing With the .emacs File; Learning Lisp
    9. Section 11.9: Using Your .emacs File to Set Default Modes
  12. Chapter 12:​ Shell Commands; Help and Info; Programs and Games
    1. Section 12.​1:​ Entering Shell Commands
    2. Section 12.​2:​ Shell Buffers
    3. Section 12.​3:​ The Help Facility
    4. Section 12.​4:​ The Emacs Tutorial; Info and the Emacs Reference Manuals
    5. Section 12.​5:​ Built-In Programs
    6. Section 12.​6:​ Built-In Tools, Including Dired
    7. Section 12.​7:​ Games and Diversions
    8. Section 12.​8:​ Zippy the Pinhead Talks to the Emacs Psychotherapist
    9. Section 12.​9:​ A Personal Note From Harley Hahn
  13. Appendix A: Personal Notes
  14. #1: Teaching Yourself Emacs
  15. #2: Computer With a Keyboard
  16. #3: Usenet, Emacs, and the Growth of the Internet
  17. #4: Free/Open Source Software
  18. #5: GNU’s Not Unix?
  19. #6: Our Tools Shape Our Minds
  20. #7: AT&T
  21. #8: Early Unix on the West Coast
  22. #9: BSD Unix in the 1980s
  23. #10: Hackers and Geeks
  24. #11: Bash
  25. #12: Linux Is Free
  26. #13: Mac OS X Is Unix
  27. #14: Terminals That Print
  28. #15: Why U.C. San Diego in 1976?
  29. #16: 80- and 132-character Lines
  30. #17: Unix Workstations
  31. #18: Time Travel
  32. #19: Midnight Commander
  33. #20: KDE and Gnome
  34. #21: Aren’t All Terminals Virtual?
  35. #22: Ubuntu Terminal Emulators
  36. #23: How to Access the Command Line With Mac OS X and Windows
  37. #24: Freddy and the Men From Mars
  38. #25: Special Files and Proc Files
  39. #26: How Many Files Are on Your Unix System?
  40. #27: Comparing Unix Packages to Commercial Apps
  41. Appendix B: Command Summaries
  42. Index of Emacs Key Sequences
  43. Index of Emacs Variables and Functions
  44. Index of Unix Keys, Files and Commands
  45. General Index

About the Author and About the Technical Reviewer

About the Author

A385558_1_En_BookFrontmatter_Figc_HTML.jpg

Harley Hahn is a writer, philosopher, humorist, abstract artist, musician and computer expert. Hahn has written 33 books, including three university-level Unix/Linux textbooks. In all, Hahn’s books have sold more than 2 million copies, including Harley Hahn’s Internet Yellow Pages , the first Internet book in history to sell more than 1 million copies.

Hahn is the best-selling Internet author of all time, and has had three of his books nominated for a Pulitzer Prize. His work—including a complete set of his books—is archived by the Special Collections Department of the library at the University of California at Santa Barbara.

In addition to books, Hahn has written numerous articles, essays, and stories on a wide variety of topics, including romance, philosophy, money and economics, culture, medicine, and biology. Much of his writing is available on his Web site www.harley.com .

Hahn has a degree in Mathematics and Computer Science from the University of Waterloo (Canada), and a graduate degree in Computer Science from the University of California at San Diego. He has also studied medicine at the University of Toronto Medical School, and has been the recipient of a number of honors and awards, including a prestigious National Research Council (Canada) post-graduate scholarship, and the 1974 George Forsythe Award from the ACM (Association of Computer Machinery).

Of all his endeavors, Hahn most enjoys writing books, because “I get to sleep in, and I like telling people what to do.”

Web Site for This Book

For online support for Harley Hahn’s Emacs Field Guide , please visit:

http://​www.​harley.​com/​emacs

At this Web site, you will find a variety of useful information. You can also send a message to Harley Hahn.

About the Technical Reviewer

A385558_1_En_BookFrontmatter_Figd_HTML.jpg

Dmitry Shkatov has an MA in Philosophy from Moscow State University, Russia, and a PhD in Computer Science from the University of Nottingham, England. Shkatov lives in South Africa, where he is a Senior Lecturer in Computer Science at the University of the Witwatersrand, Johannesburg.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.22.136