Tuesday, July 25, 2006

Trying a new programmer's editor: TextMate

Can't remember if I first saw it on digg or heard it on TWiT or something like that, but I got turned on to a new programmer's (or markupsman's) editor called TextMate a few days ago. I've been a Vim diehard for many years, and I'll still use it a lot, but this has the potential of finally converting me to the land of GUI editing.

I think the tutorial videos are what really convinced me - I plunked down the rego fee after just a few minutes of playing with it, and that's not something I normally do. It's just so damn slick! I find myself paying for programs on OS X, something I never did on Windows (confessions of a pir8). It just seems like it's something I can use over many hours and not want to barf. BBEdit reminded me of a Windows app actually - clunky, monolithic and ugly. I never got the appeal.

The first issue I had with TextMate prompted this exchange on the mail list:

I don't seem to be able to set up TM to handle tabs the same way. Here's the relevant snippet from my vimrc:

" Leave default for printing etc
set tabstop=8
" But use spaces between real tabs
set softtabstop=4
set shiftwidth=4
" Use 'real' tabs (^I) when possible
set noexpandtab


This works great, real tabs (^I) are left alone at the usual 8 spaces, however I like to indent my blocks by 4 at a time. This tells vim to use a real tab if it can, and "pad out" with spaces at the end if the current indent isn't a multiple of 8. Here's what it looks like in vim:


<?php$
$page = new PageController($
'shop.tpl',-$
array($
> 'showAds' => FALSE,$
> 'icon'> => 'shop'),$
'Online Store');$
$page->render();$
?>$


If I configure TM to use soft tabs at 4, then all my previous code looks wrong because it sets hard tabs to 4 as well. If I set it to 8, then my existing code looks fine but I'm not getting my desired softtab indent of 4.

This is a pretty annoying problem for me because I have hundreds of thousands of lines of code formatted this way :( Kind of ironic since I did it this way to maximize compatibility!

I guess what I'm looking for is the ability to set soft tab size independantly of hard tab size - the former to 4, the latter to 8. Is this possible??

(I suppose if there's no other option, I could convert all tabs to 8 spaces in all my files. However I like using tabs because it cuts down on file sizes a tiny bit.)


Unfortunately the only current solution is to convert tabs to 8 spaces in my files, and I wanted a macro or command to do it on a file by file basis as I have the need to edit them rather than touching every file en masse. Haris and Allan gave me these fast responses:


You can record a macro that uses that, or of course you can write a command. Anything you can do in the shell, you can wrap around a TM macro/command.

...

Use the Filter Through Command... (or create a command [1].)

The shell command you want is: expand -t8 with input/output set to document/replace document.


I'll give it a try and see how it goes. I've got a lot of code to maintain now with my AutoShrine Network sites, with a mix of PHP, HTML, SQL and CSS, so it should be a good test case.

PS: BSD style(9) all the way baby!!

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?