tags:

views:

134

answers:

4

I believe it is called "cuddle" style:

function foo() {
   // blah
}

function foo() 
{
   // blah
}

Does anyone know of any scripts that will go through a file and toggle in one direction or the other? My goal is TextMate integration through a bundle, but any script in any language should be fine. I believe I can hook most any language into textmate through a bundle.

A: 

Look at the CSS bundle in TextMate as it does a very similar thing when you press C-q

bjeanes
A: 

You might get away with using astyle, though it doesn't specifically support JavaScript, it's loose enough that astyle -b does format your example correctly.

Pete Kirkham
+1  A: 

Switching indentation styles is a form of pretty-printing or code beautifying.

For Javascript, the online tool at http://jsbeautifier.org/ also has the code available for download.

For other languages, there's a comprehensive list of code beautifiers on Wikipedia http://en.wikipedia.org/wiki/Prettyprint

You can script TextMate with Javascript.

Malcolm Box
+1  A: 

http://www.bierkandt.org/beautify/ is how I solved this. I made a new bundle in Textmate of

/path/to/php ~/Library/Application\ Support/TextMate/beautifyphp/beautify_php -i 5 -v 0 -l -b 0

Now all I do, is select my chunk of php, run the bundle command, and it will reformat it to my liking. It does other nice things, like align equals as well. Granted, align equals is something you can do with the "source" bundle in TextMate already.

The only downside is that it shoves in a "made pretty with phpBeautify" or something like that at the bottom, but it is a quick delete. I am sure I could strip it inside the bundle, but this work is not something I do that often.