8

How can I configure formatting options in Eclipse for Java Script source code so that having this code:

var o = {
    items: [{
        xtype: 'grid',
        columns: [<cursor here>{header: 'Column One'}],
    }],
};

after pressing Enter I get this

var o = {
    items: [{
        xtype: 'grid',
        columns: [
            {header: 'Column One'}],
    }],
};

instead of the default:

var o = {
    items: [{
        xtype: 'grid',
        columns: [
                  {header: 'Column One'}],
    }],
};

I'd like to have initializers of array's elements indented with one level of indentation (tab in my case) not aligned with the opening bracket. I can't get the right indentation even manually - given this code

var o = {
    items: [{
        xtype: 'grid',
        columns: [
{header: 'Column One'}], // cursor at the beginning of this line
    }],
};

after pressing Tab twice I get the same indentation as after pressing Enter above.
I'm using JavaScript Development Tools ver. 1.3.0.v201103031824 from Eclipse Web Tools Platform.

1

1 Answer 1

1

Hope this helps albeit a bit late...

You can change the Formatter for JavaScript in Eclipse->Preferences
Goto JavaScript->Code Style->Formatter

Edit to create your custom profile and make changes to the following:
In the Line Wrapping Tab

  • Change Default Indentation for array Initializers to "1"
  • Select Expressions->Array Initializers and set the line wrapping policy as desired. Wrap all except first seemed OK to me.
  • Change Indentation policy for the above to "Indent by one"
  • Check the Force split box to have the effect always regardless of whether or not a Wrap is required.
3
  • 2
    After setting above options the preview looks ok but in editor I still get the same formatting as described in question. Oct 4, 2012 at 21:15
  • Edited my answer to get the desired effect, but it requires that you use the Formatting shortcut (Ctrl+Shift+F) on the array declaration. The Enter still does not seem to take the formatting into account. Oct 5, 2012 at 5:33
  • @PiotrDobrogost did you get the desired effect based on my edit? Oct 8, 2012 at 5:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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