How to tell eclipse to not format parts of a codefile (pressing Strg + Shift + F)

后端 未结 2 1861
隐瞒了意图╮
隐瞒了意图╮ 2021-01-26 03:04

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

相关标签:
2条回答
  • 2021-01-26 03:26

    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
    0 讨论(0)
  • 2021-01-26 03:40

    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.

    0 讨论(0)
提交回复
热议问题