Mastering Emacs

Download Mastering Emacs

Post on 09-Sep-2015

113 views

Category:

Documents

53 download

Embed Size (px)

DESCRIPTION

Mastering Emacs

TRANSCRIPT

<ul><li><p>Contents</p><p>Contents </p><p> Introduction Thank You . . . . . . . . . . . . . . . . . . . . Intended Audience . . . . . . . . . . . . . . . . What Youll Learn . . . . . . . . . . . . . . . . </p><p> TheWay of Emacs Guiding Philosophy . . . . . . . . . . . . . . . . </p><p>LISP? . . . . . . . . . . . . . . . . . . . . . Extensibility . . . . . . . . . . . . . . . . . </p><p>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 . . . . . . </p><p> First Steps Installing and Starting Emacs . . . . . . . . . . . </p><p>Starting Emacs . . . . . . . . . . . . . . . . </p></li><li><p>The Emacs Interface . . . . . . . . . . . . . . . Keys . . . . . . . . . . . . . . . . . . . . . . . . </p><p>Caps Lock as Control . . . . . . . . . . . . M-x: Execute Extended Command . . . . . Universal Arguments . . . . . . . . . . . . Discovering and Remembering Keys . . . . </p><p>Conguring Emacs . . . . . . . . . . . . . . . . The Customize Interface . . . . . . . . . . Evaluating Elisp Code . . . . . . . . . . . . The Package Manager . . . . . . . . . . . . Color Themes . . . . . . . . . . . . . . . . </p><p>Getting Help . . . . . . . . . . . . . . . . . . . The Info Manual . . . . . . . . . . . . . . Apropos . . . . . . . . . . . . . . . . . . . The Describe System . . . . . . . . . . . . </p><p> The Theory of Movement The Basics . . . . . . . . . . . . . . . . . . . . . </p><p>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 . . . . . . . . . . . . . . . . . . </p><p>Window Management . . . . . . . . . . . . . . Working with Other Windows . . . . . . . </p><p>Frame Management . . . . . . . . . . . . . . . . Elemental Movement . . . . . . . . . . . . . . . </p><p>Navigation Keys . . . . . . . . . . . . . . . Moving by Character . . . . . . . . . . . . </p></li><li><p>Moving by Line . . . . . . . . . . . . . . . Moving by Word . . . . . . . . . . . . . . Moving by S-Expressions . . . . . . . . . . Other Movement Commands . . . . . . . Scrolling . . . . . . . . . . . . . . . . . . . </p><p>Bookmarks and Registers . . . . . . . . . . . . . Selections and Regions . . . . . . . . . . . . . . </p><p>Selection Compatibility Modes . . . . . . . Setting the Mark . . . . . . . . . . . . . . </p><p>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 . . . . . . . </p><p>Other Movement Commands . . . . . . . . . . Conclusion . . . . . . . . . . . . . . . . . . . . </p><p> The Theory of Editing Killing and Yanking Text . . . . . . . . . . . . . </p><p>Killing versus Deleting . . . . . . . . . . . Yanking Text . . . . . . . . . . . . . . . . </p><p>Transposing Text . . . . . . . . . . . . . . . . . C-t: Transpose Characters . . . . . . . . . . M-t: Transpose Words . . . . . . . . . . . . C-M-t: Transpose S-expressions . . . . . . . Other Transpose Commands . . . . . . . . </p><p>Filling and Commenting . . . . . . . . . . . . . Filling . . . . . . . . . . . . . . . . . . . . Commenting . . . . . . . . . . . . . . . . </p><p>Search and Replace . . . . . . . . . . . . . . . . </p></li><li><p>Case Folding . . . . . . . . . . . . . . . . . Regular Expressions . . . . . . . . . . . . . </p><p>Changing Case . . . . . . . . . . . . . . . . . . Counting Things . . . . . . . . . . . . . . . . . Text Manipulation . . . . . . . . . . . . . . . . </p><p>Editable Occur . . . . . . . . . . . . . . . . Deleting Duplicates . . . . . . . . . . . . . Flushing and Keeping Lines . . . . . . . . . Joining and Splitting Lines . . . . . . . . . Whitespace Commands . . . . . . . . . . . </p><p>Keyboard Macros . . . . . . . . . . . . . . . . . Basic Commands . . . . . . . . . . . . . . Advanced Commands . . . . . . . . . . . . </p><p>Text Expansion . . . . . . . . . . . . . . . . . . Abbrev . . . . . . . . . . . . . . . . . . . . DAbbrev and Hippie Expand . . . . . . . . </p><p>Indenting Text and Code . . . . . . . . . . . . . RET: Indenting New lines . . . . . . . . . . TAB: Indenting the Current Line . . . . . . Indenting Regions . . . . . . . . . . . . . . </p><p>Sorting and Aligning . . . . . . . . . . . . . . . Sorting . . . . . . . . . . . . . . . . . . . . Aligning . . . . . . . . . . . . . . . . . . . </p><p>Other Editing Commands . . . . . . . . . . . . Zapping Characters . . . . . . . . . . . . . Spell Checking . . . . . . . . . . . . . . . uoted Insert . . . . . . . . . . . . . . . . </p><p> The Practicals of Emacs Exploring Emacs . . . . . . . . . . . . . . . . . </p><p>Reading the Manual . . . . . . . . . . . . . </p></li><li><p>Using Apropos . . . . . . . . . . . . . . . C-h: Exploring Prex keys . . . . . . . . . C-h k: Describe what a key does . . . . . . C-h m: Finding mode commands . . . . . . </p><p>Working with Log Files . . . . . . . . . . . . . . Browsing Other Files . . . . . . . . . . . . </p><p>TRAMP: Remote File Editing . . . . . . . . . . Multi-Hops and User Switching . . . . . . </p><p>Dired: Files and Directories . . . . . . . . . . . Navigation . . . . . . . . . . . . . . . . . . Marking and Unmarking . . . . . . . . . . Operations . . . . . . . . . . . . . . . . . . Working Across Directories . . . . . . . . . </p><p>Shell Commands . . . . . . . . . . . . . . . . . Compiling in Emacs . . . . . . . . . . . . . </p><p>Shells in Emacs . . . . . . . . . . . . . . . . . . M-x shell: Shell Mode . . . . . . . . . . . . M-x ansi-term: Terminal Emulator . . . . . M-x eshell: Emacss Shell . . . . . . . . . . </p><p> Conclusion Other Resources . . . . . . . . . . . . . . . . . </p></li><li><p>Chapter </p><p>Introduction</p><p>Im using Linux. A library that emacs uses tocommunicate with Intel hardware.</p><p> Erwin, emacs, Freenode.</p><p>Thank You</p><p>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.</p><p>Special Thanks</p></li><li><p>Introduction</p><p>I would like to thank the following people fortheir encouragement, advice, suggestions andcritiques:</p><p>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.</p><p>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.</p><p>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.</p></li><li><p>Introduction</p><p>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.</p><p>Intended Audience</p><p>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.</p><p>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.</p><p>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.</p><p>If youre a Vim refugee, then welcome to the dark side! Ifyour primary objective is to use Emacss Vim emulation lay-</p></li><li><p>Introduction</p><p>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.</p><p>And nally, if youre an existing Emacs user but strugglingto take it to the next level, or maybe you just need a refreshercourse from the ground up, then this book is also for you.</p><p>What Youll Learn</p><p>Covering all of Emacs in just one book would be a Sisypheantask. Instead, I aim to teach you what you need to be produc-tive in Emacs, which is just a small subset of Emacss capabil-ity. Hopefully, by the end of this book, and with practice,you will know enough about Emacs to seek out and answerquestions you have about the editor.</p><p>To be more specic, I will teach you, in broad terms, sixthings:</p><p>What Emacs is about A thorough explanation of impor-tant terminology and conventions that Emacs useswhich in many cases diers greatly from other editors.You will also learn what the philosophy of Emacs is,and why a text editor even has a philosophy. I willalso talk about Vim briey and the Editor Wars andwhat the deal is with all those dierent keys.</p><p>Getting started with Emacs How to install Emacs, how torun it, and how to ensure youre using a reasonably</p></li><li><p>Introduction</p><p>new version of Emacs. I explain how to modify Emacsand what you need to do to make your changes perma-nent. I will introduce the Customize interface and howto load a color theme. And nally, Ill talk about theuser interface of Emacs and some handy tips in caseyou get stuck.</p><p>Discovering Emacs Emacs is self-documenting; but whatdoes it mean and how can you leverage that aspectto discover more about Emacs or answer questionsyou have about particular features? I will show youwhat I do when I have to learn how to use a newmode or feature in Emacs, and how you can use theself-documenting nature of Emacs to nd things forwhich youre looking.</p><p>Movement How to move around in Emacs. At rst glance asimple thing to do, but in Emacs there are many waysof going from where you are to where you need togo in the fewest possible keystrokes. Moving aroundis probably half the battle for a developer and know-ing how to do it quickly will make you more ecient.Some of the things youll learn: moving by syntacticunits, and what exactly syntactic units are; using win-dows and buers; searching and indexing text; select-ing text and using the mark.</p><p>Editing As in the chapter on movement, I will show youhow to edit text using a variety of tools oered to youby Emacs. This includes things like editing text by bal-anced expressions, words, lines, paragraphs; creatingkeyboard macros to automate repetitive tasks; search-</p></li><li><p>Introduction</p><p>ing and replacing; registers; multi-le editing; abbre-viations; remote le editing; and more.</p><p>Productivity Emacs can do more than just edit text and thischapter is only a taste of what attracts so many peopleto Emacs: its tight integration with hundreds of exter-nal tools. I will whet your appetite and show you someof the more interesting things you can do when youchoreograph Emacss movement and editing.</p></li><li><p>Chapter </p><p>TheWay of Emacs</p><p>The purpose of a windowing system is to putsome amusing u around your one almightyemacs window.</p><p> Mark, gnu.emacs.help.</p><p>If you imagine the span of the modern computing era be-ginning in the s, then Emacs has been there longer thanjust about everything else. It was rst written by RichardStallman as a set of macros on top of another editor, called, back in .1 is now mostly remembered for be-ing even more obtuse and hard to understand than Emacsand -era WordPerfect combined. Since then, there havebeen many competing implementations of Emacs but todayyoure only likely to encounter XEmacs and Emacs.</p><p>https://www.gnu.org/software/emacs/manual/html_mono/efaq.htmlOrigin-of-the-term-Emacs</p></li><li><p>TheWay of Emacs</p><p>This book will only concern itself with Emacs. Onceupon a time XEmacs was the more advanced and featurerich editor, but this is no longer the case: from Emacs on-wards Emacs is the best Emacs out there. The historyof XEmacs and Emacs is an interesting one. It was oneof the rst major forks2 in a free software project and bothXEmacs and Emacs are developed in parallel to this day.</p><p>Note</p><p>To almost everyone, the wordEmacs refers specif-ically to Emacs. I will only spell out the fullname when I am distinguishing between dier-ent implementations. When I mention Emacs, Ialways talk about Emacs.</p><p>Because of Emacss age there are a number of oddities.Weird choices of terminology and historical anachronismspersist because in most cases Emacs was ahead of the editor- curve for many decades and thus had to invent its ownterminology for things. There are talks of replacing Emacssown vernacular with words familiar to everyone, but thatis still a long way o.</p><p>Despite the lack of marketing, a small core of Emacs devel-opers, the anachronisms and terminology that predates themodern Personal Computing-era, there are many peopleout there who just love using Emacs. When Sublime Textshowed o its mini-map feature (a miniature display of thesource code) someone immediately coded up a minimappackage doing the same thing in Emacs. In fact, it is this</p><p>http://www.jwz.org/doc/lemacs.html</p></li><li><p>TheWay of Emacs</p><p>extensibility that attracts some to and repels others from Emacs.</p><p>This chapter will talk about the Way of Emacs: the terminol-ogy and what Emacs means to a lot of people, and why un-derstanding where Emacs comes from will make it easier toadopt it.</p><p>Guiding Philosophy</p><p>Emacs is a tinkerers editor. Plain and simple. People whohack on Emacs do it because almost every facet of it isextensible. It is the original extensible, customizable, self-documenting editor. If y...</p></li></ul>