Evaluating Elisp Code
Total Page:16
File Type:pdf, Size:1020Kb
Contents Contents Introduction Thank You .................... Intended Audience ................ What You’ll Learn . The Way of Emacs Guiding Philosophy . LISP? ..................... Extensibility . Important Conventions . The Buffer . 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 . Configuring 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 file . C-x C-s: Save Buffer . C-x C-c: Exits Emacs . C-x b: Switch Buffer . C-x k: Kill Buffer . 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 definitions . Helm: Incremental Completion and Selection IDO: Interactively DO Things . Grep: Searching the file system . 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 Prefix 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 . EWW: Emacs Web Wowser . 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: Emacs’s Shell . Conclusion Other Resources . Chapter Introduction “I’m using Linux. A library that emacs uses to communicate with Intel hardware.” – Erwin, emacs, Freenode. Thank You Thank you for purchasing Mastering Emacs. This book has been a long time coming. When I started my blog, Master- ing Emacs, in , it was at the recommendation of a good friend, Lee, who suggested that I share my thoughts on Emacs and work flow in Emacs. At the time I had accrued in an org mode file titled blogideas.org a large but random assortment of ideas and concepts that I’d learned about and wished someone had taught me. The end result of that file is the blog and now this book. Special Thanks Introduction I would like to thank the following people for their encouragement, advice, suggestions and critiques: Akira Kitada, Alvaro Ramirez, Arialdo Mar- tini, Bob Koss, Catherine Mongrain, Chandan Rajendra, Christopher Lee, Daniel Hannaske, Edwin Ong, Evan Misshula, Friedrich Paetzke, Gabriela Hajduk, Gabriele Lana, Greg Sieranski, Holger Pirk, John Mastro, John Kitchin, Jonas Enlund, Konstantin Nazarenko, Lee Cullip, Luis Gerhorst, Lukas Pukenis, Manuel Uberti, Marcin Borkowski, Mark Kocera, Matt Wilbur, Matthew Daly, Michael Reid, Nanci Bonfim, Oliver Martell, Patrick Mosby, Patrick Martin, Sebastian Garcia Anderman, Stephen Nelson- Smith, Steve Mayer, Tariq Master, Travis Jefferson, Travis Hartwell. Like a lot of people, I was thrust into the world of Emacs without knowing anything about it; in my case it was in my first year of University where the local computer soci- ety was made up primarily of Vim users. It was explained to me, in no uncertain terms, that “you use Vim — that’s it.” Not wanting to be told what to do, I picked the polar opposite of Vim and went with Emacs. Emacs proved to be a stable and reliable editor in all those years, but it was a tough one to get to know. Despite the extensive user documentation, it never helped me to learn and 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 in many ways, as you will find out in the next chapter. Intended Audience It’s a bit weird talking about the intended audience when you’ve already bought the book on the subject. But it bears mentioning anyway so no matter your Emacs skill level you will get something out of this book. The first and (most obvious) audience are people new to Emacs. If you’ve never used Emacs before in your life, you will hopefully find this book very useful. However, if you’re new to Emacs and non-technical, then you’re going to have a harder time. Emacs, despite being suitable for much more than just programming, is squarely aimed at computer-savvy people. Although it’s perfectly possible to use Emacs anyway, this book will assume that you’re technically inclined, but not necessarily a programmer. If you’ve tried Emacs before but given up, then I hope this book is what convinces you to stick with it. But it’s fine if you don’t; some languages or environments don’t (contrary to what a lot of Emacs users would claim) work well with Emacs. If you’re primarily a Microsoft Windows developer working with Visual Studio, using Emacs is going to be a case of two steps forward, one step back: you gain unprece- dented text editing and tool integration but lose all the ben- efits a unified would give you. If you’re a Vim refugee, then welcome to the dark side! If your primary objective is to use Emacs’s Vim emulation lay- Introduction ers, then some of this book is redundant; it concerns itself with the default Emacs bindings and it teaches “the Emacs way” of doing things. But not to worry: a lot of the tips and advice herein are still applicable, and who knows — maybe you’ll switch away from Evil mode in time. And finally, if you’re an existing Emacs user but struggling to take it to the next level, or maybe you just need a refresher course “from the ground up,” then this book is also for you. What You’ll Learn Covering all of Emacs in just one book would be a Sisyphean task. Instead, I aim to teach you what you need to be produc- tive in Emacs, which is just a small subset of Emacs’s capabil- ity. Hopefully, by the end of this book, and with practice, you will know enough about Emacs to seek out and answer questions you have about the editor. To be more specific, I will teach you, in broad terms, six things: What Emacs is about A thorough explanation of impor- tant terminology and conventions that Emacs uses which in many cases differs greatly from other editors. You will also learn what the philosophy of Emacs is, and why a text editor even has a philosophy. I will also talk about Vim briefly and the Editor Wars and what the deal is with all those different keys. Getting started with Emacs How to install Emacs, how to run it, and how to ensure you’re using a reasonably Introduction new version of Emacs. I explain how to modify Emacs and what you need to do to make your changes perma- nent. I will introduce the Customize interface and how to load a color theme. And finally, I’ll talk about the user interface of Emacs and some handy tips in case you get stuck. Discovering Emacs Emacs is self-documenting; but what does it mean and how can you leverage that aspect to discover more about Emacs or answer questions you have about particular features? I will show you what I do when I have to learn how to use a new mode or feature in Emacs, and how you can use the self-documenting nature of Emacs to find things for which you’re looking. Movement How to move around in Emacs. At first glance a simple thing to do, but in Emacs there are many ways of going from where you are to where you need to go in the fewest possible keystrokes. Moving around is probably half the battle for a developer and know- ing how to do it quickly will make you more efficient. Some of the things you’ll learn: moving by syntactic units, and what exactly syntactic units are; using win- dows and buffers; searching and indexing text; select- ing text and using the mark. Editing As in the chapter on movement, I will show you how to edit text using a variety of tools offered to you by Emacs. This includes things like editing text by bal- anced expressions, words, lines, paragraphs; creating keyboard macros to automate repetitive tasks; search- Introduction ing and replacing; registers; multi-file editing; abbre- viations; remote file editing; and more. Productivity Emacs can do more than just edit text and this chapter is only a taste of what attracts so many people to Emacs: its tight integration with hundreds of exter- nal tools. I will whet your appetite and show you some of the more interesting things you can do when you choreograph Emacs’s movement and editing.