Tag: textmate

 

TextMate book

Last week, a copy of TextMate: Power Editing for the Mac landed on my desk. TextMate has been a part of my life for about a year now. I can’t be doing without it (“Edit in TextMate” is worth the price of entry alone). I consider myself a reasonably advanced user.

Boy, was I wrong. From the very beginning of the book, I was getting something new off of each page. Not necessarily earth shattering, but a drip, drip, drip of new knowledge about textmate and how it works. By the end of the chapters on Editing, I felt hugely more confident about using the abilities of TextMate to the full.

The book is split into three main sections: Editing, Automations and Languages. Editing is well, editing. Do it hard, do it fast. The Automations section takes you to the next level, and lets you customize TextMate to your own unique workflow. From the simple snippet to the do-anything command, it really shows you how to take control.

What I particularly love about TextMate is that unlike vim or Emacs, it doesn’t have an extension language. Instead, you get to use Ruby, or Perl, or /bin/sh. You could use PHP if you prefer. In many ways it feels far more “Unixy” than either vi or Emacs. In fact, it’s much more like sam.

The final section, Languages, should rarely be needed. TextMate comes with builtin support plenty of languages (and many more are available). But when you need it, you really need it. James Gray manages to walk through the process of adding a simple language (JSON) in a very effective manner, showing you what’s possible in a succinct manner.

In fact, succinctness is present throughout this book. The text is clear and informative, never taking too long to explain, but not leaving you confused either. And at 200 pages, it’s nice slim tome. You could get through it in a couple of hours, but don’t worry—you’ll be coming back to it.

If you edit text on the Mac, do yourself a favour and get this book.

TextMate tip

I had an interesting little run-in with TextMate today. I’ve just been turned on (finally) to the lovely TODO bundle. However, it was producing very spurious results and taking a long time to do so.

Tracking it down wasn’t too hard, as it turned out. Just a few print statements in the TODO bundle did the trick. But the answer surprised me.

It turns out that when you have a project open in TextMate, it keeps a TM_PROJECT_DIRECTORY environment variable pointed at the directory you’ve got open in there. With just one folder open in that project, it’s got the same value as the folder. The TODO bundle searches everything in $TM_PROJECT_DIRECTORY. Nice and simple.

But, when you have two directories open in the project then $TM_PROJECT_DIRECTORY gets set to the highest common directory. In my case I had /Users/dom/work/project1 and /Users/dom/work/project2 open in the same TextMate project, so $TM_PROJECT_DIRECTORY was being set to /Users/dom/work. Now there’s a lot of stuff in there. No wonder it was taking a long time.

So, be warned. Stick to single folders in a project if you want to use the TODO bundle.

TextMate Tip

I got really caught out today. I needed to get some code samples from TextMate into Keynote. Cut’n’paste didn’t copy across the colours correctly. Kind of to be expected, since TextMate is a plain text editor, not a rich text editor.

After having a quick hunt around, I found the “Create HTML from Selection” command, which looked like just the ticket. Except that it produced HTML with lots of classes and no CSS (i.e. losing all the style). I played with it a bit, and the “Create CSS from Current Theme” command, all to no avail.

Eventually, I hopped onto irc and wandered into ##textmate on freenode.net. After a brief chat with several people whilst I explained my problem (badly), Allan Odgaard (textmate’s author) noticed that I had the selection enabled. Getting rid of the selection makes a new command appear, “Create HTML from Document”. And that loads into Safari just fine, from where it can be correctly cut’n’pasted into Keynote. Marvellous!

But more than anything, I can’t help but be impressed by the support that Allan offers. This was the middle of Sunday afternoon, and he personally answered my query to completion within 10 minutes. All I can say is that TextMate is well worth the money.

Character Info in Textmate

One rather useful feature of vim is that you can pull up information about a character by positioning your cursor over it and hitting ga (get ASCII?). I quite miss this in textmate, so I created a small command to add to the Text bundle. This is “Character Info”, which I’ve assigned to ^⇧I. It takes the selection as input and the information comes back in a tooltip.

  #!/usr/bin/perl
  use strict;
  use warnings;
  use charnames qw( :full );
  binmode( STDIN, ':utf8' );
  foreach my $c (split //, do { local $/; <> }) {
      my $code = ord $c;
      my $name = charnames::viacode( $code ) || "unknown character";
      printf "U+%04X %s\n", $code, $name;
  }
  exit 0;

This is what it looks like.

Character Info in action

The only caveat is that it only works if you’re using UTF-8 for your files. But really, if not, why not?

Spellchecking POD with TextMate

Trelane was asking on irc today about how to get TextMate to spell check POD. It doesn’t by default, which is annoying as it’s clever enough to check the spelling of strings.

The answer is fairly simple. Go into the Bundle Editor (^⌥⌘B) and open up the Perl category. Near the bottom you’ll see a “Comments” preferences item. Click on the plus box at the bottom of the screen and add another preferences item. Name it “Pod” and stick this in it:

    {    spellChecking = 1; }

In the “Scope Selector” field, type in comment.documentation.perl.

At this point, you have to restart TextMate. I’m not sure why, but you do. But afterwards, you should get lots of dotted red lines inside your pod.

Sadly, the Perl language definition inside TextMate doesn’t distinguish bits of pod much, so you’ll have to add words like “head1” to your dictionary (or fix the language definition).

A Month of Mac

It’s now been a month since my shiny new Mac arrived. Overall, I’m still really, really happy with it. I’ve bought NetNewsWire for feed reading and textmate for editing. I’m a little concerned that I don’t have the source code for my editor, but we’ll see how that goes.

I’m normally a devout Emacs or Vim user, but Aquamacs turned out to be just too different, despite what Tim Bray says about it. Carbon Vim was a bit better, but still felt a little clunky. TextMate just felt right, and after the recommendations from the rails people, it seemed like a good idea.

The main irritation that I’ve been having is with the keyboard. Apple keyboards don’t come easily to UK Unix users. The tilde is in the wrong position to start with (it’s been swapped with backslash), and I find myself continually hitting the wrong one. Worse is the fact that there’s no hash key on the keyboard in the UK layout. Oh all right, you can hit ⌥-3, but that pastes into the shell as UTF-8 meaning that you can’t comment things out properly in Vim. Why? I have no idea. But it’s meant that I’ve stuck to the US keyboard layout for now, which sucks.

By far and away the worst problem, though is the simple fact that you can’t copy CDs easily. The damned machine comes with a CD burner. It should be a piece of cake to say “take the bits off of this one, then right them on to this blank disk instead”. But no. The only option is to import into iTunes (converting into MP3) and then write the low-fi tracks out from iTunes again. With a 2-second gap between tracks. That really, badly sucks. Particularly when I found out that a previous version of OSX used to come with a “disk copy” utility. Thanks a bunch, Apple.