® Emacs Field Guide — Harley Hahn Harley Hahn’s Emacs Field Guide Harley Hahn Harley Hahn’s Emacs Field Guide Harley Hahn www.harley.com ISBN-13 (pbk): 978-1-4842-1702-3 ISBN-13 (electronic): 978-1-4842-1703-0 DOI 10.1007/978-1-4842-1703-0 Library of Congress Control Number: 2016938804 Copyright © 2016 by Harley Hahn 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. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. 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. The name “Harley Hahn”, the Harley Hahn stylized signature, and the Harley Hahn Unisphere logo are registered trademarks of Harley Hahn. 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. 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 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 o [email protected] , or visit w ww.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. For information on translations, please e-mail [email protected] , or visit w ww.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 w ww.apress.com/bulk-sales . Any source code or other supplementary materials referenced by the author in this text are available to readers at w ww.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. Printed on acid-free paper To Maria, for love and support. And to Sadie (my dog) and Max (Maria’s dog), for being such good company. Contents at a Glance About the Author .............................................................................xv About the Technical Reviewer .......................................................xvii Acknowledgments ..........................................................................xix A Personal Note from Harley Hahn .................................................xxi ■ Chapter 1: All About Emacs ............................................................1 ■ Chapter 2: Unix for Emacs Users ..................................................13 ■ Chapter 3: Installing Emacs .........................................................57 ■ Chapter 4: The Emacs Keyboard ...................................................71 ■ Chapter 5: Starting and Stopping Emacs......................................79 ■ Chapter 6: Commands, Buffers, Windows ....................................87 ■ Chapter 7: The Text Editing Work Environment ..........................105 ■ Chapter 8: The Cursor; Line Numbers; Point and Mark; The Region ..................................................................................121 ■ Chapter 9: Kill and Delete; Move and Copy; Correct Mistakes; Spelling; Fill ................................................................................137 ■ Chapter 10: Searching ................................................................155 ■ Chapter 11: Modes; Customizing Using Your .emacs File ........173 v ■ CONTENTS AT A GLANCE ■ Chapter 12: Shell Commands; Help and Info; Programs and Games .........................................................................................189 ■ Appendix A: Personal Notes .......................................................215 ■ Appendix B: Command Summaries ............................................231 Index of Emacs Key Sequences .....................................................257 Index of Emacs Variables and Functions .......................................261 Index of Unix Keys, Files and Commands ......................................263 General Index .................................................................................265 vi Contents About the Author .............................................................................xv About the Technical Reviewer .......................................................xvii Acknowledgments ..........................................................................xix A Personal Note from Harley Hahn .................................................xxi ■ Chapter 1: All About Emacs ............................................................1 Section 1.1: Getting Started Together ......................................................1 Section 1.2: Emacs Is a Text Editor..........................................................3 Section 1.3: Emacs Is a Working Environment ........................................5 Section: 1.4: Where Did Emacs Come From? ..........................................8 Section 1.5: The Free Software Foundation ............................................9 Section 1.6: Excerpts From The Gnu Manifesto .................................10 ■ Chapter 2: Unix for Emacs Users ..................................................13 Section 2.1: Operating Systems ............................................................13 Section 2.2: Unix and Linux ...................................................................14 Section 2.3: Unix Terminals and Userids ...............................................18 Section 2.4: Types of Terminals .............................................................21 Section 2.5: User Interfaces ..................................................................23 Section 2.6: Using a Unix Terminal ........................................................27 Section 2.7: The Unix Command Line ....................................................31 Section 2.8: The Shell Prompt ...............................................................32 vii ■ CONTENTS Section 2.9: What Unix Commands Look Like .......................................33 Section 2.10: Making Corrections as You Type Commands ...................34 Section 2.11: Two Important Keys: <Ctrl-C> and <Ctrl-D> ...................35 Section 2.12: The History List; Command Line Editing ..........................37 Section 2.13: The Unix Manual ..............................................................40 Section 2.14: Using the less Pager Program .....................................41 Section 2.15: The Three Types of Unix Files ..........................................43 Section 2.16: The Tree-Structured Filesystem .......................................45 Section 2.17: The Current Directory and Pathnames ............................48 Section 2.18: File and Directory Names ................................................52 Section 2.19: File and Directory Names: OS X and Windows ................55 ■ Chapter 3: Installing Emacs .........................................................57 Section 3.1: Installing Software: Packages vs. Manual Installation ......57 Section 3.2: Installing Emacs Using a Linux Package Manager ............60 Section 3.3: Installing Emacs Manually With Linux ...............................62 Section 3.4: Installing Emacs With OS X ................................................65 Section 3.5: Installing Emacs With Microsoft Windows .........................68 ■ Chapter 4: The Emacs Keyboard ...................................................71 Section 4.1: A Strategy for Learning Emacs ..........................................71 Section 4.2: The Ctrl Key .......................................................................72 Section 4.3: The Meta (Alt) Key .............................................................72 Section 4.4: Special Key Names ............................................................74 Section 4.5: The Meta Key, Bucky Bits, and Much More ........................75 Section 4.6: Meta Key Problems When Using a Terminal Window.........78 viii ■ CONTENTS ■ Chapter 5: Starting and Stopping Emacs......................................79 Section 5.1: Starting Emacs ..................................................................79 Section 5.2: Starting Emacs in a Terminal Window ...............................81 Section 5.3: Starting Emacs as a Read-Only Editor ..............................82 Section 5.4: Recovering Data After a System Failure ............................83 Section 5.5: Stopping Emacs .................................................................84 ■ Chapter 6: Commands, Buffers, Windows ....................................87 Section 6.1: Commands and Key Bindings ............................................87 Section 6.2: Buffers ...............................................................................89 Section 6.3: Windows ............................................................................91 Section 6.4: The Mode Line / Read-Only Viewing ..................................94 Section 6.5: The Echo Area / Typing Emacs Commands ........................96 Section 6.6: The Minibuffer ...................................................................97 Section 6.7: Completion ........................................................................99 Section 6.8: Disabled Commands ........................................................102 ■ Chapter 7: The Text Editing Work Environment ..........................105 Section 7.1: How to Practice Using Emacs ..........................................105 Section 7.2: Typing and Correcting ......................................................107 Section 7.3: The repeat and undo Commands; Redo ....................108 Section 7.4: The keyboard-quit Command (C-g) .....................112 Section 7.5: Emacs for vi Users ........................................................112 Section 7.6: Commands to Control Windows .......................................113 Section 7.7: Commands to Control Buffers .........................................115 Section 7.8: Commands for Working With Files ...................................117 ix