Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I like Textmate but its really driving me crazy when it comes to formatting code whatever the language I'm working with. Is there any way to format code? shortcut, bundle or anything that can help (eg ctrl+shift+F in netbeans)?

share|improve this question

migrated from stackoverflow.com Jul 20 '11 at 11:30

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 3 down vote accepted

No.

There is a Reformat Paragraph command under the Text menu but it is mostly useless for programming.

Some language-specific bundles (like Javascript Tools) offer reformatting options, though.

share|improve this answer
    
God help us please :) –  Ans Jul 19 '11 at 21:20
    
God is working on it ↓ –  tim Mar 27 '13 at 19:17

Textmate 2 has indenting intelligence for each language (as much as it can: See below).

You can re-indent a block with ⌥⌘-[ You can re-wrap lines with ^-Q You can align code on symbols with ^⌥⌘-9

Example indentation rule in Settings (no need for casual users to edit these)

{   increaseIndentPattern = '(?x)
    (   \{ (?! .* \} ) .*
    |   array\(
    |   (\[)
    |   ((else)?if|else|for(each)?|while|switch) .* :
    )   \s* (/[/*] .*)? $';
decreaseIndentPattern = '(?x)
    ^ (.* \*/)? \s*
    (
        (\})         |
        (\)[;,])     |
        (\][;,])     |
        (else:)      |
        ((end(if|for(each)?|while|switch));)
    )
';
indentNextLinePattern = '(?x)^(?! .*? (<\?|\?>) )
    ( . ( (?![/*]) | /(/.*$|\*.*?\*/ \s*) ) )*
    [^\s;:{}(,] \s*
    ( /(/.*$|\*.*?\*/ \s*) )*
    $
';
unIndentedLinePattern = '^\s*$';
}
share|improve this answer

If all you want to do is re-indent:

  1. select code
  2. text > indent line

All it does is indent each nested level more than its parent. It wont erase empty lines or create any carriage returns.

Personally I love this because it seems to be language agnostic. Tested with HTML, ERB, CSS, SCSS.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.