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?

4
  • 1
    Take a look at Eclipse formatter tags, see answer stackoverflow.com/a/3353765/1288408 Sep 12, 2012 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, 2012 at 19:50
  • Sorry, I didn't notice your comment. I think you should accept your own answer :) Sep 14, 2012 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, 2012 at 12:10

2 Answers 2

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
5
  • 1
    Nice tutorial, I like the example :) Sep 13, 2012 at 8:12
  • Tanks, botherd me far to long, so I had to document it^^
    – Stefan
    Sep 13, 2012 at 8:28
  • OK, if you are using Aptana Studio this works. In an standard eclipse installation you won't have this option.
    – Kai
    Sep 13, 2012 at 12:24
  • 1
    @user714965 - Eclipse Mars - I found under 'Edit' button in Preferences->Java->Code Style-> Formatter
    – Krystian
    Oct 27, 2015 at 13:58
  • Great! I`ll remove my last comment soon.
    – Kai
    Oct 28, 2015 at 6:31
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.

1
  • Works, but code gets somehow ugly. It formats them to the beginning of the document
    – Stefan
    Sep 12, 2012 at 12:37

Your Answer

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

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