0

I really love the autofromat feature. I makes your code more readable and in case of JavaScript tells you, when there are synatcs errors (missing brackets etc.).

However sometimes the formatting makes the code harder to read. e.g. when it puts a long array inizalisation into a single line. In that case I don't want him to format it, but rather leave it ofer multiple lines. E.g.

define([
    'jquery', 
    'aloha', 
    'aloha/plugin', 
    'ui/ui', 
    'ui/scopes', 
    'ui/button', 
    'ui/toggleButton', 
    'ui/port-helper-attribute-field', 
    'ui/text'
// 'css!youtube/css/youtube.css'
], 
    function(
        $, 
        Aloha, 
        Plugin, 
        Ui, 
        Scopes, 
        Button, 
        ToggleButton, 
        AttributeField) 
        {

this array should stay like this and don't become this:

define(['jquery', 'aloha', 'aloha/plugin', 'ui/ui', 'ui/scopes', 'ui/button', 'ui/toggleButton', 'ui/port-helper-attribute-field', 'ui/text' ], function($, Aloha, Plugin, Ui, Scopes, Button, ToggleButton, AttributeField) {

Is there a special tag, to tell eclipse not to format the code?

Stefan
  • 14,826
  • 17
  • 80
  • 143
  • 1
    Take a look at Eclipse formatter tags, see answer http://stackoverflow.com/a/3353765/1288408 – Modus Tollens Sep 12 '12 at 15:59
  • thanks that's what I was looking for. Well I don't want to delete this querstion, since I didn't find the link and I searched quite a while for it. Do you wanna sumerize the answer and I accept it? LG – Stefan Sep 12 '12 at 19:50
  • Sorry, I didn't notice your comment. I think you should accept your own answer :) – Modus Tollens Sep 14 '12 at 12:04
  • ^^ ok, I was going to but since you brought me on the right track, I think you deserved it – Stefan Sep 14 '12 at 12:10

2 Answers2

3

OK, it took me some time to find the right setting so I will post a toturial here.

Go to Window Preferences and Search the Formatter you are using. In my case it was under 'Aptana Studia' -> 'Formatter'. (Depending on your Package this differs, e.g. the Java Formatter is under 'Java' -> 'Code Style' -> 'Formater').

Create new Formatter Proffile

Noww create a new Build profile since you can't override the old one.

Now enable the Formatter tags. Enabale Formatter on/off tags

Now you can use the

 - @formatter:on
 - @formatter:off

tags to disable code formatting.

Example: this code:

    function hello() {             return 'hello';
}

//@formatter:off
/*
   |\      _,,,---,,_
   /,`.-'`'    -.  ;-;;,_
  |,4-  ) )-,_..;\ (  `'-'
 '---''(_/--'  `-'\_)  fL

 */
//@formatter:on

function 


world() {
    return 'world';
}

Will get formatted to like this

function hello() {
    return 'hello';
}

//@formatter:off
/*
   |\      _,,,---,,_
   /,`.-'`'    -.  ;-;;,_
  |,4-  ) )-,_..;\ (  `'-'
 '---''(_/--'  `-'\_)  fL

 */
//@formatter:on

function world() {
    return 'world';
}

Note how the function definition is formatted correct, while the ascii art isn't

Credits:

  1. Katja Christiansen for his comment
  2. https://stackoverflow.com/a/3353765/639035 : for a similar answer
Community
  • 1
  • 1
Stefan
  • 14,826
  • 17
  • 80
  • 143
2

Try to make an empty comment after each line:

define([ //
    'jquery', //
    'aloha', //
    'aloha/plugin', //
    'ui/ui', //
    'ui/scopes', //
    'ui/button', //
    'ui/toggleButton', //
...

Not nice, but I think it will work.

Kai
  • 38,985
  • 14
  • 88
  • 103