mastering emacs

Download Mastering Emacs

Post on 09-Sep-2015

414 views

Category:

Documents

148 download

Embed Size (px)

DESCRIPTION

Mastering Emacs

TRANSCRIPT

  • Contents

    Contents

    Introduction Thank You . . . . . . . . . . . . . . . . . . . . Intended Audience . . . . . . . . . . . . . . . . What Youll Learn . . . . . . . . . . . . . . . .

    TheWay of Emacs Guiding Philosophy . . . . . . . . . . . . . . . .

    LISP? . . . . . . . . . . . . . . . . . . . . . Extensibility . . . . . . . . . . . . . . . . .

    Important Conventions . . . . . . . . . . . . . . The Buer . . . . . . . . . . . . . . . . . . The Window and the Frame . . . . . . . . The Point and Mark . . . . . . . . . . . . . Killing, Yanking and CUA . . . . . . . . . .emacs.d, init.el, and .emacs . . . . . . . . . Major Modes and Minor Modes . . . . . .

    First Steps Installing and Starting Emacs . . . . . . . . . . .

    Starting Emacs . . . . . . . . . . . . . . . .

  • The Emacs Interface . . . . . . . . . . . . . . . Keys . . . . . . . . . . . . . . . . . . . . . . . .

    Caps Lock as Control . . . . . . . . . . . . M-x: Execute Extended Command . . . . . Universal Arguments . . . . . . . . . . . . Discovering and Remembering Keys . . . .

    Conguring Emacs . . . . . . . . . . . . . . . . The Customize Interface . . . . . . . . . . Evaluating Elisp Code . . . . . . . . . . . . The Package Manager . . . . . . . . . . . . Color Themes . . . . . . . . . . . . . . . .

    Getting Help . . . . . . . . . . . . . . . . . . . The Info Manual . . . . . . . . . . . . . . Apropos . . . . . . . . . . . . . . . . . . . The Describe System . . . . . . . . . . . .

    The Theory of Movement The Basics . . . . . . . . . . . . . . . . . . . . .

    C-x C-f: Find le . . . . . . . . . . . . . . . C-x C-s: Save Buer . . . . . . . . . . . . . C-x C-c: Exits Emacs . . . . . . . . . . . . . C-x b: Switch Buer . . . . . . . . . . . . . C-x k: Kill Buer . . . . . . . . . . . . . . ESC ESC ESC: Keyboard Escape . . . . . . . . C-/: Undo . . . . . . . . . . . . . . . . . .

    Window Management . . . . . . . . . . . . . . Working with Other Windows . . . . . . .

    Frame Management . . . . . . . . . . . . . . . . Elemental Movement . . . . . . . . . . . . . . .

    Navigation Keys . . . . . . . . . . . . . . . Moving by Character . . . . . . . . . . . .

  • Moving by Line . . . . . . . . . . . . . . . Moving by Word . . . . . . . . . . . . . . Moving by S-Expressions . . . . . . . . . . Other Movement Commands . . . . . . . Scrolling . . . . . . . . . . . . . . . . . . .

    Bookmarks and Registers . . . . . . . . . . . . . Selections and Regions . . . . . . . . . . . . . .

    Selection Compatibility Modes . . . . . . . Setting the Mark . . . . . . . . . . . . . .

    Searching and Indexing . . . . . . . . . . . . . . Isearch: Incremental Search . . . . . . . . . Occur: Print lines matching an expression . Imenu: Jump to denitions . . . . . . . . . Helm: Incremental Completion and Selection IDO: Interactively DO Things . . . . . . .

    Other Movement Commands . . . . . . . . . . Conclusion . . . . . . . . . . . . . . . . . . . .

    The Theory of Editing Killing and Yanking Text . . . . . . . . . . . . .

    Killing versus Deleting . . . . . . . . . . . Yanking Text . . . . . . . . . . . . . . . .

    Transposing Text . . . . . . . . . . . . . . . . . C-t: Transpose Characters . . . . . . . . . . M-t: Transpose Words . . . . . . . . . . . . C-M-t: Transpose S-expressions . . . . . . . Other Transpose Commands . . . . . . . .

    Filling and Commenting . . . . . . . . . . . . . Filling . . . . . . . . . . . . . . . . . . . . Commenting . . . . . . . . . . . . . . . .

    Search and Replace . . . . . . . . . . . . . . . .

  • Case Folding . . . . . . . . . . . . . . . . . Regular Expressions . . . . . . . . . . . . .

    Changing Case . . . . . . . . . . . . . . . . . . Counting Things . . . . . . . . . . . . . . . . . Text Manipulation . . . . . . . . . . . . . . . .

    Editable Occur . . . . . . . . . . . . . . . . Deleting Duplicates . . . . . . . . . . . . . Flushing and Keeping Lines . . . . . . . . . Joining and Splitting Lines . . . . . . . . . Whitespace Commands . . . . . . . . . . .

    Keyboard Macros . . . . . . . . . . . . . . . . . Basic Commands . . . . . . . . . . . . . . Advanced Commands . . . . . . . . . . . .

    Text Expansion . . . . . . . . . . . . . . . . . . Abbrev . . . . . . . . . . . . . . . . . . . . DAbbrev and Hippie Expand . . . . . . . .

    Indenting Text and Code . . . . . . . . . . . . . RET: Indenting New lines . . . . . . . . . . TAB: Indenting the Current Line . . . . . . Indenting Regions . . . . . . . . . . . . . .

    Sorting and Aligning . . . . . . . . . . . . . . . Sorting . . . . . . . . . . . . . . . . . . . . Aligning . . . . . . . . . . . . . . . . . . .

    Other Editing Commands . . . . . . . . . . . . Zapping Characters . . . . . . . . . . . . . Spell Checking . . . . . . . . . . . . . . . uoted Insert . . . . . . . . . . . . . . . .

    The Practicals of Emacs Exploring Emacs . . . . . . . . . . . . . . . . .

    Reading the Manual . . . . . . . . . . . . .

  • Using Apropos . . . . . . . . . . . . . . . C-h: Exploring Prex keys . . . . . . . . . C-h k: Describe what a key does . . . . . . C-h m: Finding mode commands . . . . . .

    Working with Log Files . . . . . . . . . . . . . . Browsing Other Files . . . . . . . . . . . .

    TRAMP: Remote File Editing . . . . . . . . . . Multi-Hops and User Switching . . . . . .

    Dired: Files and Directories . . . . . . . . . . . Navigation . . . . . . . . . . . . . . . . . . Marking and Unmarking . . . . . . . . . . Operations . . . . . . . . . . . . . . . . . . Working Across Directories . . . . . . . . .

    Shell Commands . . . . . . . . . . . . . . . . . Compiling in Emacs . . . . . . . . . . . . .

    Shells in Emacs . . . . . . . . . . . . . . . . . . M-x shell: Shell Mode . . . . . . . . . . . . M-x ansi-term: Terminal Emulator . . . . . M-x eshell: Emacss Shell . . . . . . . . . .

    Conclusion Other Resources . . . . . . . . . . . . . . . . .

  • Chapter

    Introduction

    Im using Linux. A library that emacs uses tocommunicate with Intel hardware.

    Erwin, emacs, Freenode.

    Thank You

    Thank you for purchasing Mastering Emacs. This book hasbeen a long time coming. When I started my blog, Master-ing Emacs, in , it was at the recommendation of a goodfriend, Lee, who suggested that I share my thoughts onEmacs and work ow in Emacs. At the time I had accruedin an org mode le titled blogideas.org a large but randomassortment of ideas and concepts that Id learned about andwished someone had taught me. The end result of that leis the blog and now this book.

    Special Thanks

  • Introduction

    I would like to thank the following people fortheir encouragement, advice, suggestions andcritiques:

    Akira Kitada, Alvaro Ramirez, Arialdo Mar-tini, Bob Koss, Catherine Mongrain, ChandanRajendra, Christopher Lee, Daniel Hannaske,Edwin Ong, Evan Misshula, Friedrich Paetzke,Gabriela Hajduk, Gabriele Lana, Greg Sieranski,Holger Pirk, John Mastro, John Kitchin, JonasEnlund, Konstantin Nazarenko, Lee Cullip,Luis Gerhorst, Lukas Pukenis, Manuel Uberti,Marcin Borkowski, Mark Kocera, Matt Wilbur,Matthew Daly, Michael Reid, Nanci Bonm,Oliver Martell, Patrick Mosby, Patrick Martin,Sebastian Garcia Anderman, Stephen Nelson-Smith, Steve Mayer, Tariq Master, TravisJeerson, Travis Hartwell.

    Like a lot of people, I was thrust into the world of Emacswithout knowing anything about it; in my case it was inmy rst year of University where the local computer soci-ety was made up primarily of Vim users. It was explainedto me, in no uncertain terms, that you use Vim thatsit. Not wanting to be told what to do, I picked the polaropposite of Vim and went with Emacs.

    Emacs proved to be a stable and reliable editor in all thoseyears, but it was a tough one to get to know. Despite theextensive user documentation, it never helped me to learnand understand Emacs.

  • Introduction

    As it turns out, Emacs is a philosophy or even a religion. So,the joke about the Church of Emacs is eerily accurate inmany ways, as you will nd out in the next chapter.

    Intended Audience

    Its a bit weird talking about the intended audience whenyouve already bought the book on the subject. But it bearsmentioning anyway so no matter your Emacs skill level youwill get something out of this book.

    The rst and (most obvious) audience are people new toEmacs. If youve never used Emacs before in your life, youwill hopefully nd this book very useful. However, ifyoure new to Emacs and non-technical, then youre goingto have a harder time. Emacs, despite being suitable formuch more than just programming, is squarely aimed atcomputer-savvy people. Although its perfectly possibleto use Emacs anyway, this book will assume that youretechnically inclined, but not necessarily a programmer.

    If youve tried Emacs before but given up, then I hope thisbook is what convinces you to stick with it. But its ne ifyou dont; some languages or environments dont (contraryto what a lot of Emacs users would claim) work well withEmacs. If youre primarily a Microsoft Windows developerworking with Visual Studio, using Emacs is going to be acase of two steps forward, one step back: you gain unprece-dented text editing and tool integration but lose all the ben-ets a unied would give you.

    If youre a Vim refugee, then welcome to the dark side! Ifyour primary objective is to use Emacss Vim emulation lay-

  • Introduction

    ers, then some of this book is redundant; it concerns itselfwith the default Emacs bindings and it teaches the Emacsway of doing things. But not to worry: a lot of the tips andadvice herein are still applicable, and who knows maybeyoull switch away from Evil mode in time.

    And nally, if you