views:

57

answers:

3

Is there a command in TextMate to re-indent or format text in a file?

I use this all the time in IDE's after pasting in a block of code, removing a block, etc for re-indenting a file.

Bonus points if there is a way to pretty indent, turning this:

has_many :users, :class_name => 'Users', :dependent => :destroy
has_many :comments, :class_name => 'Comments', :dependent => :destroy

into this:

has_many :users,    :class_name => 'Users',    :dependent => :destroy
has_many :comments, :class_name => 'Comments', :dependent => :destroy

But even just simple reformatting would be awesome.

Not sure if it matters but I'm mostly talking about Ruby-on-Rails apps here.

A: 

Actually i am using " Rubymine (jetbrains) IDE for ROR" that give a facility to TextMate to re-indent or format text in a file . You can find in menus lof Rubymine editor .

I'm not sure what you mean. Are you saying there is a TextMate Bundle for RubyMine or Rubymine somehow gives this functionality to TextMate? I know that RubyMine itself has reformatting but this doesn't solve my issue since I'm using TextMate.
Brian Armstrong
A: 

Pretty indent? No way. I had no idea there was something called that. I'll be watching this thread.

For now I use apple + '[' or ']'

And make sure I have my indentions set to soft spaces.

I can't say that's exactly what you're looking for..

Trip
Yep, not exactly but I figure I can't be the first one to want this. I use the apple + '[' or ']' to indent individual lines or selections, but it's a poor substitute for re-indenting the whole file with one key combo.
Brian Armstrong
A: 

Sweet!

This bundle adds it for Ruby code: http://github.com/mocoso/code-beautifier.tmbundle#readme

It only indents Ruby code (not HTML or anything else), and doesn't do the pretty indent (only regular indenting), but still - it re-indents the whole file with one command.

Edit: just realized another way to do it with a built in TextMate feature. option-apple-[ This indents one line. So if you do ctrl-a (to select all) and then option-apple-[ it has a similar effect (although it's two commands instead of one, and loses where you had the cursor)

Brian Armstrong