Textmate Power Editing for the Mac.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
What readers are saying about TextMate: Power Editing for the Mac This is not just a book, but a doorway to higher dimensional text edit- ing! By the third chapter I was completely switched over to TextMate from Vim. The book provided everything I needed to take full advan- tage of all that TextMate offers. This book rocks, and James is my new hero. Ernest Obusek Software Engineer, Network Appliance, Inc. This book is outstanding. Without saying it, James has made the case for TextMate quickly becoming the interface for 90% of what any OS X user will ever need to do. I’ve read a substantial amount of material concerning both OS X and TextMate, but by Chapter 3, James had blown me away. By the end of Chapter 5 . wow. This is some power- ful stuff. Stephen Hargrove System Administrator As an Emacs junkie, it takes considerable persuasion for me to even consider using another editor. This book did the job, and now I use TextMate regularly. The chapters on the various built-in automations, scripting and snippets are invaluable. Ruby on Rails and other coding enthusiasts will also find that this book provides ample coverage of programming oriented tasks. Jon Mountjoy Director, MemeStorm Ltd. I’ve been using TextMate for months and I thought I knew everything it could do. I was surprised to discover many editing tricks and key- commands that I had completely missed. James did a terrific job mak- ing this book an essential asset for even a seasoned TextMate user. Michael Gregoire Owner/Creator, nvzion.com and blocSonic.com TextMate is like an onion. It seems like such a simple thing when you first see it, then you start peeling back layers and suddenly discover the richness that lies underneath. This book peels the onion that is TextMate, revealing the awesome power underneath. It has become my Swiss-army chainsaw, flexible enough for everything and powerful enough for anything. Neal Ford Application Architect, ThoughtWorks A thorough, practical reference for anyone who ever wondered if there was more to life than Dreamweaver. Benjamin Jackson Technical Director, INCOMUM Design and Concept This beautifully written text brings the power of TextMate to some- one who does not know any programming language. Each page reveals hidden, indispensable tricks that improve work flow, which is what the TextMate philosophy is all about. Jenny Harrison Professor of Mathematics, UC Berkeley TextMate Power Editing for the Mac James Edward Gray II The Pragmatic Bookshelf Raleigh, North Carolina Dallas, Texas Many of the designations used by manufacturers and sellers to distinguish their prod- ucts are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://www.pragmaticprogrammer.com Copyright © 2007 The Pragmatic Programmers LLC. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmit- ted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. ISBN-10: 0-9787392-3-X ISBN-13: 978-0-9787392-3-2 Printed on acid-free paper with 85% recycled, 30% post-consumer content. First printing, January, 2007 Version: 2007-2-23 “James enjoys playing chess and loves his mother very much.” For Nicole and Payden, a sister and brother so cool they make me look good, and the Payne women who remain my biggest fans. Contents 1 Introduction 12 1.1 A Brief History of TextMate ................. 12 1.2 In These Pages ........................ 14 1.3 The Mac Keyboard and Mouse ............... 15 1.4 Installing TextMate and Tools ............... 17 1.5 The Editing Window ..................... 19 I Editing 21 2 Projects 22 2.1 Creating a Project ...................... 22 2.2 Moving between Files .................... 24 2.3 Shortcuts for Creating Projects ............... 25 2.4 Folder References ...................... 26 3 Power Editing 29 3.1 Moving Around ........................ 29 3.2 Making Selections ...................... 33 3.3 Editing ............................. 36 4 Find and Replace 45 4.1 Without Using a Regular Expression ........... 45 4.2 Mixing in Regular Expressions ............... 50 II Automations 58 5 Built-in Automations 59 5.1 The TODO Bundle ...................... 59 5.2 The HTML and CSS Bundles ................ 62 5.3 The Ruby Bundle ....................... 65 5.4 The Rails Bundle ....................... 67 CONTENTS 10 5.5 The Subversion Bundle ................... 69 5.6 The Math Bundle ....................... 72 5.7 The Markdown Bundle ................... 73 5.8 The Blogging Bundle ..................... 77 5.9 The Mail Bundle ....................... 78 5.10 The Text Bundle ....................... 79 5.11 The Source Bundle ...................... 80 5.12 The TextMate Bundle .................... 81 6 Snippets 83 6.1 Basic Snippets ........................ 83 6.2 Tab Stops ........................... 86 7 Macros 97 7.1 The Macro Editor ....................... 100 8 Commands 103 8.1 Shell Commands ....................... 103 8.2 TextMate Commands .................... 105 8.3 Drag Commands ....................... 115 9 Automation Tips and Tricks 117 9.1 Building Bundle Menus ................... 117 9.2 TextMate’s Environment Variables ............. 119 9.3 Useful Shell Commands ................... 124 9.4 Using TextMate’s Document Parsing ........... 129 9.5 bash Support Functions ................... 131 9.6 Ruby Support Libraries ................... 133 9.7 Hooking Into Save Operations ............... 134 9.8 Streaming Command Output ................ 136 9.9 Building Interactive Commands .............. 139 9.10 Compound Automations .................. 142 III Languages 145 10 Language Grammars 146 10.1 The JSON Data Language .................. 146 10.2 Language Grammar Reference ............... 167 CONTENTS 11 11 Preferences and Themes 176 11.1 Preferences .......................... 176 11.2 Themes ............................ 182 12 Beyond This Book 186 Index 188 Chapter 1 Introduction You probably spend most of your day reading and writing text in one form or another. Programmers write text in arcane languages with un- usual rules. Web developers produce HTML and CSS files by the pound, and those are just another flavor of plain old text. Even Ph.D. candi- dates tend to generate massive amounts of text that can be typeset using LATEX or similar tools. Now think about it: If you take the time to learn enough to trim even a few steps off your daily workflow, that’s going to add up to be a big win in very little time. The great news is that you can probably save a lot of work with just a little knowledge. This book is full of timesaving techniques that pay off immediately. So, which text editor should you learn? This is a heated topic in com- puter geek circles. Those on each side of the famous vi versus emacs debate are religious about their choice. You can use what you want, but I’ve worked with a few editors now, and TextMate is the right fit for me. In this short book, I’ll show you how to automate much of your daily workflow and try to make a true TextMate believer out of you too. 1.1 A Brief History of TextMate TextMate was created by Allan Odgaard in 2004 while he was waiting to start a new job. After a couple of months of work, he announced the first release of the editor. It was a little slim. There were no preferences to set, and you couldn’t print with it. Less than two years later, TextMate was awarded the Apple Design Award ABRIEF HISTORY OF TEXTMATE 13 for Best Developer Tool. As I write this introduction, TextMate has reg- istered users in the tens of thousands. People have certainly started to take note of the little editor. It even has preferences and can print these days. Allan never quite made it to that other job, but instead spends his time improving TextMate for us users. What has made TextMate so successful in such a short time is that it combines the power of Unix with the accessibility of Mac OS X. The many Unix tools are a powerful addition to the user’s tool belt. Unix editors such as vi and emacs have been enormously successful because they tie in so well to these tools. For Mac users, though, these editors have painfully foreign interfaces. TextMate really makes a great effort to expose these helpers to the user from a Mac-friendly interface. The automations really shine for this. You can wrap a few operations useful for a common task together and package them in a single menu item or keystroke. This helps users create tailored enhancements to TextMate for each domain with which they need to work. Even better, TextMate makes it easy to share these specialized automa- tions with others. That has given birth to a vibrant open source–like community sharing their TextMate enhancements, though the appli- cation itself remains proprietary. Today the official TextMate Subver- sion repository holds more than 125 groupings of automations and languages maintained by dozens of developers. You can even download tools to work with spreadsheet data1 or screen- plays2 in the editor. Odds are good TextMate already covers at least some of your needs, and for the situations where it doesn’t, you can train it yourself.